Class: Dionysus::Producer::Outbox::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/dionysus/producer/outbox/runner.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config: Dionysus::Producer.configuration, logger: Dionysus.logger) ⇒ Runner

Returns a new instance of Runner.



7
8
9
10
11
12
13
# File 'lib/dionysus/producer/outbox/runner.rb', line 7

def initialize(config: Dionysus::Producer.configuration,
  logger: Dionysus.logger)
  @id = SecureRandom.uuid
  @logger = logger
  logger.push_tags("Dionysus::Producer::Outbox::Runners #{id}") if logger.respond_to?(:push_tags)
  @config = config
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



4
5
6
# File 'lib/dionysus/producer/outbox/runner.rb', line 4

def id
  @id
end

Instance Method Details

#startObject



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

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

#stopObject



37
38
39
40
41
# File 'lib/dionysus/producer/outbox/runner.rb', line 37

def stop
  log("Outbox worker stopping")
  instrument("outbox_producer.stopped")
  @should_stop = true
end