Class: ActiveRecord::Base::PromiscuousTransaction

Inherits:
Promiscuous::Publisher::Operation::Transaction show all
Defined in:
lib/promiscuous/publisher/operation/active_record.rb

Instance Attribute Summary collapse

Attributes inherited from Promiscuous::Publisher::Operation::Transaction

#operation_payloads, #transaction_id, #transaction_operations

Attributes inherited from Promiscuous::Publisher::Operation::Base

#operation

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Promiscuous::Publisher::Operation::Transaction

#dependency_for_op_lock, #pending_writes, #query_dependencies, recover_operation, #recovery_payload, #should_instrument_query?

Methods inherited from Promiscuous::Publisher::Operation::Base

_acquire_lock, #acquire_op_lock, #dependencies_for, #dependency_for_op_lock, #ensure_op_still_locked, #execute, #explain_operation, #generate_payload, #get_new_op_lock, #increment_dependencies, lock_options, #on_rabbitmq_confirm, #operation_payloads, #payload_for, #publish_payload_in_rabbitmq_async, #publish_payload_in_redis, #query_dependencies, rabbitmq_staging_set_key, #record_timestamp, #recover_db_operation, recover_locks, recover_operation, recover_operation_from_lock, recover_payloads_for_rabbitmq, #recovering?, #recovery_payload, register_recovery_mechanism, #release_op_lock, run_recovery_mechanisms, #should_instrument_query?, #trace_operation, #write_dependencies

Constructor Details

#initialize(options = {}) ⇒ PromiscuousTransaction

Returns a new instance of PromiscuousTransaction.



268
269
270
271
272
# File 'lib/promiscuous/publisher/operation/active_record.rb', line 268

def initialize(options={})
  super
  # When we do a recovery, we use the default connection.
  @connection = options[:connection] || ActiveRecord::Base.connection
end

Instance Attribute Details

#connectionObject

Returns the value of attribute connection.



266
267
268
# File 'lib/promiscuous/publisher/operation/active_record.rb', line 266

def connection
  @connection
end

Class Method Details

.recover_transaction(connection, transaction_id) ⇒ Object



280
281
282
283
284
285
286
287
288
289
290
291
292
293
# File 'lib/promiscuous/publisher/operation/active_record.rb', line 280

def self.recover_transaction(connection, transaction_id)
  op = new(:connection => connection, :transaction_id => transaction_id)
  # Getting the lock will trigger the real recovery mechanism
  if op.acquire_op_lock
    op.release_op_lock
  end

  # In the event where the recovery payload wasn't found, we must roll back.
  # If the operation was recoverable, but couldn't be recovered, an
  # exception would be thrown, so we won't roll it back by mistake.
  # If the operation was recovered, the roll back will result in an error,
  # which is fine.
  connection.rollback_prepared_db_transaction(transaction_id)
end

Instance Method Details

#execute_instrumented(query) ⇒ Object



274
275
276
277
278
# File 'lib/promiscuous/publisher/operation/active_record.rb', line 274

def execute_instrumented(query)
  query.prepare      { @connection.prepare_db_transaction }
  query.instrumented { @connection.commit_prepared_db_transaction(@transaction_id) }
  super
end