Class: Que::Scheduler::DefinedJob

Inherits:
Hashie::Dash
  • Object
show all
Includes:
Hashie::Extensions::Dash::PropertyTranslation
Defined in:
lib/que/scheduler/defined_job.rb

Constant Summary collapse

DEFINED_JOB_TYPES =
[
  DEFINED_JOB_TYPE_DEFAULT = :default,
  DEFINED_JOB_TYPE_EVERY_EVENT = :every_event,
].freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.create(options) ⇒ Object



24
25
26
27
# File 'lib/que/scheduler/defined_job.rb', line 24

def create(options)
  defined_job = new(options.compact)
  defined_job.freeze.tap { |dj| dj.validate(options) }
end

Instance Method Details

#calculate_missed_runs(last_run_time, as_time) ⇒ Object

Given the last scheduler run time, and this run time, return all the instances that should be enqueued for the job class.



40
41
42
43
44
45
46
47
48
49
# File 'lib/que/scheduler/defined_job.rb', line 40

def calculate_missed_runs(last_run_time, as_time)
  missed_times = []
  last_time = last_run_time
  while (next_run = next_run_time(last_time, as_time))
    missed_times << next_run
    last_time = next_run
  end

  generate_to_enqueue_list(missed_times)
end

#next_run_time(from, to) ⇒ Object

Given a “last time”, return the next Time the event will occur, or nil if it is after “to”.



32
33
34
35
36
# File 'lib/que/scheduler/defined_job.rb', line 32

def next_run_time(from, to)
  next_time = cron.next_time(from)
  next_run = next_time.to_local_time.in_time_zone(next_time.zone)
  next_run <= to ? next_run : nil
end

#validate(options) ⇒ Object



51
52
53
54
55
# File 'lib/que/scheduler/defined_job.rb', line 51

def validate(options)
  validate_fields_presence(options)
  validate_fields_types(options)
  validate_job_class_related(options)
end