rufus-scheduler 3.3.4 → 3.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: aadc34a3585ec0563a43eeecee75009ac311490f
4
- data.tar.gz: ea9e07f929da453a7fe63711bd80c75457444f6d
3
+ metadata.gz: ad34820fe55c8eccd3edf74096abc62679e1469b
4
+ data.tar.gz: d571059ae2153fc7b6c8db515b4b37ffe965d091
5
5
  SHA512:
6
- metadata.gz: f43b61128d67c893d88a1a796dbf029c3d18577a80d4f8874c25d8272318252c96da6f499c561e5bafa25349c228d0c950a937db12b492ef2f348667b2ba700d
7
- data.tar.gz: c01cbfd377824b64f148f515e65db781f5433eaab1d574fd46c45210139bf1fbbb3ec5b8208f371044bdde909bb7917d38955d5e3dd8fcd3bdff79ef4f52d450
6
+ metadata.gz: 9524bfda419a72978d51f135243394d2af6b3805003681e6732f3270c49d14237b03943378f69171c62f40d2f0c379e2f3e971243015970d6d21341ef00f9379
7
+ data.tar.gz: d9320d55f5a4e9c43ffdb1e4b270bcf62c547386bec3ccd781a5f4e171ad8f92dc4cccba3a89f5ecb4412fc3f61fb23a34931ba40353c884069cbdfffd429d34
data/CHANGELOG.txt CHANGED
@@ -2,6 +2,13 @@
2
2
  = rufus-scheduler CHANGELOG.txt
3
3
 
4
4
 
5
+ == rufus-scheduler - 3.4.0 released 2017-03-23
6
+
7
+ - Stop supporting Ruby < 1.9
8
+ - Drop ZoTime for et-orbi's Etorbi::EoTime, gh-240
9
+ - Fix for ZooKeeper example, thanks to @djrodgerspryor, gh-238
10
+
11
+
5
12
  == rufus-scheduler - 3.3.4 released 2017-02-16
6
13
 
7
14
  - More detailed "cannot determine timezone from nil" message, gh-237
data/CREDITS.txt CHANGED
@@ -4,6 +4,9 @@
4
4
 
5
5
  == Contributors
6
6
 
7
+ - Benjamin Fleischer (https://github.com/bf4) - ZoTime#subtract
8
+ - Sam Rowe (https://github.com/riddley) - gh-240 timezone for Debian
9
+ - Daniel Rodgers-Pryor (https://github.com/djrodgerspryor) - gh-238 fix ZooKeeper example
7
10
  - Cody Cutrer (https://github.com/ccutrer) - gh-232 is_a?(Fixnum) replacement
8
11
  - Dominik Sander (https://github.com/dsander) - gh-225, gh-226
9
12
  - Piavka (https://github.com/piavka) - Job#trigger_off_schedule, gh-214
@@ -53,6 +56,7 @@
53
56
 
54
57
  == Feedback
55
58
 
59
+ - Vito Laurenza - https://github.com/veetow - help debugging tz issues - gh-240
56
60
  - Yoshimi Keiji - https://githuc.com/walf443 - v.3.3.3 mislabelling
57
61
  - Alexander Deeb - https://github.com/adeeb1 - gh-230
58
62
  - Sofia Bravo - http://stackoverflow.com/users/1123850/sofia-bravo - gh-231
data/README.md CHANGED
@@ -439,7 +439,7 @@ job.first_at = Time.now + 10
439
439
  job.first_at = Rufus::Scheduler.parse('2029-12-12')
440
440
  ```
441
441
 
442
- The first argument (in all its flavours) accepts a :now or :immediately value. That schedules the first occurence for immediate triggering. Consider:
442
+ The first argument (in all its flavours) accepts a :now or :immediately value. That schedules the first occurrence for immediate triggering. Consider:
443
443
 
444
444
  ```ruby
445
445
  require 'rufus-scheduler'
@@ -847,7 +847,7 @@ Every jobs use a time duration between each start of their execution, while inte
847
847
 
848
848
  ### frequency
849
849
 
850
- It returns the shortest interval of time between two potential occurences of the job.
850
+ It returns the shortest interval of time between two potential occurrences of the job.
851
851
 
852
852
  For instance:
853
853
  ```ruby
@@ -1282,7 +1282,7 @@ end
1282
1282
 
1283
1283
  This uses a [zookeeper](http://zookeeper.apache.org/) to make sure only one scheduler in a group of distributed schedulers runs.
1284
1284
 
1285
- The methods #lock and #unlock are overriden and #confirm_lock is provided,
1285
+ The methods #lock and #unlock are overridden and #confirm_lock is provided,
1286
1286
  to make sure that the lock is still valid.
1287
1287
 
1288
1288
  The #confirm_lock method is called right before a job triggers (if it is provided). The more generic callback #on_pre_trigger is called right after #confirm_lock.
@@ -1449,7 +1449,7 @@ rufus-scheduler/lib/rufus/scheduler/zotime.rb:41:
1449
1449
  ...
1450
1450
  ```
1451
1451
 
1452
- It may happen on Windows or on systems that poorly hints to Ruby on which timezone to use. It should be solved by setting explicitely the `ENV['TZ']` before the scheduler instantiation:
1452
+ It may happen on Windows or on systems that poorly hints to Ruby on which timezone to use. It should be solved by setting explicitly the `ENV['TZ']` before the scheduler instantiation:
1453
1453
  ```ruby
1454
1454
  ENV['TZ'] = 'Asia/Shanghai'
1455
1455
  scheduler = Rufus::Scheduler.new
@@ -1,46 +1,26 @@
1
- #--
2
- # Copyright (c) 2006-2017, John Mettraux, jmettraux@gmail.com
3
- #
4
- # Permission is hereby granted, free of charge, to any person obtaining a copy
5
- # of this software and associated documentation files (the "Software"), to deal
6
- # in the Software without restriction, including without limitation the rights
7
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
- # copies of the Software, and to permit persons to whom the Software is
9
- # furnished to do so, subject to the following conditions:
10
- #
11
- # The above copyright notice and this permission notice shall be included in
12
- # all copies or substantial portions of the Software.
13
- #
14
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20
- # THE SOFTWARE.
21
- #
22
- # Made in Japan.
23
- #++
24
1
 
2
+ require 'set'
25
3
  require 'date' if RUBY_VERSION < '1.9.0'
26
4
  require 'time'
27
5
  require 'thread'
28
- require 'tzinfo'
6
+
7
+ require 'et-orbi'
29
8
 
30
9
 
31
10
  module Rufus
32
11
 
33
12
  class Scheduler
34
13
 
14
+ VERSION = '3.4.0'
15
+
16
+ EoTime = ::EtOrbi::EoTime
17
+
35
18
  require 'rufus/scheduler/util'
36
- require 'rufus/scheduler/zotime'
37
19
  require 'rufus/scheduler/jobs'
38
20
  require 'rufus/scheduler/cronline'
39
21
  require 'rufus/scheduler/job_array'
40
22
  require 'rufus/scheduler/locks'
41
23
 
42
- VERSION = '3.3.4'
43
-
44
24
  #
45
25
  # A common error class for rufus-scheduler
46
26
  #
@@ -104,7 +84,7 @@ module Rufus
104
84
  @trigger_lock = opts[:trigger_lock] || Rufus::Scheduler::NullLock.new
105
85
 
106
86
  # If we can't grab the @scheduler_lock, don't run.
107
- @scheduler_lock.lock || return
87
+ lock || return
108
88
 
109
89
  start
110
90
  end
@@ -154,12 +134,12 @@ module Rufus
154
134
 
155
135
  def uptime
156
136
 
157
- @started_at ? Rufus::Scheduler::ZoTime.now - @started_at : nil
137
+ @started_at ? EoTime.now - @started_at : nil
158
138
  end
159
139
 
160
140
  def uptime_s
161
141
 
162
- self.class.to_duration(uptime)
142
+ uptime ? self.class.to_duration(uptime) : ''
163
143
  end
164
144
 
165
145
  def join
@@ -409,7 +389,7 @@ module Rufus
409
389
  # Accepts a query option, which can be set to:
410
390
  # * :all (default), returns all the threads that are work threads
411
391
  # or are currently running a job
412
- # * :active, returns all threads that are currenly running a job
392
+ # * :active, returns all threads that are currently running a job
413
393
  # * :vacant, returns the threads that are not running a job
414
394
  #
415
395
  # If, thanks to :blocking => true, a job is scheduled to monopolize the
@@ -478,7 +458,9 @@ module Rufus
478
458
  stderr.puts(" #{pre} tz:")
479
459
  stderr.puts(" #{pre} ENV['TZ']: #{ENV['TZ']}")
480
460
  stderr.puts(" #{pre} Time.now: #{Time.now}")
481
- stderr.puts(" #{pre} local_tzone: #{Rufus::Scheduler::ZoTime.local_tzone.inspect}")
461
+ stderr.puts(" #{pre} local_tzone: #{EoTime.local_tzone.inspect}")
462
+ stderr.puts(" #{pre} et-orbi:")
463
+ stderr.puts(" #{pre} #{EoTime.platform_info}")
482
464
  stderr.puts(" #{pre} scheduler:")
483
465
  stderr.puts(" #{pre} object_id: #{object_id}")
484
466
  stderr.puts(" #{pre} opts:")
@@ -558,7 +540,7 @@ module Rufus
558
540
 
559
541
  def start
560
542
 
561
- @started_at = Rufus::Scheduler::ZoTime.now
543
+ @started_at = EoTime.now
562
544
 
563
545
  @thread =
564
546
  Thread.new do
@@ -585,7 +567,7 @@ module Rufus
585
567
 
586
568
  def trigger_jobs
587
569
 
588
- now = Rufus::Scheduler::ZoTime.now
570
+ now = EoTime.now
589
571
 
590
572
  @jobs.each(now) do |job|
591
573
 
@@ -604,9 +586,9 @@ module Rufus
604
586
  next unless job && to && ts
605
587
  # thread might just have become inactive (job -> nil)
606
588
 
607
- to = ts + to unless to.is_a?(Rufus::Scheduler::ZoTime)
589
+ to = ts + to unless to.is_a?(EoTime)
608
590
 
609
- next if to > Rufus::Scheduler::ZoTime.now
591
+ next if to > EoTime.now
610
592
 
611
593
  t.raise(Rufus::Scheduler::TimeoutError)
612
594
  end
@@ -1,28 +1,3 @@
1
- #--
2
- # Copyright (c) 2006-2017, John Mettraux, jmettraux@gmail.com
3
- #
4
- # Permission is hereby granted, free of charge, to any person obtaining a copy
5
- # of this software and associated documentation files (the "Software"), to deal
6
- # in the Software without restriction, including without limitation the rights
7
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
- # copies of the Software, and to permit persons to whom the Software is
9
- # furnished to do so, subject to the following conditions:
10
- #
11
- # The above copyright notice and this permission notice shall be included in
12
- # all copies or substantial portions of the Software.
13
- #
14
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20
- # THE SOFTWARE.
21
- #
22
- # Made in Japan.
23
- #++
24
-
25
- require 'set'
26
1
 
27
2
 
28
3
  class Rufus::Scheduler
@@ -63,10 +38,10 @@ class Rufus::Scheduler
63
38
 
64
39
  items = line.split
65
40
 
66
- if @timezone = ZoTime.get_tzone(items.last)
41
+ if @timezone = EoTime.get_tzone(items.last)
67
42
  @original_timezone = items.pop
68
43
  else
69
- @timezone = ZoTime.get_tzone(:current)
44
+ @timezone = EoTime.local_tzone
70
45
  end
71
46
 
72
47
  fail ArgumentError.new(
@@ -99,10 +74,10 @@ class Rufus::Scheduler
99
74
  #
100
75
  def matches?(time)
101
76
 
102
- # FIXME Don't create a new ZoTime if time is already a ZoTime in same
77
+ # FIXME Don't create a new EoTime if time is already a EoTime in same
103
78
  # zone ...
104
79
  # Wait, this seems only used in specs...
105
- t = ZoTime.new(time.to_f, @timezone)
80
+ t = EoTime.new(time.to_f, @timezone)
106
81
 
107
82
  return false unless sub_match?(t, :sec, @seconds)
108
83
  return false unless sub_match?(t, :min, @minutes)
@@ -138,10 +113,10 @@ class Rufus::Scheduler
138
113
  #
139
114
  # (Thanks to K Liu for the note and the examples)
140
115
  #
141
- def next_time(from=ZoTime.now)
116
+ def next_time(from=EoTime.now)
142
117
 
143
118
  nt = nil
144
- zt = ZoTime.new(from.to_i + 1, @timezone)
119
+ zt = EoTime.new(from.to_i + 1, @timezone)
145
120
  maxy = from.year + NEXT_TIME_MAX_YEARS
146
121
 
147
122
  loop do
@@ -179,10 +154,10 @@ class Rufus::Scheduler
179
154
  # Returns the previous time the cronline matched. It's like next_time, but
180
155
  # for the past.
181
156
  #
182
- def previous_time(from=ZoTime.now)
157
+ def previous_time(from=EoTime.now)
183
158
 
184
159
  pt = nil
185
- zt = ZoTime.new(from.to_i - 1, @timezone)
160
+ zt = EoTime.new(from.to_i - 1, @timezone)
186
161
  miny = from.year - NEXT_TIME_MAX_YEARS
187
162
 
188
163
  loop do
@@ -195,19 +170,19 @@ class Rufus::Scheduler
195
170
  ) if pt.year < miny
196
171
 
197
172
  unless date_match?(pt)
198
- zt.substract(pt.hour * 3600 + pt.min * 60 + pt.sec + 1)
173
+ zt.subtract(pt.hour * 3600 + pt.min * 60 + pt.sec + 1)
199
174
  next
200
175
  end
201
176
  unless sub_match?(pt, :hour, @hours)
202
- zt.substract(pt.min * 60 + pt.sec + 1)
177
+ zt.subtract(pt.min * 60 + pt.sec + 1)
203
178
  next
204
179
  end
205
180
  unless sub_match?(pt, :min, @minutes)
206
- zt.substract(pt.sec + 1)
181
+ zt.subtract(pt.sec + 1)
207
182
  next
208
183
  end
209
184
  unless sub_match?(pt, :sec, @seconds)
210
- zt.substract(prev_second(pt))
185
+ zt.subtract(prev_second(pt))
211
186
  next
212
187
  end
213
188
 
@@ -259,7 +234,7 @@ class Rufus::Scheduler
259
234
  #
260
235
  @cache = {}; class << self; attr_reader :cache; end
261
236
 
262
- # Returns the shortest delta between two potential occurences of the
237
+ # Returns the shortest delta between two potential occurrences of the
263
238
  # schedule described by this cronline.
264
239
  #
265
240
  # .
@@ -1,27 +1,3 @@
1
- #--
2
- # Copyright (c) 2006-2017, John Mettraux, jmettraux@gmail.com
3
- #
4
- # Permission is hereby granted, free of charge, to any person obtaining a copy
5
- # of this software and associated documentation files (the "Software"), to deal
6
- # in the Software without restriction, including without limitation the rights
7
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
- # copies of the Software, and to permit persons to whom the Software is
9
- # furnished to do so, subject to the following conditions:
10
- #
11
- # The above copyright notice and this permission notice shall be included in
12
- # all copies or substantial portions of the Software.
13
- #
14
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20
- # THE SOFTWARE.
21
- #
22
- # Made in Japan.
23
- #++
24
-
25
1
 
26
2
  module Rufus
27
3
 
@@ -1,27 +1,3 @@
1
- #--
2
- # Copyright (c) 2006-2017, John Mettraux, jmettraux@gmail.com
3
- #
4
- # Permission is hereby granted, free of charge, to any person obtaining a copy
5
- # of this software and associated documentation files (the "Software"), to deal
6
- # in the Software without restriction, including without limitation the rights
7
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
- # copies of the Software, and to permit persons to whom the Software is
9
- # furnished to do so, subject to the following conditions:
10
- #
11
- # The above copyright notice and this permission notice shall be included in
12
- # all copies or substantial portions of the Software.
13
- #
14
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20
- # THE SOFTWARE.
21
- #
22
- # Made in Japan.
23
- #++
24
-
25
1
 
26
2
  module Rufus
27
3
 
@@ -86,7 +62,7 @@ module Rufus
86
62
  nil
87
63
  end
88
64
 
89
- @scheduled_at = Rufus::Scheduler::ZoTime.now
65
+ @scheduled_at = EoTime.now
90
66
  @unscheduled_at = nil
91
67
  @last_time = nil
92
68
 
@@ -132,14 +108,14 @@ module Rufus
132
108
  # Done in collaboration with Piavka in
133
109
  # https://github.com/jmettraux/rufus-scheduler/issues/214
134
110
  #
135
- def trigger_off_schedule(time=Rufus::Scheduler::ZoTime.now)
111
+ def trigger_off_schedule(time=EoTime.now)
136
112
 
137
113
  do_trigger(time)
138
114
  end
139
115
 
140
116
  def unschedule
141
117
 
142
- @unscheduled_at = Rufus::Scheduler::ZoTime.now
118
+ @unscheduled_at = EoTime.now
143
119
  end
144
120
 
145
121
  def threads
@@ -199,7 +175,7 @@ module Rufus
199
175
  #
200
176
  def call(do_rescue=false)
201
177
 
202
- do_call(Rufus::Scheduler::ZoTime.now, do_rescue)
178
+ do_call(EoTime.now, do_rescue)
203
179
  end
204
180
 
205
181
  protected
@@ -266,7 +242,7 @@ module Rufus
266
242
 
267
243
  def trigger_now(time)
268
244
 
269
- t = Rufus::Scheduler::ZoTime.now
245
+ t = EoTime.now
270
246
  # if there are mutexes, t might be really bigger than time
271
247
 
272
248
  Thread.current[:rufus_scheduler_job] = self
@@ -280,7 +256,7 @@ module Rufus
280
256
  ensure
281
257
 
282
258
  @last_work_time =
283
- Rufus::Scheduler::ZoTime.now - Thread.current[:rufus_scheduler_time]
259
+ EoTime.now - Thread.current[:rufus_scheduler_time]
284
260
  @mean_work_time =
285
261
  ((@count - 1) * @mean_work_time + @last_work_time) / @count
286
262
 
@@ -440,12 +416,13 @@ module Rufus
440
416
 
441
417
  return (@first_at = nil) if first == nil
442
418
 
443
- n0 = Rufus::Scheduler::ZoTime.now
419
+ n0 = EoTime.now
444
420
  n1 = n0 + 0.003
445
421
 
446
422
  first = n0 if first == :now || first == :immediately || first == 0
423
+ fdur = Rufus::Scheduler.parse_duration(first, no_error: true)
447
424
 
448
- @first_at = ZoTime.make(first)
425
+ @first_at = (fdur && (EoTime.now + fdur)) || EoTime.make(first)
449
426
  @first_at = n1 if @first_at >= n0 && @first_at < n1
450
427
 
451
428
  fail ArgumentError.new(
@@ -458,13 +435,18 @@ module Rufus
458
435
 
459
436
  def last_at=(last)
460
437
 
461
- #@last_at = last ? Rufus::Scheduler.parse_to_time(last) : nil
462
- @last_at = last ? ZoTime.make(last) : nil
438
+ @last_at =
439
+ if last
440
+ ldur = Rufus::Scheduler.parse_duration(last, no_error: true)
441
+ (ldur && (EoTime.now + ldur)) || EoTime.make(last)
442
+ else
443
+ nil
444
+ end
463
445
 
464
446
  fail ArgumentError.new(
465
447
  "cannot set last[_at|_in] in the past: " +
466
448
  "#{last.inspect} -> #{@last_at.inspect}"
467
- ) if last && @last_at < Rufus::Scheduler::ZoTime.now
449
+ ) if last && @last_at < EoTime.now
468
450
 
469
451
  @last_at
470
452
  end
@@ -485,7 +467,7 @@ module Rufus
485
467
 
486
468
  def pause
487
469
 
488
- @paused_at = Rufus::Scheduler::ZoTime.now
470
+ @paused_at = EoTime.now
489
471
  end
490
472
 
491
473
  def resume
@@ -564,7 +546,7 @@ module Rufus
564
546
 
565
547
  return if is_post
566
548
 
567
- n = Rufus::Scheduler::ZoTime.now
549
+ n = EoTime.now
568
550
 
569
551
  @next_time =
570
552
  if @first_at && (trigger_time == nil || @first_at > n)
@@ -604,10 +586,10 @@ module Rufus
604
586
 
605
587
  @next_time =
606
588
  if is_post
607
- Rufus::Scheduler::ZoTime.now + @interval
589
+ EoTime.now + @interval
608
590
  elsif trigger_time.nil?
609
591
  if @first_at == nil || @first_at < Time.now
610
- Rufus::Scheduler::ZoTime.now + @interval
592
+ EoTime.now + @interval
611
593
  else
612
594
  @first_at
613
595
  end