rufus-scheduler 1.0.4 → 1.0.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,6 +2,13 @@
2
2
  = rufus-scheduler CHANGELOG.txt
3
3
 
4
4
 
5
+ == rufus-scheduler - 1.0.5 released 2008/03/17
6
+
7
+ - bug #18363 : constrained precision to 0.0 < p <= 1.0 - s188
8
+ - todo #18821 : best effort drift correction integrated - s187
9
+ - bug #18513 : 0 seconds and :drop_seconds => "0m". Fixed - s186
10
+
11
+
5
12
  == rufus-scheduler - 1.0.4 released 2008/02/29
6
13
 
7
14
  - todo #18474 : implemented to_duration_array() - s183
@@ -3,6 +3,8 @@
3
3
 
4
4
  == Feedback
5
5
 
6
+ - Michael Goth, tests with precision > 1s
7
+
6
8
  * many people gave feedback previously, see
7
9
  http://openwferu.rubyforge.org/svn/trunk/openwfe-ruby/CREDITS.txt
8
10
 
@@ -268,7 +268,7 @@ module Rufus
268
268
  #
269
269
  def Rufus.to_duration_string (seconds, options={})
270
270
 
271
- return '0s' if seconds <= 0
271
+ return (options[:drop_seconds] ? '0m' : '0s') if seconds <= 0
272
272
 
273
273
  h = to_duration_hash seconds, options
274
274
 
@@ -236,7 +236,24 @@ module Rufus
236
236
  # By default, the precision is 0.250, with means the scheduler
237
237
  # will check for jobs to execute 4 times per second.
238
238
  #
239
- attr_accessor :precision
239
+ attr_reader :precision
240
+
241
+ #
242
+ # Setting the precision ( 0.0 < p <= 1.0 )
243
+ #
244
+ def precision= (f)
245
+
246
+ raise "precision must be 0.0 < p <= 1.0" \
247
+ if f <= 0.0 or f > 1.0
248
+
249
+ @precision = f
250
+ end
251
+
252
+ #--
253
+ # Set by default at 0.00045, it's meant to minimize drift
254
+ #
255
+ #attr_accessor :correction
256
+ #++
240
257
 
241
258
  #
242
259
  # As its name implies.
@@ -262,11 +279,13 @@ module Rufus
262
279
  @precision = 0.250
263
280
  # every 250ms, the scheduler wakes up (default value)
264
281
  begin
265
- @precision = Float(params[:scheduler_precision])
282
+ self.precision = Float(params[:scheduler_precision])
266
283
  rescue Exception => e
267
284
  # let precision at its default value
268
285
  end
269
286
 
287
+ #@correction = 0.00045
288
+
270
289
  @exit_when_no_more_jobs = false
271
290
  @dont_reschedule_every = false
272
291
 
@@ -296,10 +315,15 @@ module Rufus
296
315
 
297
316
  break if @stopped
298
317
 
318
+ t0 = Time.now.to_f
319
+
299
320
  step
300
321
 
301
- sleep @precision
302
- # TODO : adjust precision
322
+ d = Time.now.to_f - t0 # + @correction
323
+
324
+ next if d > @precision
325
+
326
+ sleep (@precision - d)
303
327
  end
304
328
  end
305
329
  end
@@ -665,7 +689,7 @@ module Rufus
665
689
  #
666
690
  def Scheduler.is_cron_string (s)
667
691
 
668
- s.match(".+ .+ .+ .+ .+")
692
+ s.match ".+ .+ .+ .+ .+"
669
693
  end
670
694
 
671
695
  #protected
@@ -886,7 +910,7 @@ module Rufus
886
910
 
887
911
  if @exit_when_no_more_jobs
888
912
 
889
- if @pending_jobs.size < 1
913
+ if @pending_jobs.size < 1
890
914
 
891
915
  @stopped = true
892
916
  return
@@ -911,6 +935,7 @@ module Rufus
911
935
 
912
936
  @cron_jobs.each do |cron_id, cron_job|
913
937
  #puts "step() cron_id : #{cron_id}"
938
+ #trigger(cron_job) if cron_job.matches?(now, @precision)
914
939
  trigger(cron_job) if cron_job.matches?(now)
915
940
  end
916
941
  end
@@ -1166,8 +1191,10 @@ module Rufus
1166
1191
  # has to fire this CronJob instance.
1167
1192
  #
1168
1193
  def matches? (time)
1194
+ #def matches? (time, precision)
1169
1195
 
1170
- @cron_line.matches? time
1196
+ #@cron_line.matches?(time, precision)
1197
+ @cron_line.matches?(time)
1171
1198
  end
1172
1199
 
1173
1200
  #
@@ -1240,17 +1267,29 @@ module Rufus
1240
1267
  #
1241
1268
  # Returns true if the given time matches this cron line.
1242
1269
  #
1270
+ # (the precision is passed as well to determine if it's
1271
+ # worth checking seconds and minutes)
1272
+ #
1243
1273
  def matches? (time)
1274
+ #def matches? (time, precision)
1244
1275
 
1245
1276
  time = Time.at(time) \
1246
1277
  if time.kind_of?(Float) or time.kind_of?(Integer)
1247
1278
 
1248
- return false if no_match?(time.sec, @seconds)
1249
- return false if no_match?(time.min, @minutes)
1250
- return false if no_match?(time.hour, @hours)
1251
- return false if no_match?(time.day, @days)
1252
- return false if no_match?(time.month, @months)
1253
- return false if no_match?(time.wday, @weekdays)
1279
+ return false \
1280
+ if no_match?(time.sec, @seconds)
1281
+ #if precision <= 1 and no_match?(time.sec, @seconds)
1282
+ return false \
1283
+ if no_match?(time.min, @minutes)
1284
+ #if precision <= 60 and no_match?(time.min, @minutes)
1285
+ return false \
1286
+ if no_match?(time.hour, @hours)
1287
+ return false \
1288
+ if no_match?(time.day, @days)
1289
+ return false \
1290
+ if no_match?(time.month, @months)
1291
+ return false \
1292
+ if no_match?(time.wday, @weekdays)
1254
1293
 
1255
1294
  true
1256
1295
  end
@@ -1381,10 +1420,10 @@ module Rufus
1381
1420
  return false if not cron_values
1382
1421
 
1383
1422
  cron_values.each do |v|
1384
- return false if value == v
1423
+ return false if value == v # ok, it matches
1385
1424
  end
1386
1425
 
1387
- true
1426
+ true # no match found
1388
1427
  end
1389
1428
  end
1390
1429
 
@@ -235,9 +235,9 @@ class SchedulerTest < Test::Unit::TestCase
235
235
  #
236
236
  def test_scheduler_7
237
237
 
238
- scheduler = OpenWFE::Scheduler.new(:scheduler_precision => 0.100)
238
+ scheduler = Rufus::Scheduler.new(:scheduler_precision => 0.100)
239
239
 
240
- assert_equal scheduler.precision, 0.100
240
+ assert_equal 0.100, scheduler.precision
241
241
  end
242
242
 
243
243
  #
@@ -249,7 +249,7 @@ class SchedulerTest < Test::Unit::TestCase
249
249
  #
250
250
  def test_8
251
251
 
252
- scheduler = OpenWFE::Scheduler.new
252
+ scheduler = Rufus::Scheduler.new
253
253
  scheduler.start
254
254
 
255
255
  var = false
@@ -313,6 +313,17 @@ class SchedulerTest < Test::Unit::TestCase
313
313
  scheduler.stop
314
314
  end
315
315
 
316
+ def test_10
317
+
318
+ e = nil
319
+ begin
320
+ OpenWFE::Scheduler.new.precision = 10
321
+ rescue Exception => e
322
+ end
323
+
324
+ assert_not_nil e, "exception not caught"
325
+ end
326
+
316
327
  protected
317
328
 
318
329
  class TestSchedulable
@@ -26,6 +26,7 @@ class Time1Test < Test::Unit::TestCase
26
26
  def test_0
27
27
 
28
28
  tts 0, "0s"
29
+ tts 0, "0m", { :drop_seconds => true }
29
30
  tts 60, "1m"
30
31
  tts 61, "1m1s"
31
32
  tts 3661, "1h1m1s"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rufus-scheduler
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.4
4
+ version: 1.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Mettraux
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-02-29 00:00:00 +09:00
12
+ date: 2008-03-17 00:00:00 +09:00
13
13
  default_executable:
14
14
  dependencies: []
15
15