rufus-scheduler 3.4.2 → 3.7.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,13 +1,13 @@
1
1
 
2
- module Rufus
2
+ class Rufus::Scheduler
3
3
 
4
- class Scheduler
4
+ class << self
5
5
 
6
6
  #--
7
7
  # time and string methods
8
8
  #++
9
9
 
10
- def self.parse(o, opts={})
10
+ def parse(o, opts={})
11
11
 
12
12
  opts[:no_error] = true
13
13
 
@@ -17,17 +17,14 @@ module Rufus
17
17
  fail(ArgumentError.new("couldn't parse #{o.inspect} (#{o.class})"))
18
18
  end
19
19
 
20
- def self.parse_cron(o, opts)
20
+ def parse_cron(o, opts={})
21
21
 
22
- o.is_a?(CronLine) ? o : CronLine.new(o)
23
-
24
- rescue ArgumentError => ae
25
-
26
- return nil if opts[:no_error]
27
- fail ae
22
+ opts[:no_error] ?
23
+ Fugit.parse_cron(o) :
24
+ Fugit.do_parse_cron(o)
28
25
  end
29
26
 
30
- def self.parse_in(o, opts={})
27
+ def parse_in(o, opts={})
31
28
 
32
29
  #o.is_a?(String) ? parse_duration(o, opts) : o
33
30
 
@@ -42,7 +39,7 @@ module Rufus
42
39
  fail ae
43
40
  end
44
41
 
45
- def self.parse_at(o, opts={})
42
+ def parse_at(o, opts={})
46
43
 
47
44
  return o if o.is_a?(EoTime)
48
45
  return EoTime.make(o) if o.is_a?(Time)
@@ -54,23 +51,6 @@ module Rufus
54
51
  fail se
55
52
  end
56
53
 
57
- DURATIONS2M = [
58
- [ 'y', 365 * 24 * 3600 ],
59
- [ 'M', 30 * 24 * 3600 ],
60
- [ 'w', 7 * 24 * 3600 ],
61
- [ 'd', 24 * 3600 ],
62
- [ 'h', 3600 ],
63
- [ 'm', 60 ],
64
- [ 's', 1 ]
65
- ]
66
- DURATIONS2 = DURATIONS2M.dup
67
- DURATIONS2.delete_at(1)
68
-
69
- DURATIONS = DURATIONS2M.inject({}) { |r, (k, v)| r[k] = v; r }
70
- DURATION_LETTERS = DURATIONS.keys.join
71
-
72
- DU_KEYS = DURATIONS2M.collect { |k, v| k.to_sym }
73
-
74
54
  # Turns a string like '1m10s' into a float like '70.0', more formally,
75
55
  # turns a time duration expressed as a string into a Float instance
76
56
  # (millisecond count).
@@ -98,37 +78,17 @@ module Rufus
98
78
  # Rufus::Scheduler.parse_duration "-0.5" # => -0.5
99
79
  # Rufus::Scheduler.parse_duration "-1h" # => -3600.0
100
80
  #
101
- def self.parse_duration(string, opts={})
102
-
103
- s = string.to_s.strip
104
- mod = s[0, 1] == '-' ? -1 : 1
105
- s = s[1..-1] if mod == -1
106
-
107
- ss = mod < 0 ? '-' : ''
108
- r = 0.0
109
-
110
- s.scan(/(\d*\.\d+|\d+\.?)([#{DURATION_LETTERS}]?)/) do |f, d|
111
- ss += "#{f}#{d}"
112
- r += f.to_f * (DURATIONS[d] || 1.0)
113
- end
114
-
115
- if ss == '-' || ss != string.to_s.strip
116
- return nil if opts[:no_error]
117
- fail ArgumentError.new("invalid time duration #{string.inspect}")
118
- end
81
+ def parse_duration(str, opts={})
119
82
 
120
- mod * r
83
+ d =
84
+ opts[:no_error] ?
85
+ Fugit::Duration.parse(str, opts) :
86
+ Fugit::Duration.do_parse(str, opts)
87
+ d ?
88
+ d.to_sec :
89
+ nil
121
90
  end
122
91
 
123
- class << self
124
- #-
125
- # for compatibility with rufus-scheduler 2.x
126
- #+
127
- alias parse_duration_string parse_duration
128
- alias parse_time_string parse_duration
129
- end
130
-
131
-
132
92
  # Turns a number of seconds into a a time string
133
93
  #
134
94
  # Rufus.to_duration 0 # => '0s'
@@ -158,45 +118,27 @@ module Rufus
158
118
  #
159
119
  # * :months, if set to true, months (M) of 30 days will be taken into
160
120
  # account when building up the result
161
- # * :drop_seconds, if set to true, seconds and milliseconds will be trimmed
162
- # from the result
121
+ # * :drop_seconds, if set to true, seconds and milliseconds will be
122
+ # trimmed from the result
163
123
  #
164
- def self.to_duration(seconds, options={})
124
+ def to_duration(seconds, options={})
165
125
 
166
- h = to_duration_hash(seconds, options)
167
-
168
- return (options[:drop_seconds] ? '0m' : '0s') if h.empty?
169
-
170
- s =
171
- DU_KEYS.inject('') { |r, key|
172
- count = h[key]
173
- count = nil if count == 0
174
- r << "#{count}#{key}" if count
175
- r
176
- }
177
-
178
- ms = h[:ms]
179
- s << ms.to_s if ms
180
-
181
- s
182
- end
126
+ #d = Fugit::Duration.parse(seconds, options).deflate
127
+ #d = d.drop_seconds if options[:drop_seconds]
128
+ #d = d.deflate(:month => options[:months]) if options[:months]
129
+ #d.to_rufus_s
183
130
 
184
- class << self
185
- #-
186
- # for compatibility with rufus-scheduler 2.x
187
- #+
188
- alias to_duration_string to_duration
189
- alias to_time_string to_duration
131
+ to_fugit_duration(seconds, options).to_rufus_s
190
132
  end
191
133
 
192
134
  # Turns a number of seconds (integer or Float) into a hash like in :
193
135
  #
194
136
  # Rufus.to_duration_hash 0.051
195
- # # => { :ms => "51" }
137
+ # # => { :s => 0.051 }
196
138
  # Rufus.to_duration_hash 7.051
197
- # # => { :s => 7, :ms => "51" }
139
+ # # => { :s => 7.051 }
198
140
  # Rufus.to_duration_hash 0.120 + 30 * 24 * 3600 + 1
199
- # # => { :w => 4, :d => 2, :s => 1, :ms => "120" }
141
+ # # => { :w => 4, :d => 2, :s => 1.120 }
200
142
  #
201
143
  # This method is used by to_duration behind the scenes.
202
144
  #
@@ -204,62 +146,71 @@ module Rufus
204
146
  #
205
147
  # * :months, if set to true, months (M) of 30 days will be taken into
206
148
  # account when building up the result
207
- # * :drop_seconds, if set to true, seconds and milliseconds will be trimmed
208
- # from the result
149
+ # * :drop_seconds, if set to true, seconds and milliseconds will be
150
+ # trimmed from the result
209
151
  #
210
- def self.to_duration_hash(seconds, options={})
152
+ def to_duration_hash(seconds, options={})
211
153
 
212
- h = {}
213
-
214
- if seconds.is_a?(Float)
215
- h[:ms] = (seconds % 1 * 1000).to_i
216
- seconds = seconds.to_i
217
- end
218
-
219
- if options[:drop_seconds]
220
- h.delete(:ms)
221
- seconds = (seconds - seconds % 60)
222
- end
223
-
224
- durations = options[:months] ? DURATIONS2M : DURATIONS2
154
+ to_fugit_duration(seconds, options).to_rufus_h
155
+ end
225
156
 
226
- durations.each do |key, duration|
157
+ # Used by both .to_duration and .to_duration_hash
158
+ #
159
+ def to_fugit_duration(seconds, options={})
227
160
 
228
- count = seconds / duration
229
- seconds = seconds % duration
161
+ d = Fugit::Duration
162
+ .parse(seconds, options)
163
+ .deflate
230
164
 
231
- h[key.to_sym] = count if count > 0
232
- end
165
+ d = d.drop_seconds if options[:drop_seconds]
166
+ d = d.deflate(:month => options[:months]) if options[:months]
233
167
 
234
- h
168
+ d
235
169
  end
236
170
 
237
171
  #--
238
172
  # misc
239
173
  #++
240
174
 
241
- # Produces the UTC string representation of a Time instance
242
- #
243
- # like "2009/11/23 11:11:50.947109 UTC"
244
- #
245
- def self.utc_to_s(t=Time.now)
175
+ if RUBY_VERSION > '1.9.9'
246
176
 
247
- "#{t.utc.strftime('%Y-%m-%d %H:%M:%S')}.#{sprintf('%06d', t.usec)} UTC"
248
- end
177
+ # Produces the UTC string representation of a Time instance
178
+ #
179
+ # like "2009/11/23 11:11:50.947109 UTC"
180
+ #
181
+ def utc_to_s(t=Time.now)
182
+ "#{t.dup.utc.strftime('%F %T.%6N')} UTC"
183
+ end
249
184
 
250
- # Produces a hour/min/sec/milli string representation of Time instance
251
- #
252
- def self.h_to_s(t=Time.now)
185
+ # Produces a hour/min/sec/milli string representation of Time instance
186
+ #
187
+ def h_to_s(t=Time.now)
188
+ t.strftime('%T.%6N')
189
+ end
190
+ else
253
191
 
254
- "#{t.strftime('%H:%M:%S')}.#{sprintf('%06d', t.usec)}"
192
+ def utc_to_s(t=Time.now)
193
+ "#{t.utc.strftime('%Y-%m-%d %H:%M:%S')}.#{sprintf('%06d', t.usec)} UTC"
194
+ end
195
+ def h_to_s(t=Time.now)
196
+ "#{t.strftime('%H:%M:%S')}.#{sprintf('%06d', t.usec)}"
197
+ end
255
198
  end
256
199
 
257
- # Debugging tools...
258
- #
259
- class D
260
-
261
- def self.h_to_s(t=Time.now); Rufus::Scheduler.h_to_s(t); end
200
+ if defined?(Process::CLOCK_MONOTONIC)
201
+ def monow; Process.clock_gettime(Process::CLOCK_MONOTONIC); end
202
+ else
203
+ def monow; Time.now.to_f; end
262
204
  end
205
+
206
+ def ltstamp; Time.now.strftime('%FT%T.%3N'); end
207
+ end
208
+
209
+ # Debugging tools...
210
+ #
211
+ class D
212
+
213
+ def self.h_to_s(t=Time.now); Rufus::Scheduler.h_to_s(t); end
263
214
  end
264
215
  end
265
216
 
@@ -10,8 +10,7 @@ Gem::Specification.new do |s|
10
10
  s.platform = Gem::Platform::RUBY
11
11
  s.authors = [ 'John Mettraux' ]
12
12
  s.email = [ 'jmettraux@gmail.com' ]
13
- s.homepage = 'http://github.com/jmettraux/rufus-scheduler'
14
- s.rubyforge_project = 'rufus'
13
+ s.homepage = 'https://github.com/jmettraux/rufus-scheduler'
15
14
  s.license = 'MIT'
16
15
  s.summary = 'job scheduler for Ruby (at, cron, in and every jobs)'
17
16
 
@@ -19,19 +18,31 @@ Gem::Specification.new do |s|
19
18
  Job scheduler for Ruby (at, cron, in and every jobs). Not a replacement for crond.
20
19
  }.strip
21
20
 
21
+ s.metadata = {
22
+ 'changelog_uri' => s.homepage + '/blob/master/CHANGELOG.md',
23
+ 'bug_tracker_uri' => s.homepage + '/issues',
24
+ 'homepage_uri' => s.homepage,
25
+ 'source_code_uri' => s.homepage,
26
+ #'wiki_uri' => s.homepage + '/flor/wiki',
27
+ #'documentation_uri' => s.homepage + '/tree/master/doc',
28
+ #'mailing_list_uri' => 'https://groups.google.com/forum/#!forum/floraison',
29
+ }
30
+
22
31
  #s.files = `git ls-files`.split("\n")
23
32
  s.files = Dir[
33
+ 'README.{md,txt}',
34
+ 'CHANGELOG.{md,txt}', 'CREDITS.{md,txt}', 'LICENSE.{md,txt}',
24
35
  'Makefile',
25
36
  'lib/**/*.rb', #'spec/**/*.rb', 'test/**/*.rb',
26
- '*.gemspec', '*.txt', '*.rdoc', '*.md'
37
+ "#{s.name}.gemspec",
27
38
  ]
28
39
 
29
40
  s.required_ruby_version = '>= 1.9'
30
41
 
31
- s.add_runtime_dependency 'et-orbi', '~> 1.0'
42
+ s.add_runtime_dependency 'fugit', '~> 1.1', '>= 1.1.6'
32
43
 
33
- s.add_development_dependency 'rspec', '~> 3.4'
34
- s.add_development_dependency 'chronic'
44
+ s.add_development_dependency 'rspec', '~> 3.7'
45
+ s.add_development_dependency 'chronic', '~> 0.10'
35
46
 
36
47
  s.require_path = 'lib'
37
48
  end
metadata CHANGED
@@ -1,57 +1,63 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rufus-scheduler
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.4.2
4
+ version: 3.7.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: 2017-05-24 00:00:00.000000000 Z
11
+ date: 2020-12-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: et-orbi
14
+ name: fugit
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.0'
19
+ version: '1.1'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 1.1.6
20
23
  type: :runtime
21
24
  prerelease: false
22
25
  version_requirements: !ruby/object:Gem::Requirement
23
26
  requirements:
24
- - - ~>
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '1.1'
30
+ - - ">="
25
31
  - !ruby/object:Gem::Version
26
- version: '1.0'
32
+ version: 1.1.6
27
33
  - !ruby/object:Gem::Dependency
28
34
  name: rspec
29
35
  requirement: !ruby/object:Gem::Requirement
30
36
  requirements:
31
- - - ~>
37
+ - - "~>"
32
38
  - !ruby/object:Gem::Version
33
- version: '3.4'
39
+ version: '3.7'
34
40
  type: :development
35
41
  prerelease: false
36
42
  version_requirements: !ruby/object:Gem::Requirement
37
43
  requirements:
38
- - - ~>
44
+ - - "~>"
39
45
  - !ruby/object:Gem::Version
40
- version: '3.4'
46
+ version: '3.7'
41
47
  - !ruby/object:Gem::Dependency
42
48
  name: chronic
43
49
  requirement: !ruby/object:Gem::Requirement
44
50
  requirements:
45
- - - '>='
51
+ - - "~>"
46
52
  - !ruby/object:Gem::Version
47
- version: '0'
53
+ version: '0.10'
48
54
  type: :development
49
55
  prerelease: false
50
56
  version_requirements: !ruby/object:Gem::Requirement
51
57
  requirements:
52
- - - '>='
58
+ - - "~>"
53
59
  - !ruby/object:Gem::Version
54
- version: '0'
60
+ version: '0.10'
55
61
  description: Job scheduler for Ruby (at, cron, in and every jobs). Not a replacement
56
62
  for crond.
57
63
  email:
@@ -60,47 +66,44 @@ executables: []
60
66
  extensions: []
61
67
  extra_rdoc_files: []
62
68
  files:
69
+ - CHANGELOG.md
70
+ - CREDITS.md
71
+ - LICENSE.txt
63
72
  - Makefile
64
- - lib/rufus/scheduler/cronline.rb
73
+ - README.md
74
+ - lib/rufus-scheduler.rb
75
+ - lib/rufus/scheduler.rb
65
76
  - lib/rufus/scheduler/job_array.rb
66
- - lib/rufus/scheduler/jobs.rb
77
+ - lib/rufus/scheduler/jobs_core.rb
78
+ - lib/rufus/scheduler/jobs_one_time.rb
79
+ - lib/rufus/scheduler/jobs_repeat.rb
67
80
  - lib/rufus/scheduler/locks.rb
68
81
  - lib/rufus/scheduler/util.rb
69
- - lib/rufus/scheduler.rb
70
- - lib/rufus-scheduler.rb
71
82
  - rufus-scheduler.gemspec
72
- - CHANGELOG.txt
73
- - CREDITS.txt
74
- - fail.txt
75
- - fail18.txt
76
- - LICENSE.txt
77
- - log.txt
78
- - n.txt
79
- - pics.txt
80
- - TODO.txt
81
- - README.md
82
- - sofia.md
83
- homepage: http://github.com/jmettraux/rufus-scheduler
83
+ homepage: https://github.com/jmettraux/rufus-scheduler
84
84
  licenses:
85
85
  - MIT
86
- metadata: {}
86
+ metadata:
87
+ changelog_uri: https://github.com/jmettraux/rufus-scheduler/blob/master/CHANGELOG.md
88
+ bug_tracker_uri: https://github.com/jmettraux/rufus-scheduler/issues
89
+ homepage_uri: https://github.com/jmettraux/rufus-scheduler
90
+ source_code_uri: https://github.com/jmettraux/rufus-scheduler
87
91
  post_install_message:
88
92
  rdoc_options: []
89
93
  require_paths:
90
94
  - lib
91
95
  required_ruby_version: !ruby/object:Gem::Requirement
92
96
  requirements:
93
- - - '>='
97
+ - - ">="
94
98
  - !ruby/object:Gem::Version
95
99
  version: '1.9'
96
100
  required_rubygems_version: !ruby/object:Gem::Requirement
97
101
  requirements:
98
- - - '>='
102
+ - - ">="
99
103
  - !ruby/object:Gem::Version
100
104
  version: '0'
101
105
  requirements: []
102
- rubyforge_project: rufus
103
- rubygems_version: 2.0.14
106
+ rubygems_version: 3.0.3
104
107
  signing_key:
105
108
  specification_version: 4
106
109
  summary: job scheduler for Ruby (at, cron, in and every jobs)