@@ -33,7 +33,7 @@ class << self
3333 }
3434
3535 class Locker
36- attr_reader :thread , :workers , :job_buffer , :locks , :queues , :poll_interval
36+ attr_reader :thread , :workers , :job_buffer , :locks , :queues , :poll_interval , :poll_interval_variance
3737
3838 MESSAGE_RESOLVERS = { }
3939 RESULT_RESOLVERS = { }
@@ -47,22 +47,24 @@ class Locker
4747 RESULT_RESOLVERS [ :job_finished ] =
4848 -> ( messages ) { finish_jobs ( messages . map { |m | m . fetch ( :metajob ) } ) }
4949
50- DEFAULT_POLL_INTERVAL = 5.0
51- DEFAULT_WAIT_PERIOD = 50
52- DEFAULT_MAXIMUM_BUFFER_SIZE = 8
53- DEFAULT_WORKER_PRIORITIES = [ 10 , 30 , 50 , nil , nil , nil ] . freeze
50+ DEFAULT_POLL_INTERVAL = 5.0
51+ DEFAULT_POLL_INTERVAL_VARIANCE = 0.0
52+ DEFAULT_WAIT_PERIOD = 50
53+ DEFAULT_MAXIMUM_BUFFER_SIZE = 8
54+ DEFAULT_WORKER_PRIORITIES = [ 10 , 30 , 50 , nil , nil , nil ] . freeze
5455
5556 def initialize (
56- queues : [ Que . default_queue ] ,
57- connection_url : nil ,
58- listen : true ,
59- poll : true ,
60- poll_interval : DEFAULT_POLL_INTERVAL ,
61- wait_period : DEFAULT_WAIT_PERIOD ,
62- maximum_buffer_size : DEFAULT_MAXIMUM_BUFFER_SIZE ,
63- worker_priorities : DEFAULT_WORKER_PRIORITIES ,
64- on_worker_start : nil ,
65- pidfile : nil
57+ queues : [ Que . default_queue ] ,
58+ connection_url : nil ,
59+ listen : true ,
60+ poll : true ,
61+ poll_interval : DEFAULT_POLL_INTERVAL ,
62+ poll_interval_variance : DEFAULT_POLL_INTERVAL_VARIANCE ,
63+ wait_period : DEFAULT_WAIT_PERIOD ,
64+ maximum_buffer_size : DEFAULT_MAXIMUM_BUFFER_SIZE ,
65+ worker_priorities : DEFAULT_WORKER_PRIORITIES ,
66+ on_worker_start : nil ,
67+ pidfile : nil
6668 )
6769
6870 # Sanity-check all our arguments, since some users may instantiate Locker
@@ -71,6 +73,7 @@ def initialize(
7173 Que . assert [ TrueClass , FalseClass ] , poll
7274
7375 Que . assert Numeric , poll_interval
76+ Que . assert Numeric , poll_interval_variance
7477 Que . assert Numeric , wait_period
7578
7679 Que . assert Array , worker_priorities
@@ -94,20 +97,22 @@ def initialize(
9497
9598 Que . internal_log :locker_instantiate , self do
9699 {
97- queues : queues ,
98- listen : listen ,
99- poll : poll ,
100- poll_interval : poll_interval ,
101- wait_period : wait_period ,
102- maximum_buffer_size : maximum_buffer_size ,
103- worker_priorities : worker_priorities ,
100+ queues : queues ,
101+ listen : listen ,
102+ poll : poll ,
103+ poll_interval : poll_interval ,
104+ poll_interval_variance : poll_interval_variance ,
105+ wait_period : wait_period ,
106+ maximum_buffer_size : maximum_buffer_size ,
107+ worker_priorities : worker_priorities ,
104108 }
105109 end
106110
107111 # Local cache of which advisory locks are held by this connection.
108112 @locks = Set . new
109113
110114 @poll_interval = poll_interval
115+ @poll_interval_variance = poll_interval_variance
111116
112117 if queues . is_a? ( Hash )
113118 @queue_names = queues . keys
@@ -204,9 +209,10 @@ def initialize(
204209 if poll
205210 @queues . map do |queue_name , interval |
206211 Poller . new (
207- connection : @connection ,
208- queue : queue_name ,
209- poll_interval : interval ,
212+ connection : @connection ,
213+ queue : queue_name ,
214+ poll_interval : interval ,
215+ poll_interval_variance : poll_interval_variance ,
210216 )
211217 end
212218 end
0 commit comments