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 |
# File 'lib/schked/worker.rb', line 7 def initialize(config:) @config = config @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 end |
Instance Method Details
#job(as) ⇒ Object
20 21 22 |
# File 'lib/schked/worker.rb', line 20 def job(as) scheduler.jobs.find { |job| job.opts[:as] == as } end |
#pause ⇒ Object
24 25 26 |
# File 'lib/schked/worker.rb', line 24 def pause scheduler.pause end |
#schedule ⇒ Object
36 37 38 39 40 41 42 43 |
# File 'lib/schked/worker.rb', line 36 def schedule config .paths .map { |path| File.(path) } .uniq .map { |path| File.read(path) } .join("\n") end |
#stop ⇒ Object
32 33 34 |
# File 'lib/schked/worker.rb', line 32 def stop scheduler.stop end |
#wait ⇒ Object
28 29 30 |
# File 'lib/schked/worker.rb', line 28 def wait scheduler.join end |