Class: SuperSpreader::SchedulerJob

Inherits:
ActiveJob::Base
  • Object
show all
Extended by:
StopSignal
Defined in:
lib/super_spreader/scheduler_job.rb

Instance Method Summary collapse

Methods included from StopSignal

go!, stop!, stopped?

Instance Method Details

#configObject



33
34
35
# File 'lib/super_spreader/scheduler_job.rb', line 33

def config
  @config ||= SchedulerConfig.new
end

#next_run_atObject



29
30
31
# File 'lib/super_spreader/scheduler_job.rb', line 29

def next_run_at
  config.duration.seconds.from_now
end

#performObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/super_spreader/scheduler_job.rb', line 13

def perform
  return if self.class.stopped?

  log(started_at: Time.current.iso8601)
  log(config.serializable_hash)

  super_spreader = Spreader.new(*config.super_spreader_config)
  next_id = super_spreader.enqueue_spread(**config.spread_options)
  log(next_id: next_id)

  return if next_id.zero?

  self.class.set(wait_until: next_run_at).perform_later
  log(next_run_at: next_run_at.iso8601)
end