lib/rufus/scheduler/jobs.rb in rufus-scheduler-3.5.2 vs lib/rufus/scheduler/jobs.rb in rufus-scheduler-3.6.0
- old
+ new
@@ -175,10 +175,15 @@
# o.class == self.class && o.hash == self.hash
#end
#
# might be necessary at some point
+ def next_times(count)
+
+ next_time ? [ next_time ] : []
+ end
+
# Calls the callable (usually a block) wrapped in this Job instance.
#
# Warning: error rescueing is the responsibity of the caller.
#
def call(do_rescue=false)
@@ -518,10 +523,24 @@
ts = ts - 1 if ts
end
a
end
+
+ # Starting from now, returns the {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").
+ #
+ def next_times(count)
+
+ (count - 1).times.inject([ next_time ]) { |a|
+ a << next_time_from(a.last)
+ a }
+ end
end
#
# A parent class of EveryJob and IntervalJob
#
@@ -557,10 +576,15 @@
"job frequency (#{@frequency}s) is higher than " +
"scheduler frequency (#{@scheduler.frequency}s)"
) if @frequency < @scheduler.frequency
end
+ def next_time_from(time)
+
+ time + @frequency
+ end
+
protected
def set_next_time(trigger_time, is_post=false)
return if is_post
@@ -572,15 +596,10 @@
@first_at
else
(@next_time || n) + @frequency
end
end
-
- def next_time_from(time)
-
- time + @frequency
- end
end
class IntervalJob < EvInJob
attr_reader :interval
@@ -597,10 +616,15 @@
) if @interval <= 0
set_next_time(nil)
end
+ def next_time_from(time)
+
+ time + @mean_work_time + @interval
+ end
+
protected
def set_next_time(trigger_time, is_post=false)
@next_time =
@@ -614,26 +638,21 @@
end
else
false
end
end
-
- def next_time_from(time)
-
- time + @mean_work_time + @interval
- end
end
class CronJob < RepeatJob
attr_reader :cron_line
def initialize(scheduler, cronline, opts, block)
super(scheduler, cronline, opts, block)
- @cron_line = opts[:_t] || ::Fugit::Cron.parse(cronline)
+ @cron_line = opts[:_t] || ::Fugit::Cron.do_parse(cronline)
set_next_time(nil)
end
def check_frequency
@@ -659,23 +678,23 @@
def rough_frequency
@cron_line.rough_frequency
end
- protected
-
- def set_next_time(trigger_time, is_post=false)
-
- @next_time = next_time_from(trigger_time || Time.now)
- end
-
def next_time_from(time)
if @first_at == nil || @first_at <= time
@cron_line.next_time(time)
else
@first_at
end
+ end
+
+ protected
+
+ def set_next_time(trigger_time, is_post=false)
+
+ @next_time = next_time_from(trigger_time || Time.now)
end
end
end
end