Class: Rufus::Scheduler::RepeatJob
- Defined in:
- lib/rufus/scheduler/jobs_repeat.rb
Constant Summary collapse
- FIRSTS =
[ :now, :immediately, 0 ].freeze
Constants inherited from Job
Instance Attribute Summary collapse
-
#first_at ⇒ Object
Returns the value of attribute first_at.
-
#last_at ⇒ Object
Returns the value of attribute last_at.
-
#paused_at ⇒ Object
readonly
Returns the value of attribute paused_at.
-
#times ⇒ Object
Returns the value of attribute times.
Attributes inherited from Job
#callable, #count, #handler, #id, #last_time, #last_work_time, #locals, #mean_work_time, #name, #next_time, #opts, #original, #previous_time, #scheduled_at, #tags, #unscheduled_at
Instance Method Summary collapse
- #determine_id ⇒ Object
-
#initialize(scheduler, duration, opts, block) ⇒ RepeatJob
constructor
A new instance of RepeatJob.
-
#next_times(count) ⇒ Object
Starting from now, returns the Job#count next occurences (EtOrbi::EoTime instances) for this job.
- #occurrences(time0, time1) ⇒ Object
- #pause ⇒ Object
- #paused? ⇒ Boolean
- #resume(opts = {}) ⇒ Object
- #trigger(time) ⇒ Object
Methods inherited from Job
#[], #[]=, #call, #check_frequency, #entries, #has_key?, #keys, #kill, #past?, #resume_discard_past=, #running?, #scheduled?, #source_location, #threads, #trigger_off_schedule, #unschedule, #values
Constructor Details
#initialize(scheduler, duration, opts, block) ⇒ RepeatJob
Returns a new instance of RepeatJob.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/rufus/scheduler/jobs_repeat.rb', line 10 def initialize(scheduler, duration, opts, block) super @paused_at = nil @times = opts[:times] @first_at_no_error = opts[:first_at_no_error] || false fail ArgumentError.new( "cannot accept :times => #{@times.inspect}, not nil or an int" ) unless @times == nil || @times.is_a?(Integer) self.first_at = opts[:first] || opts[:first_time] || opts[:first_at] || opts[:first_in] || nil self.last_at = opts[:last] || opts[:last_at] || opts[:last_in] @resume_discard_past = nil end |
Instance Attribute Details
#first_at ⇒ Object
Returns the value of attribute first_at.
6 7 8 |
# File 'lib/rufus/scheduler/jobs_repeat.rb', line 6 def first_at @first_at end |
#last_at ⇒ Object
Returns the value of attribute last_at.
7 8 9 |
# File 'lib/rufus/scheduler/jobs_repeat.rb', line 7 def last_at @last_at end |
#paused_at ⇒ Object (readonly)
Returns the value of attribute paused_at.
4 5 6 |
# File 'lib/rufus/scheduler/jobs_repeat.rb', line 4 def paused_at @paused_at end |
#times ⇒ Object
Returns the value of attribute times.
8 9 10 |
# File 'lib/rufus/scheduler/jobs_repeat.rb', line 8 def times @times end |
Instance Method Details
#determine_id ⇒ Object
107 108 109 110 111 112 113 114 |
# File 'lib/rufus/scheduler/jobs_repeat.rb', line 107 def determine_id [ self.class.name.split(':').last.downcase[0..-4], @scheduled_at.to_f, (self.object_id < 0 ? 'm' : '') + self.object_id.to_s ].map(&:to_s).join('_') end |
#next_times(count) ⇒ Object
Starting from now, returns the Job#count next occurences (EtOrbi::EoTime instances) for this job.
Warning, for IntervalJob, the @mean_work_time is used since “interval” works from the end of a job to its next trigger (not from one trigger to the next, as for “cron” and “every”).
144 145 146 147 148 149 |
# File 'lib/rufus/scheduler/jobs_repeat.rb', line 144 def next_times(count) (count - 1).times.inject([ next_time ]) { |a| a << next_time_from(a.last) a } end |
#occurrences(time0, time1) ⇒ Object
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/rufus/scheduler/jobs_repeat.rb', line 116 def occurrences(time0, time1) a = [] nt = @next_time ts = @times loop do break if nt > time1 break if ts && ts <= 0 a << nt if nt >= time0 nt = next_time_from(nt) ts = ts - 1 if ts end a end |
#pause ⇒ Object
91 92 93 94 |
# File 'lib/rufus/scheduler/jobs_repeat.rb', line 91 def pause @paused_at = EoTime.now end |
#paused? ⇒ Boolean
102 103 104 105 |
# File 'lib/rufus/scheduler/jobs_repeat.rb', line 102 def paused? !! @paused_at end |
#resume(opts = {}) ⇒ Object
96 97 98 99 100 |
# File 'lib/rufus/scheduler/jobs_repeat.rb', line 96 def resume(opts={}) @resume_discard_past = opts[:discard_past] @paused_at = nil end |
#trigger(time) ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/rufus/scheduler/jobs_repeat.rb', line 76 def trigger(time) return if @paused_at #return set_next_time(time) if @paused_at return (@next_time = nil) if @times && @times < 1 return (@next_time = nil) if @last_at && time >= @last_at # # It keeps jobs one step too much in @jobs, but it's OK super @times -= 1 if @times end |