rufus-scheduler 3.5.1 → 3.8.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,200 +1,216 @@
1
1
 
2
- module Rufus
2
+ class Rufus::Scheduler
3
3
 
4
- class Scheduler
4
+ class << self
5
5
 
6
- class << self
6
+ #--
7
+ # time and string methods
8
+ #++
7
9
 
8
- #--
9
- # time and string methods
10
- #++
10
+ def parse(o, opts={})
11
11
 
12
- def parse(o, opts={})
12
+ opts[:no_error] = true
13
13
 
14
- opts[:no_error] = true
14
+ parse_cron(o, opts) ||
15
+ parse_in(o, opts) || # covers 'every' schedule strings
16
+ parse_at(o, opts) ||
17
+ fail(ArgumentError.new("couldn't parse #{o.inspect} (#{o.class})"))
18
+ end
15
19
 
16
- parse_cron(o, opts) ||
17
- parse_in(o, opts) || # covers 'every' schedule strings
18
- parse_at(o, opts) ||
19
- fail(ArgumentError.new("couldn't parse #{o.inspect} (#{o.class})"))
20
- end
20
+ def parse_cron(o, opts={})
21
21
 
22
- def parse_cron(o, opts)
22
+ opts[:no_error] ?
23
+ Fugit.parse_cron(o) :
24
+ Fugit.do_parse_cron(o)
25
+ end
23
26
 
24
- Fugit.parse_cron(o)
25
- end
27
+ def parse_in(o, opts={})
26
28
 
27
- def parse_in(o, opts={})
29
+ #o.is_a?(String) ? parse_duration(o, opts) : o
28
30
 
29
- #o.is_a?(String) ? parse_duration(o, opts) : o
31
+ return parse_duration(o, opts) if o.is_a?(String)
32
+ return o if o.is_a?(Numeric)
30
33
 
31
- return parse_duration(o, opts) if o.is_a?(String)
32
- return o if o.is_a?(Numeric)
34
+ fail ArgumentError.new("couldn't parse time point in #{o.inspect}")
33
35
 
34
- fail ArgumentError.new("couldn't parse time point in #{o.inspect}")
36
+ rescue ArgumentError => ae
35
37
 
36
- rescue ArgumentError => ae
38
+ return nil if opts[:no_error]
39
+ fail ae
40
+ end
37
41
 
38
- return nil if opts[:no_error]
39
- fail ae
40
- end
42
+ def parse_at(o, opts={})
41
43
 
42
- def parse_at(o, opts={})
44
+ return o if o.is_a?(EoTime)
45
+ return EoTime.make(o) if o.is_a?(Time)
46
+ EoTime.parse(o, opts)
43
47
 
44
- return o if o.is_a?(EoTime)
45
- return EoTime.make(o) if o.is_a?(Time)
46
- EoTime.parse(o, opts)
48
+ rescue StandardError => se
47
49
 
48
- rescue StandardError => se
50
+ return nil if opts[:no_error]
51
+ fail se
52
+ end
49
53
 
50
- return nil if opts[:no_error]
51
- fail se
52
- end
54
+ # Turns a string like '1m10s' into a float like '70.0', more formally,
55
+ # turns a time duration expressed as a string into a Float instance
56
+ # (millisecond count).
57
+ #
58
+ # w -> week
59
+ # d -> day
60
+ # h -> hour
61
+ # m -> minute
62
+ # s -> second
63
+ # M -> month
64
+ # y -> year
65
+ # 'nada' -> millisecond
66
+ #
67
+ # Some examples:
68
+ #
69
+ # Rufus::Scheduler.parse_duration "0.5" # => 0.5
70
+ # Rufus::Scheduler.parse_duration "500" # => 0.5
71
+ # Rufus::Scheduler.parse_duration "1000" # => 1.0
72
+ # Rufus::Scheduler.parse_duration "1h" # => 3600.0
73
+ # Rufus::Scheduler.parse_duration "1h10s" # => 3610.0
74
+ # Rufus::Scheduler.parse_duration "1w2d" # => 777600.0
75
+ #
76
+ # Negative time strings are OK (Thanks Danny Fullerton):
77
+ #
78
+ # Rufus::Scheduler.parse_duration "-0.5" # => -0.5
79
+ # Rufus::Scheduler.parse_duration "-1h" # => -3600.0
80
+ #
81
+ def parse_duration(str, opts={})
82
+
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
90
+ end
53
91
 
54
- # Turns a string like '1m10s' into a float like '70.0', more formally,
55
- # turns a time duration expressed as a string into a Float instance
56
- # (millisecond count).
57
- #
58
- # w -> week
59
- # d -> day
60
- # h -> hour
61
- # m -> minute
62
- # s -> second
63
- # M -> month
64
- # y -> year
65
- # 'nada' -> millisecond
66
- #
67
- # Some examples:
68
- #
69
- # Rufus::Scheduler.parse_duration "0.5" # => 0.5
70
- # Rufus::Scheduler.parse_duration "500" # => 0.5
71
- # Rufus::Scheduler.parse_duration "1000" # => 1.0
72
- # Rufus::Scheduler.parse_duration "1h" # => 3600.0
73
- # Rufus::Scheduler.parse_duration "1h10s" # => 3610.0
74
- # Rufus::Scheduler.parse_duration "1w2d" # => 777600.0
75
- #
76
- # Negative time strings are OK (Thanks Danny Fullerton):
77
- #
78
- # Rufus::Scheduler.parse_duration "-0.5" # => -0.5
79
- # Rufus::Scheduler.parse_duration "-1h" # => -3600.0
80
- #
81
- def parse_duration(str, opts={})
82
-
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
90
- end
92
+ # Turns a number of seconds into a a time string
93
+ #
94
+ # Rufus.to_duration 0 # => '0s'
95
+ # Rufus.to_duration 60 # => '1m'
96
+ # Rufus.to_duration 3661 # => '1h1m1s'
97
+ # Rufus.to_duration 7 * 24 * 3600 # => '1w'
98
+ # Rufus.to_duration 30 * 24 * 3600 + 1 # => "4w2d1s"
99
+ #
100
+ # It goes from seconds to the year. Months are not counted (as they
101
+ # are of variable length). Weeks are counted.
102
+ #
103
+ # For 30 days months to be counted, the second parameter of this
104
+ # method can be set to true.
105
+ #
106
+ # Rufus.to_duration 30 * 24 * 3600 + 1, true # => "1M1s"
107
+ #
108
+ # If a Float value is passed, milliseconds will be displayed without
109
+ # 'marker'
110
+ #
111
+ # Rufus.to_duration 0.051 # => "51"
112
+ # Rufus.to_duration 7.051 # => "7s51"
113
+ # Rufus.to_duration 0.120 + 30 * 24 * 3600 + 1 # => "4w2d1s120"
114
+ #
115
+ # (this behaviour mirrors the one found for parse_time_string()).
116
+ #
117
+ # Options are :
118
+ #
119
+ # * :months, if set to true, months (M) of 30 days will be taken into
120
+ # account when building up the result
121
+ # * :drop_seconds, if set to true, seconds and milliseconds will be
122
+ # trimmed from the result
123
+ #
124
+ def to_duration(seconds, options={})
91
125
 
92
- # Turns a number of seconds into a a time string
93
- #
94
- # Rufus.to_duration 0 # => '0s'
95
- # Rufus.to_duration 60 # => '1m'
96
- # Rufus.to_duration 3661 # => '1h1m1s'
97
- # Rufus.to_duration 7 * 24 * 3600 # => '1w'
98
- # Rufus.to_duration 30 * 24 * 3600 + 1 # => "4w2d1s"
99
- #
100
- # It goes from seconds to the year. Months are not counted (as they
101
- # are of variable length). Weeks are counted.
102
- #
103
- # For 30 days months to be counted, the second parameter of this
104
- # method can be set to true.
105
- #
106
- # Rufus.to_duration 30 * 24 * 3600 + 1, true # => "1M1s"
107
- #
108
- # If a Float value is passed, milliseconds will be displayed without
109
- # 'marker'
110
- #
111
- # Rufus.to_duration 0.051 # => "51"
112
- # Rufus.to_duration 7.051 # => "7s51"
113
- # Rufus.to_duration 0.120 + 30 * 24 * 3600 + 1 # => "4w2d1s120"
114
- #
115
- # (this behaviour mirrors the one found for parse_time_string()).
116
- #
117
- # Options are :
118
- #
119
- # * :months, if set to true, months (M) of 30 days will be taken into
120
- # account when building up the result
121
- # * :drop_seconds, if set to true, seconds and milliseconds will be
122
- # trimmed from the result
123
- #
124
- def to_duration(seconds, options={})
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
125
130
 
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
131
+ to_fugit_duration(seconds, options).to_rufus_s
132
+ end
130
133
 
131
- to_fugit_duration(seconds, options).to_rufus_s
132
- end
134
+ # Turns a number of seconds (integer or Float) into a hash like in :
135
+ #
136
+ # Rufus.to_duration_hash 0.051
137
+ # # => { :s => 0.051 }
138
+ # Rufus.to_duration_hash 7.051
139
+ # # => { :s => 7.051 }
140
+ # Rufus.to_duration_hash 0.120 + 30 * 24 * 3600 + 1
141
+ # # => { :w => 4, :d => 2, :s => 1.120 }
142
+ #
143
+ # This method is used by to_duration behind the scenes.
144
+ #
145
+ # Options are :
146
+ #
147
+ # * :months, if set to true, months (M) of 30 days will be taken into
148
+ # account when building up the result
149
+ # * :drop_seconds, if set to true, seconds and milliseconds will be
150
+ # trimmed from the result
151
+ #
152
+ def to_duration_hash(seconds, options={})
133
153
 
134
- # Turns a number of seconds (integer or Float) into a hash like in :
135
- #
136
- # Rufus.to_duration_hash 0.051
137
- # # => { :s => 0.051 }
138
- # Rufus.to_duration_hash 7.051
139
- # # => { :s => 7.051 }
140
- # Rufus.to_duration_hash 0.120 + 30 * 24 * 3600 + 1
141
- # # => { :w => 4, :d => 2, :s => 1.120 }
142
- #
143
- # This method is used by to_duration behind the scenes.
144
- #
145
- # Options are :
146
- #
147
- # * :months, if set to true, months (M) of 30 days will be taken into
148
- # account when building up the result
149
- # * :drop_seconds, if set to true, seconds and milliseconds will be
150
- # trimmed from the result
151
- #
152
- def to_duration_hash(seconds, options={})
154
+ to_fugit_duration(seconds, options).to_rufus_h
155
+ end
153
156
 
154
- to_fugit_duration(seconds, options).to_rufus_h
155
- end
157
+ # Used by both .to_duration and .to_duration_hash
158
+ #
159
+ def to_fugit_duration(seconds, options={})
156
160
 
157
- # Used by both .to_duration and .to_duration_hash
158
- #
159
- def to_fugit_duration(seconds, options={})
161
+ d = Fugit::Duration
162
+ .parse(seconds, options)
163
+ .deflate
160
164
 
161
- d = Fugit::Duration
162
- .parse(seconds, options)
163
- .deflate
165
+ d = d.drop_seconds if options[:drop_seconds]
166
+ d = d.deflate(:month => options[:months]) if options[:months]
164
167
 
165
- d = d.drop_seconds if options[:drop_seconds]
166
- d = d.deflate(:month => options[:months]) if options[:months]
168
+ d
169
+ end
167
170
 
168
- d
169
- end
171
+ #--
172
+ # misc
173
+ #++
170
174
 
171
- #--
172
- # misc
173
- #++
175
+ if RUBY_VERSION > '1.9.9'
174
176
 
175
177
  # Produces the UTC string representation of a Time instance
176
178
  #
177
179
  # like "2009/11/23 11:11:50.947109 UTC"
178
180
  #
179
181
  def utc_to_s(t=Time.now)
180
-
181
- "#{t.utc.strftime('%Y-%m-%d %H:%M:%S')}.#{sprintf('%06d', t.usec)} UTC"
182
+ "#{t.dup.utc.strftime('%F %T.%6N')} UTC"
182
183
  end
183
184
 
184
185
  # Produces a hour/min/sec/milli string representation of Time instance
185
186
  #
186
187
  def h_to_s(t=Time.now)
188
+ t.strftime('%T.%6N')
189
+ end
190
+ else
187
191
 
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)
188
196
  "#{t.strftime('%H:%M:%S')}.#{sprintf('%06d', t.usec)}"
189
197
  end
190
198
  end
191
199
 
192
- # Debugging tools...
193
- #
194
- class D
195
-
196
- 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
197
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
198
214
  end
199
215
  end
200
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,6 +18,16 @@ 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[
24
33
  'README.{md,txt}',
@@ -30,7 +39,7 @@ Job scheduler for Ruby (at, cron, in and every jobs). Not a replacement for cron
30
39
 
31
40
  s.required_ruby_version = '>= 1.9'
32
41
 
33
- s.add_runtime_dependency 'fugit', '~> 1.1', '>= 1.1.4'
42
+ s.add_runtime_dependency 'fugit', '~> 1.1', '>= 1.1.6'
34
43
 
35
44
  s.add_development_dependency 'rspec', '~> 3.7'
36
45
  s.add_development_dependency 'chronic', '~> 0.10'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rufus-scheduler
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.5.1
4
+ version: 3.8.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: 2018-07-20 00:00:00.000000000 Z
11
+ date: 2021-07-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fugit
@@ -19,7 +19,7 @@ dependencies:
19
19
  version: '1.1'
20
20
  - - ">="
21
21
  - !ruby/object:Gem::Version
22
- version: 1.1.4
22
+ version: 1.1.6
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
@@ -29,7 +29,7 @@ dependencies:
29
29
  version: '1.1'
30
30
  - - ">="
31
31
  - !ruby/object:Gem::Version
32
- version: 1.1.4
32
+ version: 1.1.6
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: rspec
35
35
  requirement: !ruby/object:Gem::Requirement
@@ -74,14 +74,20 @@ files:
74
74
  - lib/rufus-scheduler.rb
75
75
  - lib/rufus/scheduler.rb
76
76
  - lib/rufus/scheduler/job_array.rb
77
- - 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
78
80
  - lib/rufus/scheduler/locks.rb
79
81
  - lib/rufus/scheduler/util.rb
80
82
  - rufus-scheduler.gemspec
81
- homepage: http://github.com/jmettraux/rufus-scheduler
83
+ homepage: https://github.com/jmettraux/rufus-scheduler
82
84
  licenses:
83
85
  - MIT
84
- 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
85
91
  post_install_message:
86
92
  rdoc_options: []
87
93
  require_paths:
@@ -97,8 +103,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
97
103
  - !ruby/object:Gem::Version
98
104
  version: '0'
99
105
  requirements: []
100
- rubyforge_project: rufus
101
- rubygems_version: 2.5.2.3
106
+ rubygems_version: 3.0.3
102
107
  signing_key:
103
108
  specification_version: 4
104
109
  summary: job scheduler for Ruby (at, cron, in and every jobs)