File tree Expand file tree Collapse file tree 5 files changed +27
-13
lines changed
Expand file tree Collapse file tree 5 files changed +27
-13
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+ timeout : '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 :timeout
85+
86+ def timeout
87+ @timeout ||= environment . fetch ( '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 @@ -56,21 +56,21 @@ def setup_pid_file
5656
5757 def setup_scheduler_configuration
5858 Resque ::Scheduler . configure do |c |
59- c . app_name = options [ :app_name ] if options . key? ( :app_name )
60-
61- c . dynamic = !!options [ :dynamic ] if options . key? ( :dynamic )
62-
63- c . env = options [ :env ] if options . key? ( :env )
64-
65- c . logfile = options [ :logfile ] if options . key? ( :logfile )
66-
67- c . logformat = options [ :logformat ] if options . key? ( :logformat )
59+ [
60+ :app_name ,
61+ :dynamic ,
62+ :env ,
63+ :logfile ,
64+ :logformat ,
65+ :timeout ,
66+ :verbose
67+ ] . each do |option_key |
68+ c . send ( "#{ option_key } =" , options [ option_key ] ) if options . key? ( option_key )
69+ end
6870
6971 if ( psleep = options [ :poll_sleep_amount ] ) && !psleep . nil?
7072 c . poll_sleep_amount = Float ( psleep )
7173 end
72-
73- c . verbose = !!options [ :verbose ] if options . key? ( :verbose )
7474 end
7575 end
7676
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 . 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 timeout from environment' do
23+ configuration . environment = { 'TIMEOUT' => '47' }
24+
25+ assert_equal 47 , configuration . 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