Class: Schked::Worker
- Inherits:
-
Object
- Object
- Schked::Worker
- Defined in:
- lib/schked/worker.rb
Instance Method Summary collapse
-
#initialize(config:) ⇒ Worker
constructor
A new instance of Worker.
- #job(as) ⇒ Object
- #pause ⇒ Object
- #schedule ⇒ Object
- #stop ⇒ Object
- #wait ⇒ Object
Constructor Details
#initialize(config:) ⇒ Worker
Returns a new instance of Worker.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/schked/worker.rb', line 7 def initialize(config:) @config = config @liveness_probe = nil @locker = RedisLocker.new(config.redis, lock_ttl: 40_000, logger: config.logger) unless config.standalone? @scheduler = Rufus::Scheduler.new(trigger_lock: locker) watch_signals define_callbacks define_extend_lock unless config.standalone? load_schedule start_liveness_probe end |
Instance Method Details
#job(as) ⇒ Object
22 23 24 |
# File 'lib/schked/worker.rb', line 22 def job(as) scheduler.jobs.find { |job| job.opts[:as] == as } end |
#pause ⇒ Object
26 27 28 |
# File 'lib/schked/worker.rb', line 26 def pause scheduler.pause end |
#schedule ⇒ Object
39 40 41 42 43 44 45 46 |
# File 'lib/schked/worker.rb', line 39 def schedule config .paths .map { |path| File.(path) } .uniq .map { |path| File.read(path) } .join("\n") end |
#stop ⇒ Object
34 35 36 37 |
# File 'lib/schked/worker.rb', line 34 def stop liveness_probe&.stop scheduler.stop end |
#wait ⇒ Object
30 31 32 |
# File 'lib/schked/worker.rb', line 30 def wait scheduler.join end |