Class: RailsTransactionalOutbox::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/rails_transactional_outbox/runner.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config: RailsTransactionalOutbox.configuration) ⇒ Runner

Returns a new instance of Runner.



8
9
10
11
12
# File 'lib/rails_transactional_outbox/runner.rb', line 8

def initialize(config: RailsTransactionalOutbox.configuration)
  @id = SecureRandom.uuid
  @config = config
  logger.push_tags("RailsTransactionalOutbox::Runner #{id}") if logger.respond_to?(:push_tags)
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



5
6
7
# File 'lib/rails_transactional_outbox/runner.rb', line 5

def id
  @id
end

Instance Method Details

#startObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/rails_transactional_outbox/runner.rb', line 14

def start
  log("started")
  instrument("rails_transactional_outbox.started")
  @should_stop = false
  ensure_database_connection!
  loop do
    if @should_stop
      instrument("rails_transactional_outbox.shutting_down")
      log("shutting down")
      break
    end
    entries = process_entries
    instrument("rails_transactional_outbox.heartbeat")
    sleep sleep_interval_for(entries)
  end
rescue => e
  error_handler.capture_exception(e)
  log("error: #{e} #{e.message}")
  instrument("rails_transactional_outbox.error", error: e, error_message: e.message)
  raise e
end

#stopObject



36
37
38
39
40
# File 'lib/rails_transactional_outbox/runner.rb', line 36

def stop
  log("Rails Transactional Outbox Worker stopping")
  instrument("rails_transactional_outbox.stopped")
  @should_stop = true
end