32 lines
710 B
Ruby
32 lines
710 B
Ruby
# 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
|