Module: SidekiqUniqueJobs::Orphans::ReaperResurrector
- Defined in:
- lib/sidekiq_unique_jobs/orphans/reaper_resurrector.rb
Overview
Restarts orphan manager if it is considered dead
Constant Summary collapse
- DRIFT_FACTOR =
0.1
- REAPERS =
[:ruby, :lua].freeze
Class Method Summary collapse
- .current_timestamp ⇒ Object
- .drift_reaper_interval ⇒ Object
-
.logging_context ⇒ Hash, String
A context to use for all log entries.
-
.orphans_manager ⇒ SidekiqUniqueJobs::Orphans::Manager
Returns orphan manager.
- .reaper ⇒ Object
-
.reaper_disabled? ⇒ true, false
Checks if reaping is disabled.
-
.reaper_enabled? ⇒ true, false
Checks if reaping is enabled.
- .reaper_interval ⇒ Object
-
.reaper_registered? ⇒ true, false
Checks if reaper is registered.
- .reaper_resurrector_interval ⇒ Object
-
.restart_if_dead ⇒ Object
Starts new instance of orphan reaper if reaper is considered dead (reaper mutex has not been refreshed lately).
-
.resurrector_disabled? ⇒ true, false
Checks if resurrector is disabled.
-
.resurrector_enabled? ⇒ true, false
Checks if resurrector is enabled.
-
.run_task ⇒ SidekiqUniqueJobs::TimerTask
Runs reaper resurrector task.
-
.start ⇒ SidekiqUniqueJobs::TimerTask
Starts reaper resurrector that watches orphans reaper.
-
.task ⇒ SidekiqUniqueJobs::TimerTask
The task that runs the resurrector.
-
.timer_task_options ⇒ Hash
Arguments passed on to the timer task.
Class Method Details
.current_timestamp ⇒ Object
165 166 167 |
# File 'lib/sidekiq_unique_jobs/orphans/reaper_resurrector.rb', line 165 def Time.now.to_i end |
.drift_reaper_interval ⇒ Object
161 162 163 |
# File 'lib/sidekiq_unique_jobs/orphans/reaper_resurrector.rb', line 161 def drift_reaper_interval reaper_interval + (reaper_interval * DRIFT_FACTOR).to_i end |
.logging_context ⇒ Hash, String
A context to use for all log entries
142 143 144 145 146 147 148 |
# File 'lib/sidekiq_unique_jobs/orphans/reaper_resurrector.rb', line 142 def logging_context if logger_context_hash? { "uniquejobs" => "reaper-resurrector" } else "uniquejobs=reaper-resurrector" end end |
.orphans_manager ⇒ SidekiqUniqueJobs::Orphans::Manager
Returns orphan manager
65 66 67 |
# File 'lib/sidekiq_unique_jobs/orphans/reaper_resurrector.rb', line 65 def orphans_manager SidekiqUniqueJobs::Orphans::Manager end |
.reaper ⇒ Object
120 121 122 |
# File 'lib/sidekiq_unique_jobs/orphans/reaper_resurrector.rb', line 120 def reaper SidekiqUniqueJobs.config.reaper end |
.reaper_disabled? ⇒ true, false
Checks if reaping is disabled
94 95 96 |
# File 'lib/sidekiq_unique_jobs/orphans/reaper_resurrector.rb', line 94 def reaper_disabled? !reaper_enabled? end |
.reaper_enabled? ⇒ true, false
Checks if reaping is enabled
103 104 105 |
# File 'lib/sidekiq_unique_jobs/orphans/reaper_resurrector.rb', line 103 def reaper_enabled? REAPERS.include?(reaper) end |
.reaper_interval ⇒ Object
157 158 159 |
# File 'lib/sidekiq_unique_jobs/orphans/reaper_resurrector.rb', line 157 def reaper_interval SidekiqUniqueJobs.config.reaper_interval end |
.reaper_registered? ⇒ true, false
Checks if reaper is registered
111 112 113 114 115 |
# File 'lib/sidekiq_unique_jobs/orphans/reaper_resurrector.rb', line 111 def reaper_registered? redis do |conn| conn.get(UNIQUE_REAPER).to_i + drift_reaper_interval > end end |
.reaper_resurrector_interval ⇒ Object
153 154 155 |
# File 'lib/sidekiq_unique_jobs/orphans/reaper_resurrector.rb', line 153 def reaper_resurrector_interval SidekiqUniqueJobs.config.reaper_resurrector_interval end |
.restart_if_dead ⇒ Object
Starts new instance of orphan reaper if reaper is considered dead (reaper mutex has not been refreshed lately)
54 55 56 57 58 59 |
# File 'lib/sidekiq_unique_jobs/orphans/reaper_resurrector.rb', line 54 def restart_if_dead return if reaper_registered? log_info("Reaper is considered dead. Starting new reaper instance") orphans_manager.start end |
.resurrector_disabled? ⇒ true, false
Checks if resurrector is disabled
75 76 77 |
# File 'lib/sidekiq_unique_jobs/orphans/reaper_resurrector.rb', line 75 def resurrector_disabled? !resurrector_enabled? end |
.resurrector_enabled? ⇒ true, false
Checks if resurrector is enabled
83 84 85 |
# File 'lib/sidekiq_unique_jobs/orphans/reaper_resurrector.rb', line 83 def resurrector_enabled? SidekiqUniqueJobs.config.reaper_resurrector_enabled end |
.run_task ⇒ SidekiqUniqueJobs::TimerTask
Runs reaper resurrector task
33 34 35 36 37 |
# File 'lib/sidekiq_unique_jobs/orphans/reaper_resurrector.rb', line 33 def run_task log_info("Starting Reaper Resurrector") task.execute task end |
.start ⇒ SidekiqUniqueJobs::TimerTask
Starts reaper resurrector that watches orphans reaper
20 21 22 23 24 25 26 27 |
# File 'lib/sidekiq_unique_jobs/orphans/reaper_resurrector.rb', line 20 def start return if resurrector_disabled? return if reaper_disabled? with_logging_context do run_task end end |
.task ⇒ SidekiqUniqueJobs::TimerTask
The task that runs the resurrector
43 44 45 46 47 48 49 |
# File 'lib/sidekiq_unique_jobs/orphans/reaper_resurrector.rb', line 43 def task SidekiqUniqueJobs::TimerTask.new() do with_logging_context do restart_if_dead end end end |
.timer_task_options ⇒ Hash
Arguments passed on to the timer task
130 131 132 133 |
# File 'lib/sidekiq_unique_jobs/orphans/reaper_resurrector.rb', line 130 def { run_now: false, execution_interval: reaper_resurrector_interval } end |