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 |
# File 'lib/schked/worker.rb', line 7 def initialize(config:) @config = config @locker = RedisLocker.new(config.redis_servers, 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
19 20 21 |
# File 'lib/schked/worker.rb', line 19 def job(as) scheduler.jobs.find { |job| job.opts[:as] == as } end |
#pause ⇒ Object
23 24 25 |
# File 'lib/schked/worker.rb', line 23 def pause scheduler.pause end |
#schedule ⇒ Object
35 36 37 38 39 40 |
# File 'lib/schked/worker.rb', line 35 def schedule config .paths .map { |path| File.read(path) } .join("\n") end |
#stop ⇒ Object
31 32 33 |
# File 'lib/schked/worker.rb', line 31 def stop scheduler.stop end |
#wait ⇒ Object
27 28 29 |
# File 'lib/schked/worker.rb', line 27 def wait scheduler.join end |