Module: Delayed::RecurringJob
- Defined in:
- lib/delayed/recurring_job.rb
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Instance Method Summary collapse
- #failure ⇒ Object
- #next_run_time ⇒ Object
-
#schedule!(options = {}) ⇒ Object
Schedule this “repeating” job.
- #success ⇒ Object
Class Method Details
.included(base) ⇒ Object
8 9 10 11 12 13 14 |
# File 'lib/delayed/recurring_job.rb', line 8 def self.included(base) base.extend(ClassMethods) base.class_eval do @@logger = Delayed::Worker.logger cattr_reader :logger end end |
Instance Method Details
#failure ⇒ Object
16 17 18 |
# File 'lib/delayed/recurring_job.rb', line 16 def failure schedule! end |
#next_run_time ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/delayed/recurring_job.rb', line 57 def next_run_time times = @schedule_options[:run_at] times = [times] unless times.is_a? Array times = times.map{|time| parse_time(time, @schedule_options[:timezone])} times = times.map{|time| time.in_time_zone @schedule_options[:timezone]} if @schedule_options[:timezone] interval = deserialize_duration(@schedule_options[:run_interval]) until next_time = next_future_time(times) times.map!{ |time| time + interval } end # Update @schedule_options to avoid growing number of calculations each time @schedule_options[:run_at] = times next_time end |
#schedule!(options = {}) ⇒ Object
Schedule this “repeating” job
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/delayed/recurring_job.rb', line 25 def schedule! = {} = .dup.reverse_merge(@schedule_options || {}) if [:new_instance] && !.delete(:reentry) return self.class.new.schedule! .merge(reentry: true) end if run_every = .delete(:run_every) [:run_interval] = serialize_duration(run_every) end @schedule_options = .reverse_merge( run_at: self.class.run_at, timezone: self.class.timezone, run_interval: serialize_duration(self.class.run_every), priority: self.class.priority, queue: self.class.queue ) enqueue_opts = { priority: @schedule_options[:priority], run_at: next_run_time } enqueue_opts[:queue] = @schedule_options[:queue] if @schedule_options[:queue] Delayed::Job.transaction do self.class.jobs(@schedule_options).destroy_all if Gem.loaded_specs['delayed_job'].version.to_s.first.to_i < 3 Delayed::Job.enqueue self, enqueue_opts[:priority], enqueue_opts[:run_at] else Delayed::Job.enqueue self, enqueue_opts end end end |
#success ⇒ Object
20 21 22 |
# File 'lib/delayed/recurring_job.rb', line 20 def success schedule! end |