File tree Expand file tree Collapse file tree 5 files changed +20
-2
lines changed
Expand file tree Collapse file tree 5 files changed +20
-2
lines changed Original file line number Diff line number Diff line change @@ -15,7 +15,8 @@ module Scheduler
1515 quiet : 'QUIET' ,
1616 pidfile : 'PIDFILE' ,
1717 poll_sleep_amount : 'RESQUE_SCHEDULER_INTERVAL' ,
18- verbose : 'VERBOSE'
18+ verbose : 'VERBOSE' ,
19+ lock_timeout : 'LOCK_TIMEOUT'
1920 } . freeze
2021
2122 class Cli
Original file line number Diff line number Diff line change @@ -80,6 +80,13 @@ def poll_sleep_amount
8080 Float ( environment . fetch ( 'RESQUE_SCHEDULER_INTERVAL' , '5' ) )
8181 end
8282
83+ # Sets timeout for Resque::Scheduler::Lock::Base
84+ attr_writer :lock_timeout
85+
86+ def lock_timeout
87+ @lock_timeout ||= environment . fetch ( 'LOCK_TIMEOUT' , 60 * 3 ) . to_i
88+ end
89+
8390 private
8491
8592 # Copied from https://github.com/rails/rails/blob/main/activemodel/lib/active_model/type/boolean.rb#L17
Original file line number Diff line number Diff line change @@ -54,6 +54,7 @@ def setup_pid_file
5454 at_exit { cleanup_pid_file }
5555 end
5656
57+ # rubocop:disable Metrics/AbcSize
5758 def setup_scheduler_configuration
5859 Resque ::Scheduler . configure do |c |
5960 c . app_name = options [ :app_name ] if options . key? ( :app_name )
@@ -66,13 +67,16 @@ def setup_scheduler_configuration
6667
6768 c . logformat = options [ :logformat ] if options . key? ( :logformat )
6869
70+ c . lock_timeout = options [ :lock_timeout ] if options . key? ( :lock_timeout )
71+
6972 if ( psleep = options [ :poll_sleep_amount ] ) && !psleep . nil?
7073 c . poll_sleep_amount = Float ( psleep )
7174 end
7275
7376 c . verbose = !!options [ :verbose ] if options . key? ( :verbose )
7477 end
7578 end
79+ # rubocop:enable Metrics/AbcSize
7680
7781 def cleanup_pid_file
7882 return unless pidfile_path
Original file line number Diff line number Diff line change @@ -11,7 +11,7 @@ def initialize(key, options = {})
1111 @key = key
1212
1313 # 3 minute default timeout
14- @timeout = options [ :timeout ] || 60 * 3
14+ @timeout = options [ :timeout ] || Resque :: Scheduler . lock_timeout
1515 end
1616
1717 # Attempts to acquire the lock. Returns true if successfully acquired.
Original file line number Diff line number Diff line change 1919 end
2020 end
2121
22+ test 'setting lock_timeout from environment' do
23+ configuration . environment = { 'LOCK_TIMEOUT' => '47' }
24+
25+ assert_equal 47 , configuration . lock_timeout
26+ end
27+
2228 test 'env set from Rails.env' do
2329 Rails . expects ( :env ) . returns ( 'development' )
2430
You can’t perform that action at this time.
0 commit comments