diff --git a/CHANGELOG.md b/CHANGELOG.md index d61a6fbd8..5cc6b20ac 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,9 @@ +14.07.2015 + +* Updated que init script doc example, now status and stop works faster + 07.07.2015 + * Before applyling 20150707104937_refactor_reserved_domains.rb migration, enable hstore extension in db 01.07.2015 diff --git a/Gemfile b/Gemfile index 6e502b3c1..921074895 100644 --- a/Gemfile +++ b/Gemfile @@ -13,7 +13,7 @@ gem 'iso8601', '~> 0.8.2' # for dates and times gem 'hashie-forbidden_attributes', '~> 0.1.1' # load env -gem 'figaro', '~> 1.1.0' +gem 'figaro', '~> 1.1.1' # model related gem 'pg', '~> 0.18.0' diff --git a/Gemfile.lock b/Gemfile.lock index 836ecc817..b6ac5c808 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -567,7 +567,7 @@ DEPENDENCIES epp-xml (~> 1.0.3) fabrication (~> 2.13.2) faker (~> 1.4.3) - figaro (~> 1.1.0) + figaro (~> 1.1.1) grape (~> 0.12.0) guard (~> 2.12.6) guard-rails (~> 0.7.1) diff --git a/doc/que/que-init-example b/doc/que/que-init-example index d9162e013..424060f76 100644 --- a/doc/que/que-init-example +++ b/doc/que/que-init-example @@ -27,7 +27,7 @@ cd $APP_ROOT || exit 1 case ${1-help} in status) - cd $APP_ROOT && RAILS_ENV=$RAILS_ENV $RUBY_BUNDLE_PATH exec rake daemon:que:status + cd $APP_ROOT && RAILS_ENV=$RAILS_ENV lib/daemons/que_ctl status ;; start) echo "$1 que monitor and server" @@ -38,7 +38,7 @@ start) ;; stop) echo "$1 que monitor and server" - cd $APP_ROOT && RAILS_ENV=$RAILS_ENV $RUBY_BUNDLE_PATH exec rake daemon:que:stop + cd $APP_ROOT && RAILS_ENV=$RAILS_ENV lib/daemons/que_ctl stop ;; restart) echo "$1 que monitor and server" diff --git a/lib/daemons/que.rb b/lib/daemons/que.rb index c4ad0abf0..d5e0e5528 100755 --- a/lib/daemons/que.rb +++ b/lib/daemons/que.rb @@ -8,11 +8,36 @@ Dir.chdir(root) require File.join(root, "config", "environment") -@running = true -Signal.trap("TERM") do - @running = false +# 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 -# rubocop: disable Style/WhileUntilDo -while @running do +Que.logger.level = Logger.const_get((ENV['QUE_LOG_LEVEL'] || 'INFO').upcase) +Que.worker_count = 1 +Que.wake_interval = (ENV['QUE_WAKE_INTERVAL'] || 0.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 TERM ).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 0.01 + break if stop end diff --git a/lib/daemons/que_ctl b/lib/daemons/que_ctl index 0a9d3598b..446f8eac0 100755 --- a/lib/daemons/que_ctl +++ b/lib/daemons/que_ctl @@ -3,4 +3,4 @@ require 'rubygems' require 'daemons/rails/config' config = Daemons::Rails::Config.for_controller(File.expand_path(__FILE__)) -Daemons::Rails.run config[:script], config.to_hash \ No newline at end of file +Daemons::Rails.run config[:script], config.to_hash