Bring back Que gem for painless migration

This commit is contained in:
Alex Sherman 2021-03-24 13:52:36 +05:00
parent f8c90e05d3
commit 7210140de6
10 changed files with 84 additions and 82 deletions

View file

@ -1,43 +1,43 @@
# #!/usr/bin/env ruby
#
# ENV["RAILS_ENV"] ||= "production"
#
# root = File.expand_path(File.dirname(__FILE__))
# root = File.dirname(root) until File.exist?(File.join(root, 'config'))
# Dir.chdir(root)
#
# require File.join(root, "config", "environment")
#
# # from que gem rake task
# if defined?(::Rails) && Rails.respond_to?(:application)
# # ActiveSupport's dependency autoloading isn't threadsafe, and Que uses
# # multiple threads, which means that eager loading is necessary. Rails
# # explicitly prevents eager loading when the environment task is invoked,
# # so we need to manually eager load the app here.
# Rails.application.eager_load!
# end
#
# Que.logger.level = Logger.const_get((ENV['QUE_LOG_LEVEL'] || 'INFO').upcase)
# Que.worker_count = 1
# Que.wake_interval = (ENV['QUE_WAKE_INTERVAL'] || 1).to_f
# Que.mode = :async
#
# # When changing how signals are caught, be sure to test the behavior with
# # the rake task in tasks/safe_shutdown.rb.
#
# stop = false
# %w( INT ).each do |signal|
# trap(signal) { stop = true }
# end
#
# at_exit do
# $stdout.puts "Finishing Que's current jobs before exiting..."
# Que.worker_count = 0
# Que.mode = :off
# $stdout.puts "Que's jobs finished, exiting..."
# end
#
# loop do
# sleep 1
# break if stop
# end
#!/usr/bin/env ruby
ENV["RAILS_ENV"] ||= "production"
root = File.expand_path(File.dirname(__FILE__))
root = File.dirname(root) until File.exist?(File.join(root, 'config'))
Dir.chdir(root)
require File.join(root, "config", "environment")
# from que gem rake task
if defined?(::Rails) && Rails.respond_to?(:application)
# ActiveSupport's dependency autoloading isn't threadsafe, and Que uses
# multiple threads, which means that eager loading is necessary. Rails
# explicitly prevents eager loading when the environment task is invoked,
# so we need to manually eager load the app here.
Rails.application.eager_load!
end
Que.logger.level = Logger.const_get((ENV['QUE_LOG_LEVEL'] || 'INFO').upcase)
Que.worker_count = 1
Que.wake_interval = (ENV['QUE_WAKE_INTERVAL'] || 1).to_f
Que.mode = :async
# When changing how signals are caught, be sure to test the behavior with
# the rake task in tasks/safe_shutdown.rb.
stop = false
%w( INT ).each do |signal|
trap(signal) { stop = true }
end
at_exit do
$stdout.puts "Finishing Que's current jobs before exiting..."
Que.worker_count = 0
Que.mode = :off
$stdout.puts "Que's jobs finished, exiting..."
end
loop do
sleep 1
break if stop
end

View file

@ -1,6 +1,5 @@
# #!/usr/bin/env ruby
# require 'rubygems'
# require 'daemons/rails/config'
#
# config = Daemons::Rails::Config.for_controller(File.expand_path(__FILE__))
# Daemons::Rails.run config[:script], config.to_hash
#!/usr/bin/env ruby
require 'rubygems'
require 'daemons/rails/config'
config = Daemons::Rails::Config.for_controller(File.expand_path(__FILE__))
Daemons::Rails.run config[:script], config.to_hash