Class: Philiprehberger::Scheduler::Runner
- Inherits:
-
Object
- Object
- Philiprehberger::Scheduler::Runner
- Defined in:
- lib/philiprehberger/scheduler/runner.rb
Constant Summary collapse
- TICK =
0.25
Instance Method Summary collapse
-
#initialize(jobs, mutex, error_handler: nil) ⇒ Runner
constructor
A new instance of Runner.
- #running? ⇒ Boolean
- #start ⇒ Object
- #stop(timeout = 5) ⇒ Object
Constructor Details
#initialize(jobs, mutex, error_handler: nil) ⇒ Runner
Returns a new instance of Runner.
8 9 10 11 12 13 14 |
# File 'lib/philiprehberger/scheduler/runner.rb', line 8 def initialize(jobs, mutex, error_handler: nil) @jobs = jobs @mutex = mutex @error_handler = error_handler @thread = nil @running = false end |
Instance Method Details
#running? ⇒ Boolean
28 29 30 |
# File 'lib/philiprehberger/scheduler/runner.rb', line 28 def running? @running && @thread&.alive? end |
#start ⇒ Object
16 17 18 19 |
# File 'lib/philiprehberger/scheduler/runner.rb', line 16 def start @running = true @thread = Thread.new { run_loop } end |
#stop(timeout = 5) ⇒ Object
21 22 23 24 25 26 |
# File 'lib/philiprehberger/scheduler/runner.rb', line 21 def stop(timeout = 5) @running = false @thread&.join(timeout) @thread&.kill if @thread&.alive? @thread = nil end |