Class: TransactionalOutbox::Database::Adapters::ActiveRecord
- Defined in:
- lib/transactional_outbox/database/adapters/active_record.rb
Instance Method Summary collapse
- #delete_events(ids) ⇒ Object
- #fetch_events(queue, batch_size) ⇒ Object
- #fetch_queues ⇒ Object
- #insert_events(attributes) ⇒ Object
- #move_to_processing(ids) ⇒ Object
- #transaction(*options) ⇒ Object
Methods included from InstanceMethods
Instance Method Details
#delete_events(ids) ⇒ Object
18 |
# File 'lib/transactional_outbox/database/adapters/active_record.rb', line 18 def delete_events(ids) = model.where(id: ids).delete_all |
#fetch_events(queue, batch_size) ⇒ Object
9 10 11 12 13 14 15 |
# File 'lib/transactional_outbox/database/adapters/active_record.rb', line 9 def fetch_events(queue, batch_size) claimable_scope(model.where(queue:)) .order(:created_at) .limit(batch_size) .lock("FOR UPDATE SKIP LOCKED") .map { |event| event.attributes.symbolize_keys } end |
#fetch_queues ⇒ Object
19 |
# File 'lib/transactional_outbox/database/adapters/active_record.rb', line 19 def fetch_queues = claimable_scope(model).select(:queue).distinct.map(&:queue) |
#insert_events(attributes) ⇒ Object
17 |
# File 'lib/transactional_outbox/database/adapters/active_record.rb', line 17 def insert_events(attributes) = model.insert_all(attributes) |
#move_to_processing(ids) ⇒ Object
21 22 23 24 25 |
# File 'lib/transactional_outbox/database/adapters/active_record.rb', line 21 def move_to_processing(ids) model .where(id: ids) .update_all(status: TransactionalOutbox::EVENT_PROCESSING_STATUS, processing_started_at: current_time) end |
#transaction(*options) ⇒ Object
7 |
# File 'lib/transactional_outbox/database/adapters/active_record.rb', line 7 def transaction(*, &) = model.transaction(*, &) |