lib/rufus/scheduler/cronline.rb in rufus-scheduler-3.0.3 vs lib/rufus/scheduler/cronline.rb in rufus-scheduler-3.0.4

- old
+ new

@@ -1,7 +1,7 @@ #-- -# Copyright (c) 2006-2013, John Mettraux, jmettraux@gmail.com +# Copyright (c) 2006-2014, 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 @@ -195,10 +195,32 @@ @monthdays, @timezone ? @timezone.name : nil ] end + # Returns a quickly computed approximation of the frequency for this + # cron line. + # + # #brute_frequency, on the other hand, will compute the frequency by + # examining a whole, that can take more than seconds for a seconds + # level cron... + # + def frequency + + return brute_frequency unless @seconds && @seconds.length > 1 + + delta = 60 + prev = @seconds[0] + + @seconds[1..-1].each do |sec| + d = sec - prev + delta = d if d < delta + end + + delta + end + # Returns the shortest delta between two potential occurences of the # schedule described by this cronline. # # . # @@ -219,10 +241,10 @@ # One obvious improvement would be to cache the result once computed... # # See https://github.com/jmettraux/rufus-scheduler/issues/89 # for a discussion about this method. # - def frequency + def brute_frequency delta = 366 * DAY_S t0 = previous_time(Time.local(2000, 1, 1))