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
# 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

#pauseObject



24
25
26
# File 'lib/schked/worker.rb', line 24

def pause
  scheduler.pause
end

#scheduleObject



36
37
38
39
40
41
42
43
# File 'lib/schked/worker.rb', line 36

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

#stopObject



32
33
34
# File 'lib/schked/worker.rb', line 32

def stop
  scheduler.stop
end

#waitObject



28
29
30
# File 'lib/schked/worker.rb', line 28

def wait
  scheduler.join
end