diff --git a/lib/rufus/scheduler.rb b/lib/rufus/scheduler.rb index 0455a1ca..d33c2135 100644 --- a/lib/rufus/scheduler.rb +++ b/lib/rufus/scheduler.rb @@ -194,9 +194,7 @@ def pause def resume(opts={}) dp = opts[:discard_past] - jobs.each do |job| - job.resume_discard_past = dp if job.respond_to?(:resume_discard_past=) - end if dp != nil + jobs.each { |job| job.resume_discard_past = dp } @paused_at = nil end diff --git a/lib/rufus/scheduler/jobs_core.rb b/lib/rufus/scheduler/jobs_core.rb index 767489da..19944ff8 100644 --- a/lib/rufus/scheduler/jobs_core.rb +++ b/lib/rufus/scheduler/jobs_core.rb @@ -36,6 +36,10 @@ class KillSignal < StandardError; end # attr_reader :handler + # Default, core, implementation has no effect. Repeat jobs do override it. + # + def resume_discard_past=(v); end + def initialize(scheduler, original, opts, block) @scheduler = scheduler diff --git a/lib/rufus/scheduler/jobs_repeat.rb b/lib/rufus/scheduler/jobs_repeat.rb index 3c196603..94ce5087 100644 --- a/lib/rufus/scheduler/jobs_repeat.rb +++ b/lib/rufus/scheduler/jobs_repeat.rb @@ -143,6 +143,17 @@ def next_times(count) a << next_time_from(a.last) a } end + + protected + + def discard_past? + + dp = @scheduler.discard_past + dp = @discard_past if @discard_past != nil + dp = @resume_discard_past if @resume_discard_past != nil + + dp + end end # @@ -201,14 +212,12 @@ def set_next_time(trigger_time, is_post=false, now=nil) return @next_time = @first_at \ if @first_at && (trigger_time == nil || @first_at > n) - dp = @scheduler.discard_past - dp = @discard_past if @discard_past != nil - dp = @resume_discard_past if @resume_discard_past != nil - @resume_discard_past = nil # reset that -#p [ :dp, dp ] + dp = discard_past? loop do + @next_time = (@next_time || n) + @frequency + break if dp == false break if @next_time > n end