Initial commit
This commit is contained in:
31
lib/daemons/daemons.rb
Normal file
31
lib/daemons/daemons.rb
Normal file
@@ -0,0 +1,31 @@
|
||||
# encoding: UTF-8
|
||||
# frozen_string_literal: true
|
||||
ROOT = File.expand_path('../../..', __FILE__)
|
||||
require File.join(ROOT, 'config', 'environment')
|
||||
# default in peatio image
|
||||
# require File.join(ENV.fetch('RAILS_ROOT'), 'config', 'environment')
|
||||
|
||||
raise "Worker name must be provided." if ARGV.size == 0
|
||||
|
||||
name = ARGV[0]
|
||||
worker = "Workers::Daemons::#{name.camelize}".constantize.new
|
||||
|
||||
terminate = proc do
|
||||
puts "Terminating worker .."
|
||||
worker.stop
|
||||
puts "Stopped."
|
||||
end
|
||||
|
||||
Signal.trap("INT", &terminate)
|
||||
Signal.trap("TERM", &terminate)
|
||||
|
||||
begin
|
||||
worker.run
|
||||
rescue StandardError => e
|
||||
if worker.is_db_connection_error?(e)
|
||||
logger.error(db: :unhealthy, message: e.message)
|
||||
raise e
|
||||
end
|
||||
|
||||
report_exception(e)
|
||||
end
|
||||
Reference in New Issue
Block a user