Class: Sqeduler::LockMaintainer
- Inherits:
-
Object
- Object
- Sqeduler::LockMaintainer
- Defined in:
- lib/sqeduler/lock_maintainer.rb
Overview
This is to ensure that if you set your jobs to run one a time and something goes wrong causing a job to run for a long time, your lock won't expire. This doesn't stop long running jobs, it just ensures you only end up with one long running job rather than 20 of them.
Constant Summary collapse
- RUN_INTERVAL =
30
- RUN_JITTER =
(1..5).freeze
Instance Method Summary collapse
-
#initialize ⇒ LockMaintainer
constructor
A new instance of LockMaintainer.
-
#run ⇒ Object
This is only done when we initialize Sqeduler, don't need to worry about threading.
Constructor Details
#initialize ⇒ LockMaintainer
Returns a new instance of LockMaintainer.
12 13 14 |
# File 'lib/sqeduler/lock_maintainer.rb', line 12 def initialize @class_with_locks = {} end |
Instance Method Details
#run ⇒ Object
This is only done when we initialize Sqeduler, don't need to worry about threading
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/sqeduler/lock_maintainer.rb', line 17 def run @maintainer_thread ||= Thread.new do loop do begin if redis_lock.lock begin synchronize ensure redis_lock.unlock end end rescue StandardError => ex Service.logger.error "[#{self.class}] #{ex.class}, #{ex.}" end sleep RUN_INTERVAL + rand(RUN_JITTER) end end end |