Skip to content

Commit

Permalink
Simplify discard_past
Browse files Browse the repository at this point in the history
  • Loading branch information
jmettraux committed Nov 8, 2020
1 parent fac05b6 commit 2435304
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
4 changes: 1 addition & 3 deletions lib/rufus/scheduler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions lib/rufus/scheduler/jobs_core.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 14 additions & 5 deletions lib/rufus/scheduler/jobs_repeat.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

#
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 2435304

Please sign in to comment.