lib/rufus/scheduler/jobs.rb in rufus-scheduler-3.0.9 vs lib/rufus/scheduler/jobs.rb in rufus-scheduler-3.1.0

- old
+ new

@@ -1,7 +1,7 @@ #-- -# Copyright (c) 2006-2014, John Mettraux, jmettraux@gmail.com +# Copyright (c) 2006-2015, John Mettraux, jmettraux@gmail.com # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell @@ -338,11 +338,11 @@ alias time next_time def occurrences(time0, time1) - time >= time0 && time <= time1 ? [ time ] : [] + (time >= time0 && time <= time1) ? [ time ] : [] end protected def determine_id @@ -407,19 +407,21 @@ ) unless @times == nil || @times.is_a?(Fixnum) self.first_at = opts[:first] || opts[:first_time] || opts[:first_at] || opts[:first_in] || - 0 + nil self.last_at = opts[:last] || opts[:last_at] || opts[:last_in] end def first_at=(first) + return @first_at = nil if first == nil + n = Time.now - first = n + 0.001 if first == :now || first == :immediately + first = n + 0.003 if first == :now || first == :immediately @first_at = Rufus::Scheduler.parse_to_time(first) raise ArgumentError.new( "cannot set first[_at|_in] in the past: " + @@ -438,13 +440,10 @@ end def trigger(time) return if @paused_at - return if time < @first_at - # - # TODO: remove me when @first_at gets reworked return (@next_time = nil) if @times && @times < 1 return (@next_time = nil) if @last_at && time >= @last_at # # TODO: rework that, jobs are thus kept 1 step too much in @jobs @@ -536,14 +535,12 @@ def set_next_time(trigger_time, is_post=false) return if is_post @next_time = - if trigger_time - trigger_time + @frequency - elsif @first_at < Time.now - Time.now + @frequency + if @first_at == nil || @first_at < Time.now + (trigger_time || Time.now) + @frequency else @first_at end end @@ -577,11 +574,11 @@ @next_time = if is_post Time.now + @interval elsif trigger_time.nil? - if @first_at < Time.now + if @first_at == nil || @first_at < Time.now Time.now + @interval else @first_at end else @@ -600,11 +597,11 @@ def initialize(scheduler, cronline, opts, block) super(scheduler, cronline, opts, block) @cron_line = opts[:_t] || CronLine.new(cronline) - @next_time = @cron_line.next_time + set_next_time(nil) end def frequency @cron_line.frequency @@ -617,15 +614,19 @@ protected def set_next_time(trigger_time, is_post=false) - @next_time = @cron_line.next_time + @next_time = next_time_from(trigger_time || Time.now) end def next_time_from(time) - @cron_line.next_time(time) + if @first_at == nil || @first_at < time + @cron_line.next_time(time) + else + @first_at + end end end end end