Class: Schked::Worker

Inherits:
Object
  • Object
show all
Defined in:
lib/schked/worker.rb

Instance Method Summary collapse

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

#pauseObject



26
27
28
# File 'lib/schked/worker.rb', line 26

def pause
  scheduler.pause
end

#scheduleObject



39
40
41
42
43
44
45
46
# File 'lib/schked/worker.rb', line 39

def schedule
  config
    .paths
    .map { |path| File.expand_path(path) }
    .uniq
    .map { |path| File.read(path) }
    .join("\n")
end

#stopObject



34
35
36
37
# File 'lib/schked/worker.rb', line 34

def stop
  liveness_probe&.stop
  scheduler.stop
end

#waitObject



30
31
32
# File 'lib/schked/worker.rb', line 30

def wait
  scheduler.join
end