Class: Promiscuous::Publisher::Worker

Inherits:
Object
  • Object
show all
Defined in:
lib/promiscuous/publisher/worker.rb

Instance Method Summary collapse

Constructor Details

#initializeWorker

Returns a new instance of Worker.



2
3
4
# File 'lib/promiscuous/publisher/worker.rb', line 2

def initialize
  @recovery_timer = Promiscuous::Timer.new("recovery", Promiscuous::Config.recovery_timeout) { try_recover }
end

Instance Method Details

#startObject



6
7
8
# File 'lib/promiscuous/publisher/worker.rb', line 6

def start
  @recovery_timer.start(:run_immediately => true)
end

#stopObject



10
11
12
# File 'lib/promiscuous/publisher/worker.rb', line 10

def stop
  @recovery_timer.reset
end

#try_recoverObject



14
15
16
17
18
19
20
21
# File 'lib/promiscuous/publisher/worker.rb', line 14

def try_recover
  Promiscuous::Publisher::Operation::Base.run_recovery_mechanisms
rescue Exception => e
  Promiscuous.warn "[recovery] #{e}\n#{e.backtrace.join("\n")}"
  Promiscuous::Config.error_notifier.call(e)
ensure
  ActiveRecord::Base.clear_active_connections! if defined?(ActiveRecord::Base)
end