Class: WorkerKiller::RufusScheduler::BaseLimiter
- Inherits:
-
Object
- Object
- WorkerKiller::RufusScheduler::BaseLimiter
- Defined in:
- lib/worker_killer/rufus_scheduler/base_limiter.rb
Overview
Base class for registration rufus process killer.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#frequency ⇒ Object
readonly
Returns the value of attribute frequency.
-
#job_filter ⇒ Object
readonly
Returns the value of attribute job_filter.
-
#killer ⇒ Object
readonly
Returns the value of attribute killer.
-
#limiter ⇒ Object
readonly
Returns the value of attribute limiter.
-
#scheduler ⇒ Object
readonly
Returns the value of attribute scheduler.
-
#timeout ⇒ Object
readonly
Returns the value of attribute timeout.
Class Method Summary collapse
Instance Method Summary collapse
- #check_after_job?(job, trigger_time) ⇒ Boolean
-
#initialize(scheduler:, limiter:, frequency: 30, timeout: 60, logger: nil, job_filter: nil) ⇒ BaseLimiter
constructor
A new instance of BaseLimiter.
- #register ⇒ Object
- #run_check ⇒ Object
Constructor Details
#initialize(scheduler:, limiter:, frequency: 30, timeout: 60, logger: nil, job_filter: nil) ⇒ BaseLimiter
Returns a new instance of BaseLimiter.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/worker_killer/rufus_scheduler/base_limiter.rb', line 19 def initialize(scheduler:, limiter:, frequency: 30, timeout: 60, logger: nil, job_filter: nil) ::WorkerKiller.configure do |config| # Setting up logger for both limiter and killer config.logger = logger unless logger.nil? # We use wait instead of attempts, because attempts does not work for rufus. # rufus can either kill active jobs now or wait N seconds until they finished. config.quit_attempts = 1 config.term_attempts = 0 end @scheduler = scheduler @frequency = frequency&.to_i @timeout = timeout.to_i @killer = ::WorkerKiller::Killer::RufusScheduler.new @limiter = limiter @job_filter = job_filter end |
Instance Attribute Details
#frequency ⇒ Object (readonly)
Returns the value of attribute frequency.
11 12 13 |
# File 'lib/worker_killer/rufus_scheduler/base_limiter.rb', line 11 def frequency @frequency end |
#job_filter ⇒ Object (readonly)
Returns the value of attribute job_filter.
11 12 13 |
# File 'lib/worker_killer/rufus_scheduler/base_limiter.rb', line 11 def job_filter @job_filter end |
#killer ⇒ Object (readonly)
Returns the value of attribute killer.
11 12 13 |
# File 'lib/worker_killer/rufus_scheduler/base_limiter.rb', line 11 def killer @killer end |
#limiter ⇒ Object (readonly)
Returns the value of attribute limiter.
11 12 13 |
# File 'lib/worker_killer/rufus_scheduler/base_limiter.rb', line 11 def limiter @limiter end |
#scheduler ⇒ Object (readonly)
Returns the value of attribute scheduler.
11 12 13 |
# File 'lib/worker_killer/rufus_scheduler/base_limiter.rb', line 11 def scheduler @scheduler end |
#timeout ⇒ Object (readonly)
Returns the value of attribute timeout.
11 12 13 |
# File 'lib/worker_killer/rufus_scheduler/base_limiter.rb', line 11 def timeout @timeout end |
Class Method Details
.register(**kwargs) ⇒ Object
7 8 9 |
# File 'lib/worker_killer/rufus_scheduler/base_limiter.rb', line 7 def self.register(**kwargs) new(**kwargs).register end |
Instance Method Details
#check_after_job?(job, trigger_time) ⇒ Boolean
49 50 51 52 53 |
# File 'lib/worker_killer/rufus_scheduler/base_limiter.rb', line 49 def check_after_job?(job, trigger_time) return true if job_filter.nil? job_filter.call(job, trigger_time) end |
#register ⇒ Object
37 38 39 40 41 42 43 |
# File 'lib/worker_killer/rufus_scheduler/base_limiter.rb', line 37 def register if frequency register_every_job else register_post_run_job end end |
#run_check ⇒ Object
45 46 47 |
# File 'lib/worker_killer/rufus_scheduler/base_limiter.rb', line 45 def run_check killer.kill(limiter.started_at, scheduler: scheduler, timeout: timeout) if limiter.check end |