From d262d6eb9361316ebdf6ec85cee9b8f5b3658de3 Mon Sep 17 00:00:00 2001 From: Dmitry Bochkarev Date: Tue, 17 May 2016 13:39:20 +0500 Subject: [PATCH] =?UTF-8?q?fix:=20=D0=B7=D0=B0=D0=BF=D1=83=D1=81=D0=BA=20G?= =?UTF-8?q?C=20=D0=BF=D1=80=D0=B8=20=D0=B7=D0=B0=D0=B2=D0=B5=D1=80=D1=88?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B8=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D1=8B?= =?UTF-8?q?=20=D0=B2=D0=BE=D1=80=D0=BA=D0=B5=D1=80=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://jira.railsc.ru/browse/SERVICES-1092 --- lib/resque/integration/configuration.rb | 11 +++++++++++ lib/resque/integration/tasks/hooks.rake | 4 ++++ spec/resque/integration/configuration_spec.rb | 12 ++++++++++++ 3 files changed, 27 insertions(+) diff --git a/lib/resque/integration/configuration.rb b/lib/resque/integration/configuration.rb index 78522e6..9375eaa 100644 --- a/lib/resque/integration/configuration.rb +++ b/lib/resque/integration/configuration.rb @@ -106,6 +106,17 @@ def failure_notifier @notifier ||= Notifier.new(self['failure.notifier']) end + # Returns flag for cleaning on shutdown see https://github.com/resque/resque/issues/1167 + def run_at_exit_hooks? + value = self['resque.run_at_exit_hooks'] + + if value.is_a?(String) && %w(n no false off disabled).include?(value) + value = false + end + + value.nil? ? true : value + end + # Returns Resque polling interval def interval (self['resque.interval'] || 5).to_i diff --git a/lib/resque/integration/tasks/hooks.rake b/lib/resque/integration/tasks/hooks.rake index 996c9cb..e4519b4 100644 --- a/lib/resque/integration/tasks/hooks.rake +++ b/lib/resque/integration/tasks/hooks.rake @@ -43,5 +43,9 @@ namespace :resque do if Resque.config.resque_scheduler? && Resque.config.schedule_exists? Resque.schedule = YAML.load_file(Resque.config.schedule_file) end + + if Resque.config.run_at_exit_hooks? && ENV['RUN_AT_EXIT_HOOKS'].nil? + ENV['RUN_AT_EXIT_HOOKS'] = '1' + end end end diff --git a/spec/resque/integration/configuration_spec.rb b/spec/resque/integration/configuration_spec.rb index 9a07fa1..4a5ec39 100644 --- a/spec/resque/integration/configuration_spec.rb +++ b/spec/resque/integration/configuration_spec.rb @@ -41,6 +41,18 @@ it { expect(config.resque_scheduler?).to be_false } end end + + describe '#run_at_exit_hooks?' do + context 'when default' do + it { expect(config.resque_scheduler?).to be_true } + end + + context 'when defined' do + let(:config_yaml) { {'resque' => {'run_at_exit_hooks' => 'no'}} } + + it { expect(config.run_at_exit_hooks?).to be_false } + end + end end describe Resque::Integration::Configuration::Notifier do