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.
metadata CHANGED
@@ -1,43 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rufus-scheduler
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.3.0
4
+ version: 3.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Mettraux
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-11-28 00:00:00.000000000 Z
11
+ date: 2017-03-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: tzinfo
14
+ name: et-orbi
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
19
+ version: '1.0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ">="
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '0'
26
+ version: '1.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rspec
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 2.13.0
33
+ version: 3.4.0
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ">="
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 2.13.0
40
+ version: 3.4.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: chronic
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -52,7 +52,8 @@ dependencies:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
- description: job scheduler for Ruby (at, cron, in and every jobs).
55
+ description: Job scheduler for Ruby (at, cron, in and every jobs). Not a replacement
56
+ for crond.
56
57
  email:
57
58
  - jmettraux@gmail.com
58
59
  executables: []
@@ -65,6 +66,7 @@ files:
65
66
  - Makefile
66
67
  - README.md
67
68
  - TODO.txt
69
+ - fail.txt
68
70
  - fail18.txt
69
71
  - lib/rufus-scheduler.rb
70
72
  - lib/rufus/scheduler.rb
@@ -73,9 +75,11 @@ files:
73
75
  - lib/rufus/scheduler/jobs.rb
74
76
  - lib/rufus/scheduler/locks.rb
75
77
  - lib/rufus/scheduler/util.rb
76
- - lib/rufus/scheduler/zotime.rb
78
+ - log.txt
79
+ - n.txt
77
80
  - pics.txt
78
81
  - rufus-scheduler.gemspec
82
+ - sofia.md
79
83
  homepage: http://github.com/jmettraux/rufus-scheduler
80
84
  licenses:
81
85
  - MIT
@@ -88,7 +92,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
88
92
  requirements:
89
93
  - - ">="
90
94
  - !ruby/object:Gem::Version
91
- version: '0'
95
+ version: '1.9'
92
96
  required_rubygems_version: !ruby/object:Gem::Requirement
93
97
  requirements:
94
98
  - - ">="
@@ -96,7 +100,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
96
100
  version: '0'
97
101
  requirements: []
98
102
  rubyforge_project: rufus
99
- rubygems_version: 2.4.5.1
103
+ rubygems_version: 2.4.5.2
100
104
  signing_key:
101
105
  specification_version: 4
102
106
  summary: job scheduler for Ruby (at, cron, in and every jobs)
@@ -1,449 +0,0 @@
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
-
26
- class Rufus::Scheduler
27
-
28
- #
29
- # Zon{ing|ed}Time, whatever.
30
- #
31
- class ZoTime
32
-
33
- attr_reader :seconds
34
- attr_reader :zone
35
-
36
- def initialize(s, zone)
37
-
38
- @seconds = s.to_f
39
- @zone = self.class.get_tzone(zone || :current)
40
-
41
- fail ArgumentError.new(
42
- "cannot determine timezone from #{zone.inspect}"
43
- ) unless @zone
44
-
45
- @time = nil # cache for #to_time result
46
- end
47
-
48
- def seconds=(f)
49
-
50
- @time = nil
51
- @seconds = f
52
- end
53
-
54
- def zone=(z)
55
-
56
- @time = nil
57
- @zone = self.class.get_tzone(zone || :current)
58
- end
59
-
60
- def utc
61
-
62
- Time.utc(1970, 1, 1) + @seconds
63
- end
64
-
65
- # Returns a Ruby Time instance.
66
- #
67
- # Warning: the timezone of that Time instance will be UTC.
68
- #
69
- def to_time
70
-
71
- @time ||= begin; u = utc; @zone.period_for_utc(u).to_local(u); end
72
- end
73
-
74
- %w[
75
- year month day wday hour min sec usec asctime
76
- ].each do |m|
77
- define_method(m) { to_time.send(m) }
78
- end
79
- def iso8601(fraction_digits=0); to_time.iso8601(fraction_digits); end
80
-
81
- def ==(o)
82
-
83
- o.is_a?(ZoTime) && o.seconds == @seconds && o.zone == @zone
84
- end
85
- #alias eq? == # FIXME see Object#== (ri)
86
-
87
- def >(o); @seconds > _to_f(o); end
88
- def >=(o); @seconds >= _to_f(o); end
89
- def <(o); @seconds < _to_f(o); end
90
- def <=(o); @seconds <= _to_f(o); end
91
- def <=>(o); @seconds <=> _to_f(o); end
92
-
93
- alias getutc utc
94
- alias getgm utc
95
-
96
- def to_i
97
-
98
- @seconds.to_i
99
- end
100
-
101
- def to_f
102
-
103
- @seconds
104
- end
105
-
106
- def is_dst?
107
-
108
- @zone.period_for_utc(utc).std_offset != 0
109
- end
110
- alias isdst is_dst?
111
-
112
- def utc_offset
113
-
114
- #@zone.period_for_utc(utc).utc_offset
115
- #@zone.period_for_utc(utc).utc_total_offset
116
- #@zone.period_for_utc(utc).std_offset
117
- @zone.period_for_utc(utc).utc_offset
118
- end
119
-
120
- def strftime(format)
121
-
122
- format = format.gsub(/%(\/?Z|:{0,2}z)/) { |f| strfz(f) }
123
-
124
- to_time.strftime(format)
125
- end
126
-
127
- def add(t); @time = nil; @seconds += t.to_f; end
128
- def substract(t); @time = nil; @seconds -= t.to_f; end
129
-
130
- def +(t); inc(t, 1); end
131
- def -(t); inc(t, -1); end
132
-
133
- WEEK_S = 7 * 24 * 3600
134
-
135
- def monthdays
136
-
137
- date = to_time
138
-
139
- pos = 1
140
- d = self.dup
141
-
142
- loop do
143
- d.add(-WEEK_S)
144
- break if d.month != date.month
145
- pos = pos + 1
146
- end
147
-
148
- neg = -1
149
- d = self.dup
150
-
151
- loop do
152
- d.add(WEEK_S)
153
- break if d.month != date.month
154
- neg = neg - 1
155
- end
156
-
157
- [ "#{date.wday}##{pos}", "#{date.wday}##{neg}" ]
158
- end
159
-
160
- def to_s
161
-
162
- strftime('%Y-%m-%d %H:%M:%S %z')
163
- end
164
-
165
- def to_debug_s
166
-
167
- uo = self.utc_offset
168
- uos = uo < 0 ? '-' : '+'
169
- uo = uo.abs
170
- uoh, uom = [ uo / 3600, uo % 3600 ]
171
-
172
- [
173
- 'zt',
174
- self.strftime('%Y-%m-%d %H:%M:%S'),
175
- "%s%02d:%02d" % [ uos, uoh, uom ],
176
- "dst:#{self.isdst}"
177
- ].join(' ')
178
- end
179
-
180
- # Debug current time by showing local time / delta / utc time
181
- # for example: "0120-7(0820)"
182
- #
183
- def to_utc_comparison_s
184
-
185
- per = @zone.period_for_utc(utc)
186
- off = per.utc_total_offset
187
-
188
- off = off / 3600
189
- off = off >= 0 ? "+#{off}" : off.to_s
190
-
191
- strftime('%H%M') + off + utc.strftime('(%H%M)')
192
- end
193
-
194
- def self.now(zone=nil)
195
-
196
- ZoTime.new(Time.now.to_f, zone)
197
- end
198
-
199
- # https://en.wikipedia.org/wiki/ISO_8601
200
- # Postel's law applies
201
- #
202
- def self.extract_iso8601_zone(s)
203
-
204
- m = s.match(
205
- /[0-2]\d(?::?[0-6]\d(?::?[0-6]\d))?\s*([+-]\d\d(?::?\d\d)?)\s*\z/)
206
- return nil unless m
207
-
208
- zs = m[1].split(':')
209
- zs << '00' if zs.length < 2
210
-
211
- zh = zs[0].to_i.abs
212
-
213
- return nil if zh > 24
214
- return nil if zh == 24 && zs[1].to_i != 0
215
-
216
- zs.join(':')
217
- end
218
-
219
- def self.parse(str, opts={})
220
-
221
- if defined?(::Chronic) && t = ::Chronic.parse(str, opts)
222
- return ZoTime.new(t, nil)
223
- end
224
-
225
- #rold = RUBY_VERSION < '1.9.0'
226
- #rold = RUBY_VERSION < '2.0.0'
227
-
228
- begin
229
- DateTime.parse(str)
230
- rescue
231
- fail ArgumentError, "no time information in #{str.inspect}"
232
- end #if rold
233
- #
234
- # is necessary since Time.parse('xxx') in Ruby < 1.9 yields `now`
235
-
236
- zone = nil
237
-
238
- s =
239
- str.gsub(/\S+/) do |w|
240
- if z = get_tzone(w)
241
- zone ||= z
242
- ''
243
- else
244
- w
245
- end
246
- end
247
-
248
- local = Time.parse(s)
249
- izone = extract_iso8601_zone(s)
250
-
251
- zone ||=
252
- if s.match(/\dZ\b/)
253
- get_tzone('Zulu')
254
- #elsif rold && izone
255
- elsif izone
256
- get_tzone(izone)
257
- elsif local.zone.nil? && izone
258
- get_tzone(local.strftime('%:z'))
259
- else
260
- get_tzone(:local)
261
- end
262
-
263
- secs =
264
- #if rold && izone
265
- if izone
266
- local.to_f
267
- else
268
- zone.period_for_local(local).to_utc(local).to_f
269
- end
270
-
271
- ZoTime.new(secs, zone)
272
- end
273
-
274
- def self.get_tzone(str)
275
-
276
- return str if str.is_a?(::TZInfo::Timezone)
277
-
278
- # discard quickly when it's certainly not a timezone
279
-
280
- return nil if str == nil
281
- return nil if str == '*'
282
-
283
- # ok, it's a timezone then
284
-
285
- str = Time.now.zone if str == :current || str == :local
286
-
287
- # utc_offset
288
-
289
- if str.is_a?(Numeric)
290
- i = str.to_i
291
- sn = i < 0 ? '-' : '+'; i = i.abs
292
- hr = i / 3600; mn = i % 3600; sc = i % 60
293
- str = (sc > 0 ? "%s%02d:%02d:%02d" : "%s%02d:%02d") % [ sn, hr, mn, sc ]
294
- end
295
-
296
- return nil if str.index('#')
297
- # counters "sun#2", etc... On OSX would go all the way to true
298
-
299
- # vanilla time zones
300
-
301
- z = (::TZInfo::Timezone.get(str) rescue nil)
302
- return z if z
303
-
304
- # time zone abbreviations
305
-
306
- if str.match(/\A[A-Z0-9-]{3,6}\z/)
307
-
308
- twin = Time.utc(Time.now.year, 1, 1)
309
- tsum = Time.utc(Time.now.year, 7, 1)
310
-
311
- z =
312
- ::TZInfo::Timezone.all.find do |tz|
313
- tz.period_for_utc(twin).abbreviation.to_s == str ||
314
- tz.period_for_utc(tsum).abbreviation.to_s == str
315
- end
316
- return z if z
317
- end
318
-
319
- # some time zone aliases
320
-
321
- return ::TZInfo::Timezone.get('Zulu') if %w[ Z ].include?(str)
322
-
323
- # custom timezones, no DST, just an offset, like "+08:00" or "-01:30"
324
-
325
- tz = (@custom_tz_cache ||= {})[str]
326
- return tz if tz
327
-
328
- if m = str.match(/\A([+-][0-1][0-9]):?([0-5][0-9])\z/)
329
-
330
- hr = m[1].to_i
331
- mn = m[2].to_i
332
-
333
- hr = nil if hr.abs > 11
334
- hr = nil if mn > 59
335
- mn = -mn if hr && hr < 0
336
-
337
- return (
338
- @custom_tz_cache[str] =
339
- begin
340
- tzi = TZInfo::TransitionDataTimezoneInfo.new(str)
341
- tzi.offset(str, hr * 3600 + mn * 60, 0, str)
342
- tzi.create_timezone
343
- end
344
- ) if hr
345
- end
346
-
347
- # so it's not a timezone.
348
-
349
- nil
350
- end
351
-
352
- def self.local_tzone
353
-
354
- get_tzone(:local)
355
- end
356
-
357
- def self.make(o)
358
-
359
- zt =
360
- case o
361
- when Time
362
- ZoTime.new(o.to_f, o.zone)
363
- when Date
364
- t =
365
- o.respond_to?(:to_time) ?
366
- o.to_time :
367
- Time.parse(o.strftime('%Y-%m-%d %H:%M:%S'))
368
- ZoTime.new(t.to_f, t.zone)
369
- when String
370
- Rufus::Scheduler.parse_in(o, :no_error => true) || self.parse(o)
371
- else
372
- o
373
- end
374
-
375
- zt = ZoTime.new(Time.now.to_f + zt, nil) if zt.is_a?(Numeric)
376
-
377
- fail ArgumentError.new(
378
- "cannot turn #{o.inspect} to a ZoTime instance"
379
- ) unless zt.is_a?(ZoTime)
380
-
381
- zt
382
- end
383
-
384
- # def in_zone(&block)
385
- #
386
- # current_timezone = ENV['TZ']
387
- # ENV['TZ'] = @zone
388
- #
389
- # block.call
390
- #
391
- # ensure
392
- #
393
- # ENV['TZ'] = current_timezone
394
- # end
395
-
396
- protected
397
-
398
- def inc(t, dir)
399
-
400
- if t.is_a?(Numeric)
401
- nt = self.dup
402
- nt.seconds += dir * t.to_f
403
- nt
404
- elsif t.respond_to?(:to_f)
405
- @seconds + dir * t.to_f
406
- else
407
- fail ArgumentError.new(
408
- "cannot call ZoTime #- or #+ with arg of class #{t.class}")
409
- end
410
- end
411
-
412
- def _to_f(o)
413
-
414
- fail ArgumentError(
415
- "comparison of ZoTime with #{o.inspect} failed"
416
- ) unless o.is_a?(ZoTime) || o.is_a?(Time)
417
-
418
- o.to_f
419
- end
420
-
421
- def strfz(code)
422
-
423
- return @zone.name if code == '%/Z'
424
-
425
- per = @zone.period_for_utc(utc)
426
-
427
- return per.abbreviation.to_s if code == '%Z'
428
-
429
- off = per.utc_total_offset
430
- #
431
- sn = off < 0 ? '-' : '+'; off = off.abs
432
- hr = off / 3600
433
- mn = (off % 3600) / 60
434
- sc = 0
435
-
436
- fmt =
437
- if code == '%z'
438
- "%s%02d%02d"
439
- elsif code == '%:z'
440
- "%s%02d:%02d"
441
- else
442
- "%s%02d:%02d:%02d"
443
- end
444
-
445
- fmt % [ sn, hr, mn, sc ]
446
- end
447
- end
448
- end
449
-