rufus-scheduler 3.3.0 → 3.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f5efdaec8fd127103673241abfcb7a14d9135aef
4
- data.tar.gz: 95b4b8f72eaea194b946e9b6738fa42b9086fc2a
3
+ metadata.gz: ad34820fe55c8eccd3edf74096abc62679e1469b
4
+ data.tar.gz: d571059ae2153fc7b6c8db515b4b37ffe965d091
5
5
  SHA512:
6
- metadata.gz: d511d09f4a9c0deffd90a97005d0824b891a55a92236cf885fde676830960ebbaad407d1a4fd4817b81d20d0f7ef9a504ad35b96a58b7a195e30bae89eda0046
7
- data.tar.gz: d4da5209b9d01d6a4c861ed022b36971377762ae31ec785d068c0070af3e098e0ff0f6939cd128a96f5752deb74c49daf798a074d6a7557fa80d125f4286dcd5
6
+ metadata.gz: 9524bfda419a72978d51f135243394d2af6b3805003681e6732f3270c49d14237b03943378f69171c62f40d2f0c379e2f3e971243015970d6d21341ef00f9379
7
+ data.tar.gz: d9320d55f5a4e9c43ffdb1e4b270bcf62c547386bec3ccd781a5f4e171ad8f92dc4cccba3a89f5ecb4412fc3f61fb23a34931ba40353c884069cbdfffd429d34
data/CHANGELOG.txt CHANGED
@@ -2,6 +2,41 @@
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
+
12
+ == rufus-scheduler - 3.3.4 released 2017-02-16
13
+
14
+ - More detailed "cannot determine timezone from nil" message, gh-237
15
+
16
+
17
+ == rufus-scheduler - 3.3.3 released 2017-01-29
18
+
19
+ - use Rails' timezone by default if Rails is present, gh-230, gh-233,
20
+ thanks Alexander Deeb
21
+ - is_a?(Fixnum) replaced by is_a?(Integer), gh-232, thanks Cody Cutrer
22
+ - Fix for every double trigger, gh-231, thanks Sofia Bravo
23
+
24
+
25
+ == rufus-scheduler - 3.3.2 released 2017-01-05
26
+
27
+ - Fix ZoTime issue with Time.zone.now #=> 'CST', thanks zzjin
28
+ - Fix cron weekdays + monthdays, by Dominik Sander, https://github.com/dsander
29
+ - Speedup CronLine#brute_frequency, by Dominik Sander
30
+ - Use object_id instead of hash to make Job id
31
+
32
+
33
+ == rufus-scheduler - 3.3.1 released 2016-12-03
34
+
35
+ - gh-222 fall back on ENV['TZ'] when Time.now.zone is something
36
+ like "中国标准时间" (ask for "Asia/Shanghai"), thanks to
37
+ https://github.com/lovingyu
38
+
39
+
5
40
  == rufus-scheduler - 3.3.0 released 2016-11-28
6
41
 
7
42
  - Bring in Piavka's Job#trigger_off_schedule, gh-214
data/CREDITS.txt CHANGED
@@ -4,6 +4,11 @@
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
10
+ - Cody Cutrer (https://github.com/ccutrer) - gh-232 is_a?(Fixnum) replacement
11
+ - Dominik Sander (https://github.com/dsander) - gh-225, gh-226
7
12
  - Piavka (https://github.com/piavka) - Job#trigger_off_schedule, gh-214
8
13
  - Paulo Delgado (https://github.com/paulodelgado) counter ActiveRecord, gh-210
9
14
  - Anjali Sharma (https://github.com/anjali-sharma) enhance job#last_time example
@@ -51,6 +56,12 @@
51
56
 
52
57
  == Feedback
53
58
 
59
+ - Vito Laurenza - https://github.com/veetow - help debugging tz issues - gh-240
60
+ - Yoshimi Keiji - https://githuc.com/walf443 - v.3.3.3 mislabelling
61
+ - Alexander Deeb - https://github.com/adeeb1 - gh-230
62
+ - Sofia Bravo - http://stackoverflow.com/users/1123850/sofia-bravo - gh-231
63
+ - zzjin - https://githu.com/zzjin - 3.3.x vs CST abbreviated timezone - gh-228
64
+ - lovingyu - https://github.com/lovingyu - fallback to ENV['TZ'] - gh-222
54
65
  - Ramon Tayag - https://github.com/ramontayag - prevent day 0 in cronlines
55
66
  - Akinori Musha - https://github.com/knu - ENV['TZ'] setting is harmful
56
67
  - Nicolás Satragno - https://twitter.com/nsatragno - parse_to_time vs Date
data/LICENSE.txt CHANGED
@@ -1,5 +1,5 @@
1
1
 
2
- Copyright (c) 2005-2016, John Mettraux, jmettraux@gmail.com
2
+ Copyright (c) 2005-2017, John Mettraux, jmettraux@gmail.com
3
3
 
4
4
  Permission is hereby granted, free of charge, to any person obtaining a copy
5
5
  of this software and associated documentation files (the "Software"), to deal
data/README.md CHANGED
@@ -8,7 +8,7 @@ Job scheduler for Ruby (at, cron, in and every jobs).
8
8
 
9
9
  It uses threads.
10
10
 
11
- **Note**: maybe are you looking for the [README of rufus-scheduler 2.x](https://github.com/jmettraux/rufus-scheduler/blob/two/README.rdoc)?
11
+ **Note**: maybe are you looking for the [README of rufus-scheduler 2.x](https://github.com/jmettraux/rufus-scheduler/blob/two/README.rdoc)? (especially if you're using [Dashing](https://github.com/Shopify/dashing) which is [stuck](https://github.com/Shopify/dashing/blob/master/dashing.gemspec) on rufus-scheduler 2.0.24)
12
12
 
13
13
  Quickstart:
14
14
  ```ruby
@@ -67,7 +67,7 @@ A rufus-scheduler instance will go on scheduling while it is present among the o
67
67
  ## related and similar gems
68
68
 
69
69
  * [Whenever](https://github.com/javan/whenever) - let cron call back your Ruby code, trusted and reliable cron drives your schedule
70
- * [Clockwork](https://github.com/tomykaira/clockwork) - rufus-scheduler inspired gem
70
+ * [Clockwork](https://github.com/Rykian/clockwork) - rufus-scheduler inspired gem
71
71
  * [Crono](https://github.com/plashchynski/crono) - an in-Rails cron scheduler
72
72
  * [PerfectSched](https://github.com/treasure-data/perfectsched) - highly available distributed cron built on [Sequel](http://sequel.jeremyevans.net) and more
73
73
 
@@ -91,7 +91,7 @@ I'll drive you right to the [tracks](#so-rails).
91
91
  * As said, no more EventMachine-based scheduler
92
92
  * ```scheduler.every('100') {``` will schedule every 100 seconds (previously, it would have been 0.1s). This aligns rufus-scheduler on Ruby's ```sleep(100)```
93
93
  * The scheduler isn't catching the whole of Exception anymore, only StandardError
94
- * The error_handler is #on_error (instead of #on_exception), by default it now prints the details of the error to $stderr (used to be $stdout)
94
+ * The error_handler is [#on_error](#rufusscheduleron_errorjob-error) (instead of #on_exception), by default it now prints the details of the error to $stderr (used to be $stdout)
95
95
  * Rufus::Scheduler::TimeOutError renamed to Rufus::Scheduler::TimeoutError
96
96
  * Introduction of "interval" jobs. Whereas "every" jobs are like "every 10 minutes, do this", interval jobs are like "do that, then wait for 10 minutes, then do that again, and so on"
97
97
  * Introduction of a :lockfile => true/filename mechanism to prevent multiple schedulers from executing
@@ -129,6 +129,7 @@ Yes, issues can be reported in [rufus-scheduler issues](https://github.com/jmett
129
129
  * [Passenger in-depth spawn methods (smart spawning)](https://www.phusionpassenger.com/library/indepth/ruby/spawn_methods/#smart-spawning-hooks)
130
130
  * [The scheduler comes up when running the Rails console or a Rake task](https://github.com/jmettraux/rufus-scheduler#avoid-scheduling-when-running-the-ruby-on-rails-console)
131
131
  * [I don't get any of this, I just want it to work in my Rails application](#so-rails)
132
+ * [I get "zotime.rb:41:in `initialize': cannot determine timezone from nil"](#i-get-zotimerb41in-initialize-cannot-determine-timezone-from-nil)
132
133
 
133
134
 
134
135
  ## scheduling
@@ -438,7 +439,7 @@ job.first_at = Time.now + 10
438
439
  job.first_at = Rufus::Scheduler.parse('2029-12-12')
439
440
  ```
440
441
 
441
- 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:
442
443
 
443
444
  ```ruby
444
445
  require 'rufus-scheduler'
@@ -781,7 +782,7 @@ job =
781
782
  job.call
782
783
  ```
783
784
 
784
- Warning: the Scheduler#on_error handler is not involved. Error handling is the responsibility of the caller.
785
+ Warning: the Scheduler[#on_error](#rufusscheduleron_errorjob-error) handler is not involved. Error handling is the responsibility of the caller.
785
786
 
786
787
  If the call has to be rescued by the error handler of the scheduler, ```call(true)``` might help:
787
788
 
@@ -846,7 +847,7 @@ Every jobs use a time duration between each start of their execution, while inte
846
847
 
847
848
  ### frequency
848
849
 
849
- 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.
850
851
 
851
852
  For instance:
852
853
  ```ruby
@@ -1063,6 +1064,20 @@ def scheduler.on_error(job, error)
1063
1064
  end
1064
1065
  ```
1065
1066
 
1067
+ On Rails, the `on_error` method redefinition might look like:
1068
+ ```ruby
1069
+ def scheduler.on_error(job, error)
1070
+
1071
+ Rails.logger.error(
1072
+ "err#{error.object_id} rufus-scheduler intercepted #{error.inspect}" +
1073
+ " in job #{job.inspect}")
1074
+ error.backtrace.each_with_index do |line, i|
1075
+ Rails.logger.error(
1076
+ "err#{error.object_id} #{i}: #{line}")
1077
+ end
1078
+ end
1079
+ ```
1080
+
1066
1081
  ## Rufus::Scheduler #on_pre_trigger and #on_post_trigger callbacks
1067
1082
 
1068
1083
  One can bind callbacks before and after jobs trigger:
@@ -1267,7 +1282,7 @@ end
1267
1282
 
1268
1283
  This uses a [zookeeper](http://zookeeper.apache.org/) to make sure only one scheduler in a group of distributed schedulers runs.
1269
1284
 
1270
- 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,
1271
1286
  to make sure that the lock is still valid.
1272
1287
 
1273
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.
@@ -1417,7 +1432,58 @@ end
1417
1432
  # or even
1418
1433
 
1419
1434
  Rufus::Scheduler.parse("2013-12-12 14:00 Pacific/Saipan")
1420
- # => 2013-12-12 04:00:00 UTC
1435
+ # => #<Rufus::Scheduler::ZoTime:0x007fb424abf4e8 @seconds=1386820800.0, @zone=#<TZInfo::DataTimezone: Pacific/Saipan>, @time=nil>
1436
+ ```
1437
+
1438
+ ### I get "zotime.rb:41:in `initialize': cannot determine timezone from nil"
1439
+
1440
+ For when you see an error like:
1441
+ ```
1442
+ rufus-scheduler/lib/rufus/scheduler/zotime.rb:41:
1443
+ in `initialize':
1444
+ cannot determine timezone from nil (etz:nil,tnz:"中国标准时间",tzid:nil)
1445
+ (ArgumentError)
1446
+ from rufus-scheduler/lib/rufus/scheduler/zotime.rb:198:in `new'
1447
+ from rufus-scheduler/lib/rufus/scheduler/zotime.rb:198:in `now'
1448
+ from rufus-scheduler/lib/rufus/scheduler.rb:561:in `start'
1449
+ ...
1450
+ ```
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 explicitly the `ENV['TZ']` before the scheduler instantiation:
1453
+ ```ruby
1454
+ ENV['TZ'] = 'Asia/Shanghai'
1455
+ scheduler = Rufus::Scheduler.new
1456
+ scheduler.every '2s' do
1457
+ puts "#{Time.now} Hello #{ENV['TZ']}!"
1458
+ end
1459
+ ```
1460
+
1461
+ On Rails you might want to try with:
1462
+ ```ruby
1463
+ ENV['TZ'] = Time.zone.name # Rails only
1464
+ scheduler = Rufus::Scheduler.new
1465
+ scheduler.every '2s' do
1466
+ puts "#{Time.now} Hello #{ENV['TZ']}!"
1467
+ end
1468
+ ```
1469
+ (Hat tip to Alexander in [gh-230](https://github.com/jmettraux/rufus-scheduler/issues/230))
1470
+
1471
+ Rails sets its timezone under `config/application.rb`.
1472
+
1473
+ Rufus-Scheduler 3.3.3 detects the presence of Rails and uses its timezone setting (tested with Rails 4), so setting `ENV['TZ']` should not be necessary.
1474
+
1475
+ The value can be determined thanks to [https://en.wikipedia.org/wiki/List_of_tz_database_time_zones](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones).
1476
+
1477
+ Use a "continent/city" identifier (for example "Asia/Shanghai"). Do not use an abbreviation (not "CST") and do not use a local time zone name (not "中国标准时间" nor "Eastern Standard Time" which, for instance, points to a time zone in America and to another one in Australia...).
1478
+
1479
+ If the error persists (and especially on Windows), try to add the `tzinfo-data` to your Gemfile, as in:
1480
+ ```ruby
1481
+ gem 'tzinfo-data'
1482
+ ```
1483
+ or by manually requiring it before requiring rufus-scheduler (if you don't use Bundler):
1484
+ ```ruby
1485
+ require 'tzinfo/data'
1486
+ require 'rufus-scheduler'
1421
1487
  ```
1422
1488
 
1423
1489
 
data/fail.txt ADDED
@@ -0,0 +1,2 @@
1
+ rspec ./spec/job_spec.rb:465 # Rufus::Scheduler::Job :mutex :mutex => [ array_of_mutex_names_or_instances ] prevents concurrent executions
2
+ rspec ./spec/scheduler_spec.rb:534 # Rufus::Scheduler#running_jobs(:tag/:tags => x) returns a list of running jobs filtered by tag
@@ -1,28 +1,3 @@
1
- #--
2
- # Copyright (c) 2006-2016, 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
@@ -33,6 +8,11 @@ class Rufus::Scheduler
33
8
  #
34
9
  class CronLine
35
10
 
11
+ # The max number of years in the future or the past before giving up
12
+ # searching for #next_time or #previous_time respectively
13
+ #
14
+ NEXT_TIME_MAX_YEARS = 14
15
+
36
16
  # The string used for creating this cronline instance.
37
17
  #
38
18
  attr_reader :original
@@ -58,10 +38,10 @@ class Rufus::Scheduler
58
38
 
59
39
  items = line.split
60
40
 
61
- if @timezone = ZoTime.get_tzone(items.last)
41
+ if @timezone = EoTime.get_tzone(items.last)
62
42
  @original_timezone = items.pop
63
43
  else
64
- @timezone = ZoTime.get_tzone(:current)
44
+ @timezone = EoTime.local_tzone
65
45
  end
66
46
 
67
47
  fail ArgumentError.new(
@@ -81,7 +61,7 @@ class Rufus::Scheduler
81
61
 
82
62
  fail ArgumentError.new(
83
63
  "invalid cronline: '#{line}'"
84
- ) if es && es.find { |e| ! e.is_a?(Fixnum) }
64
+ ) if es && es.find { |e| ! e.is_a?(Integer) }
85
65
  end
86
66
 
87
67
  if @days && @days.include?(0) # gh-221
@@ -94,10 +74,10 @@ class Rufus::Scheduler
94
74
  #
95
75
  def matches?(time)
96
76
 
97
- # 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
98
78
  # zone ...
99
79
  # Wait, this seems only used in specs...
100
- t = ZoTime.new(time.to_f, @timezone)
80
+ t = EoTime.new(time.to_f, @timezone)
101
81
 
102
82
  return false unless sub_match?(t, :sec, @seconds)
103
83
  return false unless sub_match?(t, :min, @minutes)
@@ -133,15 +113,21 @@ class Rufus::Scheduler
133
113
  #
134
114
  # (Thanks to K Liu for the note and the examples)
135
115
  #
136
- def next_time(from=ZoTime.now)
116
+ def next_time(from=EoTime.now)
137
117
 
138
118
  nt = nil
139
- zt = ZoTime.new(from.to_i + 1, @timezone)
119
+ zt = EoTime.new(from.to_i + 1, @timezone)
120
+ maxy = from.year + NEXT_TIME_MAX_YEARS
140
121
 
141
122
  loop do
142
123
 
143
124
  nt = zt.dup
144
125
 
126
+ fail RangeError.new(
127
+ "failed to reach occurrence within " +
128
+ "#{NEXT_TIME_MAX_YEARS} years for '#{original}'"
129
+ ) if nt.year > maxy
130
+
145
131
  unless date_match?(nt)
146
132
  zt.add((24 - nt.hour) * 3600 - nt.min * 60 - nt.sec)
147
133
  next
@@ -168,29 +154,35 @@ class Rufus::Scheduler
168
154
  # Returns the previous time the cronline matched. It's like next_time, but
169
155
  # for the past.
170
156
  #
171
- def previous_time(from=Time.now)
157
+ def previous_time(from=EoTime.now)
172
158
 
173
159
  pt = nil
174
- zt = ZoTime.new(from.to_i - 1, @timezone)
160
+ zt = EoTime.new(from.to_i - 1, @timezone)
161
+ miny = from.year - NEXT_TIME_MAX_YEARS
175
162
 
176
163
  loop do
177
164
 
178
165
  pt = zt.dup
179
166
 
167
+ fail RangeError.new(
168
+ "failed to reach occurrence within " +
169
+ "#{NEXT_TIME_MAX_YEARS} years for '#{original}'"
170
+ ) if pt.year < miny
171
+
180
172
  unless date_match?(pt)
181
- zt.substract(pt.hour * 3600 + pt.min * 60 + pt.sec + 1)
173
+ zt.subtract(pt.hour * 3600 + pt.min * 60 + pt.sec + 1)
182
174
  next
183
175
  end
184
176
  unless sub_match?(pt, :hour, @hours)
185
- zt.substract(pt.min * 60 + pt.sec + 1)
177
+ zt.subtract(pt.min * 60 + pt.sec + 1)
186
178
  next
187
179
  end
188
180
  unless sub_match?(pt, :min, @minutes)
189
- zt.substract(pt.sec + 1)
181
+ zt.subtract(pt.sec + 1)
190
182
  next
191
183
  end
192
184
  unless sub_match?(pt, :sec, @seconds)
193
- zt.substract(prev_second(pt))
185
+ zt.subtract(prev_second(pt))
194
186
  next
195
187
  end
196
188
 
@@ -242,7 +234,7 @@ class Rufus::Scheduler
242
234
  #
243
235
  @cache = {}; class << self; attr_reader :cache; end
244
236
 
245
- # Returns the shortest delta between two potential occurences of the
237
+ # Returns the shortest delta between two potential occurrences of the
246
238
  # schedule described by this cronline.
247
239
  #
248
240
  # .
@@ -279,8 +271,10 @@ class Rufus::Scheduler
279
271
  #p Time.now - st
280
272
  d = t1 - t0
281
273
  delta = d if d < delta
282
-
283
- break if @months == nil && t1.month == 2
274
+ break if @months.nil? && t1.month == 2
275
+ break if @months.nil? && @days.nil? && t1.day == 2
276
+ break if @months.nil? && @days.nil? && @hours.nil? && t1.hour == 1
277
+ break if @months.nil? && @days.nil? && @hours.nil? && @minutes.nil? && t1.min == 1
284
278
  break if t1.year >= 2001
285
279
 
286
280
  t0 = t1
@@ -488,9 +482,15 @@ class Rufus::Scheduler
488
482
 
489
483
  return false unless sub_match?(zt, :day, @days)
490
484
  return false unless sub_match?(zt, :month, @months)
485
+
486
+ return true if (
487
+ (@weekdays && @monthdays) &&
488
+ (sub_match?(zt, :wday, @weekdays) ||
489
+ sub_match?(zt, :monthdays, @monthdays)))
490
+
491
491
  return false unless sub_match?(zt, :wday, @weekdays)
492
- #return false unless monthday_match?(zt, @monthdays)
493
492
  return false unless sub_match?(zt, :monthdays, @monthdays)
493
+
494
494
  true
495
495
  end
496
496
  end
@@ -1,27 +1,3 @@
1
- #--
2
- # Copyright (c) 2006-2016, 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-2016, 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
 
@@ -373,7 +349,7 @@ module Rufus
373
349
  self.class.name.split(':').last.downcase[0..-4],
374
350
  @scheduled_at.to_f,
375
351
  @next_time.to_f,
376
- self.hash.abs
352
+ (self.object_id < 0 ? 'm' : '') + self.object_id.to_s
377
353
  ].map(&:to_s).join('_')
378
354
  end
379
355
 
@@ -426,7 +402,7 @@ module Rufus
426
402
 
427
403
  fail ArgumentError.new(
428
404
  "cannot accept :times => #{@times.inspect}, not nil or an int"
429
- ) unless @times == nil || @times.is_a?(Fixnum)
405
+ ) unless @times == nil || @times.is_a?(Integer)
430
406
 
431
407
  self.first_at =
432
408
  opts[:first] || opts[:first_time] ||
@@ -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
@@ -503,7 +485,7 @@ module Rufus
503
485
  [
504
486
  self.class.name.split(':').last.downcase[0..-4],
505
487
  @scheduled_at.to_f,
506
- self.hash.abs
488
+ (self.object_id < 0 ? 'm' : '') + self.object_id.to_s
507
489
  ].map(&:to_s).join('_')
508
490
  end
509
491
 
@@ -564,14 +546,13 @@ 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
- if @first_at == nil || @first_at < (n - @scheduler.frequency)
571
- nt = (@next_time || trigger_time || n) + @frequency
572
- nt > n ? nt : (trigger_time || n) + @frequency
573
- else
552
+ if @first_at && (trigger_time == nil || @first_at > n)
574
553
  @first_at
554
+ else
555
+ (@next_time || n) + @frequency
575
556
  end
576
557
  end
577
558
 
@@ -605,10 +586,10 @@ module Rufus
605
586
 
606
587
  @next_time =
607
588
  if is_post
608
- Rufus::Scheduler::ZoTime.now + @interval
589
+ EoTime.now + @interval
609
590
  elsif trigger_time.nil?
610
591
  if @first_at == nil || @first_at < Time.now
611
- Rufus::Scheduler::ZoTime.now + @interval
592
+ EoTime.now + @interval
612
593
  else
613
594
  @first_at
614
595
  end
@@ -1,26 +1,3 @@
1
- #--
2
- # Copyright (c) 2006-2016, 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
 
25
2
  require 'fileutils'
26
3