cronos 0.3.1 → 0.4.2
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 +7 -0
- data/CHANGELOG +4 -0
- data/README.rdoc +17 -9
- data/TODO +4 -0
- data/lib/cronos/version.rb +3 -0
- data/lib/cronos.rb +85 -21
- data/spec/cronos_spec.rb +103 -67
- data/spec/spec_helper.rb +1 -2
- metadata +44 -40
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 7b7d4c5d68b641d07b172cafc2f63c7a789bb1e54e53dd19c5ac577a2bd1a9f9
|
4
|
+
data.tar.gz: d2f3391d9133ea6cbde4c4a0e61ceae775ebf69dbd7fe28997c83a0c2888177b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 76f985fe6e9b0431e54e5437f6ea8fe14971dad147aec7fd0bec11bda12d4fdd7282a90b54c567aa62ee0fce098c93765a1299cd208dd6cf2f326bc28ff8353d
|
7
|
+
data.tar.gz: e4db5b26f822054a3e71e125f290f60957de866f582ac36db3357d9b1f75145d7df897aff3e3e447dee001c0d157f71fc66f70630b4c5086f06e0e0c65f7cd86
|
data/CHANGELOG
CHANGED
data/README.rdoc
CHANGED
@@ -10,33 +10,41 @@ you are after instead of trying to remember the cron syntax and conventions.
|
|
10
10
|
|
11
11
|
cron = Cronos::Interval
|
12
12
|
|
13
|
-
cron.new.hourly
|
13
|
+
puts cron.new.hourly
|
14
14
|
# => '0 * * * *'
|
15
15
|
|
16
|
-
cron.new.daily
|
16
|
+
puts cron.new.daily
|
17
17
|
# => '0 0 * * *'
|
18
18
|
|
19
|
-
cron.new.weekly
|
19
|
+
puts cron.new.weekly
|
20
20
|
# => '0 0 * * 0'
|
21
21
|
|
22
|
-
cron.new.weekdays.at(12.30)
|
22
|
+
puts cron.new.weekdays.at(12.30)
|
23
23
|
# => '30 12 * * 1-5'
|
24
24
|
|
25
|
-
cron.new.weekends.at(12.30)
|
25
|
+
puts cron.new.weekends.at(12.30)
|
26
26
|
# => '30 12 * * 0,6'
|
27
27
|
|
28
|
-
cron.new.at('1.30pm').daily
|
28
|
+
puts cron.new.at('1.30pm').daily
|
29
29
|
# => '30 13 * * *'
|
30
30
|
|
31
|
-
cron.new.every(6).hours.on('15th').of(:january)
|
31
|
+
puts cron.new.every(6).hours.on('15th').of(:january)
|
32
32
|
# => '0 0,6,12,18 15 1 *'
|
33
33
|
|
34
|
-
cron.new.every(20).minutes.on(
|
34
|
+
puts cron.new.every(20).minutes.on('15th'..'18th').of(:jan, :feb, :mar)
|
35
35
|
# => '0,20,40 * 15-18 1,2,3 *'
|
36
36
|
|
37
|
-
cron.new.at(14.45).
|
37
|
+
puts cron.new.at(14.45).every(:monday, :tuesday)
|
38
38
|
# => '45 14 * * 1,2'
|
39
39
|
|
40
|
+
|
41
|
+
You can also output the whole cron task string using the schedule method:
|
42
|
+
|
43
|
+
puts Cronos.schedule('some_task').every(:Sunday).at('3am')
|
44
|
+
# => '0 3 * * 0 some_task'
|
45
|
+
|
46
|
+
This does not actually schedule the task in cron. Cronos is merely a DSL to output the cron intervals.
|
47
|
+
|
40
48
|
== Caveats
|
41
49
|
|
42
50
|
Certain combinations produce unintuitive results. They should be obvious but just in case I will
|
data/TODO
CHANGED
data/lib/cronos.rb
CHANGED
@@ -1,14 +1,22 @@
|
|
1
|
+
require 'cronos/version'
|
2
|
+
|
1
3
|
module Cronos
|
2
4
|
|
3
|
-
|
5
|
+
def self.schedule(task)
|
6
|
+
TaskInterval.new(task)
|
7
|
+
end
|
4
8
|
|
5
9
|
class Interval
|
6
10
|
attr_accessor :min, :hour, :day, :month, :dow
|
7
11
|
|
8
|
-
MONTHS = [:jan, :feb, :mar, :apr, :may, :jun, :jul, :aug, :sep, :oct, :nov, :dec]
|
12
|
+
MONTHS = [nil, :jan, :feb, :mar, :apr, :may, :jun, :jul, :aug, :sep, :oct, :nov, :dec]
|
9
13
|
|
10
14
|
DAYS = [:sun, :mon, :tue, :wed, :thu, :fri, :sat]
|
11
15
|
|
16
|
+
def initialize(interval=nil)
|
17
|
+
@min, @hour, @day, @month, @dow = *parse_cron(interval) if interval
|
18
|
+
end
|
19
|
+
|
12
20
|
# Time:
|
13
21
|
# at(12)
|
14
22
|
# at(1.30)
|
@@ -19,14 +27,14 @@ module Cronos
|
|
19
27
|
def at(time)
|
20
28
|
@hour, @min, meridian = parse_time(time)
|
21
29
|
|
22
|
-
raise "invalid hour value for 'at'" if @hour > 12 && meridian
|
23
|
-
raise "invalid minute value for 'at'" if @min > 59
|
30
|
+
raise ArgumentError, "invalid hour value for 'at'" if @hour > 12 && meridian
|
31
|
+
raise ArgumentError, "invalid minute value for 'at'" if @min > 59
|
24
32
|
|
25
33
|
case meridian
|
26
|
-
when 'am'
|
27
|
-
when 'pm'
|
34
|
+
when 'am' then @hour = 0 if @hour == 12
|
35
|
+
when 'pm' then @hour += 12 if @hour < 12
|
28
36
|
end
|
29
|
-
raise "invalid hour value for 'at'" if @hour > 23
|
37
|
+
raise ArgumentError, "invalid hour value for 'at'" if @hour > 23
|
30
38
|
self
|
31
39
|
end
|
32
40
|
|
@@ -37,19 +45,20 @@ module Cronos
|
|
37
45
|
#
|
38
46
|
# or use as an alias for #on or #days
|
39
47
|
# every(:monday)
|
48
|
+
# every(:mon, :tues)
|
49
|
+
# every('Monday'.. 'Wednesday')
|
40
50
|
# every('February', :march)
|
51
|
+
# every('Feb'..'June')
|
41
52
|
#
|
42
53
|
def every(*multiple)
|
43
|
-
return RepeatInterval.new(multiple.first, self) if multiple.first.is_a?(
|
54
|
+
return RepeatInterval.new(multiple.first, self) if multiple.first.is_a?(Numeric)
|
44
55
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
elsif abbrs.all? {|abbr| DAYS.include?(abbr) }
|
50
|
-
days(*abbrs)
|
56
|
+
if multiple.all? {|abbr| is_month?(abbr) }
|
57
|
+
of(*multiple)
|
58
|
+
elsif multiple.all? {|abbr| is_day?(abbr) }
|
59
|
+
days(*multiple)
|
51
60
|
else
|
52
|
-
raise "Unknown interval type passed to #every"
|
61
|
+
raise ArgumentError, "Unknown interval type passed to #every"
|
53
62
|
end
|
54
63
|
end
|
55
64
|
|
@@ -57,6 +66,7 @@ module Cronos
|
|
57
66
|
# on(13)
|
58
67
|
# on('13th')
|
59
68
|
# on(13..17)
|
69
|
+
# on('13th'..'17th')
|
60
70
|
# on(13...18)
|
61
71
|
# on_the('13th')
|
62
72
|
#
|
@@ -76,6 +86,7 @@ module Cronos
|
|
76
86
|
# days('Monday')
|
77
87
|
# days(:mon)
|
78
88
|
# days(1..3)
|
89
|
+
# days('mon'..'wed')
|
79
90
|
# days(1...4)
|
80
91
|
# on_day(:monday)
|
81
92
|
# days(:mon, :tues)
|
@@ -85,7 +96,7 @@ module Cronos
|
|
85
96
|
if args.first.is_a?(Range)
|
86
97
|
@dow = format_range(args.first)
|
87
98
|
else
|
88
|
-
list = args.map {|day|
|
99
|
+
list = args.map {|day| day_value(day) unless day.is_a?(Numeric) }
|
89
100
|
@dow = list.join(',')
|
90
101
|
end
|
91
102
|
self
|
@@ -99,6 +110,7 @@ module Cronos
|
|
99
110
|
# of(:jan)
|
100
111
|
# of(:jan, :feb, :mar)
|
101
112
|
# of(1..3)
|
113
|
+
# of('jan'..'mar')
|
102
114
|
# of(1...4)
|
103
115
|
# of_months(1, 2, 3)
|
104
116
|
# in(:january)
|
@@ -107,7 +119,7 @@ module Cronos
|
|
107
119
|
if args.first.is_a?(Range)
|
108
120
|
@month = format_range(args.first)
|
109
121
|
else
|
110
|
-
list = args.map {|month|
|
122
|
+
list = args.map {|month| month_value(month) unless month.is_a?(Numeric) }
|
111
123
|
@month = list.join(',')
|
112
124
|
end
|
113
125
|
self
|
@@ -193,6 +205,12 @@ module Cronos
|
|
193
205
|
|
194
206
|
private
|
195
207
|
|
208
|
+
def parse_cron(string)
|
209
|
+
parts = string.squeeze(' ').split(' ')
|
210
|
+
parts.collect! {|p| Integer(p) rescue p == '*' ? nil : p }
|
211
|
+
parts[0..4]
|
212
|
+
end
|
213
|
+
|
196
214
|
def parse_time(time)
|
197
215
|
meridian = /pm|am/i.match(time.to_s)[0].downcase rescue nil
|
198
216
|
hour, min = *time.to_s.split('.')
|
@@ -205,10 +223,37 @@ module Cronos
|
|
205
223
|
end
|
206
224
|
|
207
225
|
def format_range(range)
|
208
|
-
|
226
|
+
values = [range.first, range.last]
|
227
|
+
|
228
|
+
if values.all? {|v| v.to_i > 0 }
|
229
|
+
first, last = values.first.to_i, values.last.to_i
|
230
|
+
elsif values.all? {|abbr| is_month?(abbr) }
|
231
|
+
first, last = month_value(values.first), month_value(values.last)
|
232
|
+
elsif values.all? {|abbr| is_day?(abbr) }
|
233
|
+
first, last = day_value(values.first), day_value(values.last)
|
234
|
+
end
|
235
|
+
|
236
|
+
int_range = range.exclude_end? ? first...last : first..last
|
237
|
+
list = Array(int_range).sort
|
209
238
|
"#{list.first}-#{list.last}"
|
210
239
|
end
|
211
240
|
|
241
|
+
def is_month?(value)
|
242
|
+
MONTHS.include?(value.to_s.downcase[0..2].to_sym)
|
243
|
+
end
|
244
|
+
|
245
|
+
def month_value(value)
|
246
|
+
MONTHS.index(value.to_s.downcase[0..2].to_sym)
|
247
|
+
end
|
248
|
+
|
249
|
+
def is_day?(value)
|
250
|
+
DAYS.include?(value.to_s.downcase[0..2].to_sym)
|
251
|
+
end
|
252
|
+
|
253
|
+
def day_value(value)
|
254
|
+
DAYS.index(value.to_s.downcase[0..2].to_sym)
|
255
|
+
end
|
256
|
+
|
212
257
|
class RepeatInterval
|
213
258
|
|
214
259
|
def initialize(multiple, interval)
|
@@ -216,14 +261,16 @@ module Cronos
|
|
216
261
|
end
|
217
262
|
|
218
263
|
def minutes
|
219
|
-
raise 'Multiple of minutes will not fit into an hour' if (60 % @multiple) > 0
|
264
|
+
raise ArgumentError, 'Multiple of minutes will not fit into an hour' if (60 % @multiple) > 0
|
265
|
+
|
220
266
|
calculate_intervals(60)
|
221
267
|
@interval.min = self
|
222
268
|
@interval
|
223
269
|
end
|
224
270
|
|
225
271
|
def hours
|
226
|
-
raise 'Multiple of hours will not fit into a day' if (24 % @multiple) > 0
|
272
|
+
raise ArgumentError, 'Multiple of hours will not fit into a day' if (24 % @multiple) > 0
|
273
|
+
|
227
274
|
calculate_intervals(24)
|
228
275
|
@interval.min = 0
|
229
276
|
@interval.hour = self
|
@@ -231,7 +278,8 @@ module Cronos
|
|
231
278
|
end
|
232
279
|
|
233
280
|
def months
|
234
|
-
raise 'Multiple of months will not fit into a year' if (12 % @multiple) > 0
|
281
|
+
raise ArgumentError, 'Multiple of months will not fit into a year' if (12 % @multiple) > 0
|
282
|
+
|
235
283
|
calculate_intervals(12, 1)
|
236
284
|
@interval.min ||= 0
|
237
285
|
@interval.hour ||= 0
|
@@ -258,4 +306,20 @@ module Cronos
|
|
258
306
|
|
259
307
|
end
|
260
308
|
|
309
|
+
class TaskInterval < Interval
|
310
|
+
attr_accessor :task
|
311
|
+
|
312
|
+
def initialize(task)
|
313
|
+
@task = task
|
314
|
+
end
|
315
|
+
|
316
|
+
def to_s
|
317
|
+
"#{super} #{@task}"
|
318
|
+
end
|
319
|
+
|
320
|
+
def to_hash
|
321
|
+
super.merge(:command => task)
|
322
|
+
end
|
323
|
+
end
|
324
|
+
|
261
325
|
end
|
data/spec/cronos_spec.rb
CHANGED
@@ -1,325 +1,353 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/spec_helper'
|
2
2
|
|
3
|
+
describe Cronos do
|
4
|
+
|
5
|
+
it "should return task interval instance from schedule method" do
|
6
|
+
expect(Cronos.schedule('ls')).to be_kind_of(Cronos::TaskInterval)
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should return task interval hash with command" do
|
10
|
+
expect(Cronos.schedule('ls').at('8.00am').to_hash[:command]).to eq('ls')
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
3
14
|
describe Cronos::Interval do
|
4
15
|
|
5
16
|
it "should return default interval for every minute" do
|
6
|
-
interval.to_s.
|
17
|
+
expect(interval.to_s).to eq('* * * * *')
|
7
18
|
end
|
8
19
|
|
9
20
|
it "should return hash of values from to_hash method" do
|
10
|
-
interval.at(2.01).on_the('3rd').of(:april).to_hash.
|
21
|
+
expect(interval.at(2.01).on_the('3rd').of(:april).to_hash).to eq({:minute => '1', :hour => '2', :day => '3', :month => '4', :weekday => '*'})
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should instantiate interval from cron string" do
|
25
|
+
cron_string = '30 12 * * 0'
|
26
|
+
expect(Cronos::Interval.new(cron_string).to_s).to eq(cron_string)
|
11
27
|
end
|
12
28
|
|
13
29
|
describe "at method" do
|
14
30
|
it "should output interval from integer with hour as integer value and 0 minute" do
|
15
|
-
interval.at(8).to_s.
|
31
|
+
expect(interval.at(8).to_s).to eq('0 8 * * *')
|
16
32
|
end
|
17
33
|
|
18
34
|
it "should output interval from a float with hour value from integer part and minute from decimal part" do
|
19
|
-
interval.at(8.21).to_s.
|
35
|
+
expect(interval.at(8.21).to_s).to eq('21 8 * * *')
|
20
36
|
end
|
21
37
|
|
22
38
|
it "should output interval from a float with hour value from integer part and minute from decimal part left justified to 2 digits" do
|
23
|
-
interval.at(8.20).to_s.
|
39
|
+
expect(interval.at(8.20).to_s).to eq('20 8 * * *')
|
24
40
|
end
|
25
41
|
|
26
42
|
it "should output interval from time string with pm meridian having hour adjusted 24 hour time" do
|
27
|
-
interval.at('8.21pm').to_s.
|
43
|
+
expect(interval.at('8.21pm').to_s).to eq('21 20 * * *')
|
28
44
|
end
|
29
45
|
|
30
46
|
it "should output interval from time string with pm meridian having hour unadjusted if hour is 12" do
|
31
|
-
interval.at('12.21pm').to_s.
|
47
|
+
expect(interval.at('12.21pm').to_s).to eq('21 12 * * *')
|
32
48
|
end
|
33
49
|
|
34
50
|
it "should output interval from time string with am meridian having hour adjusted to 0 if hour is 12" do
|
35
|
-
interval.at('12.21am').to_s.
|
51
|
+
expect(interval.at('12.21am').to_s).to eq('21 0 * * *')
|
36
52
|
end
|
37
53
|
|
38
54
|
it "should raise error if hours out of range" do
|
39
|
-
|
55
|
+
expect { interval.daily.at('24.21') }.to raise_error(ArgumentError)
|
40
56
|
end
|
41
57
|
|
42
58
|
it "should raise error if minutes out of range" do
|
43
|
-
|
59
|
+
expect { interval.daily.at('23.60') }.to raise_error(ArgumentError)
|
44
60
|
end
|
45
61
|
end
|
46
62
|
|
47
63
|
describe "on method" do
|
48
64
|
it "should output interval from integer with day of month as value" do
|
49
|
-
interval.on(15).to_s.
|
65
|
+
expect(interval.on(15).to_s).to eq('* * 15 * *')
|
50
66
|
end
|
51
67
|
|
52
68
|
it "should output interval from day string with ordinal suffix" do
|
53
|
-
interval.on('15th').to_s.
|
69
|
+
expect(interval.on('15th').to_s).to eq('* * 15 * *')
|
54
70
|
end
|
55
71
|
|
56
72
|
it "should output interval from inclusive range as dashed day of month range " do
|
57
|
-
interval.on(15..17).to_s.
|
73
|
+
expect(interval.on(15..17).to_s).to eq('* * 15-17 * *')
|
58
74
|
end
|
59
75
|
|
76
|
+
it "should output interval from string inclusive range as dashed day of month range " do
|
77
|
+
expect(interval.on('15th'..'17th').to_s).to eq('* * 15-17 * *')
|
78
|
+
end
|
79
|
+
|
60
80
|
it "should output interval from exclusive range as dashed day of month range " do
|
61
|
-
interval.on(15...18).to_s.
|
81
|
+
expect(interval.on(15...18).to_s).to eq('* * 15-17 * *')
|
62
82
|
end
|
63
83
|
|
64
84
|
it "should output interval from integer array as day number list" do
|
65
|
-
interval.on(15, 16, 17).to_s.
|
85
|
+
expect(interval.on(15, 16, 17).to_s).to eq('* * 15,16,17 * *')
|
66
86
|
end
|
67
87
|
|
68
88
|
it "should output interval from day string array as day number list" do
|
69
|
-
interval.on('15th', '16th', '17th').to_s.
|
89
|
+
expect(interval.on('15th', '16th', '17th').to_s).to eq('* * 15,16,17 * *')
|
70
90
|
end
|
71
91
|
end
|
72
92
|
|
73
93
|
describe "of method" do
|
74
94
|
it "should output interval with month number from a symbol month name" do
|
75
|
-
interval.of(:january).to_s.
|
95
|
+
expect(interval.of(:january).to_s).to eq('* * * 1 *')
|
76
96
|
end
|
77
97
|
|
78
98
|
it "should output interval with month number from a symbol short month name" do
|
79
|
-
interval.of(:jan).to_s.
|
99
|
+
expect(interval.of(:jan).to_s).to eq('* * * 1 *')
|
80
100
|
end
|
81
101
|
|
82
102
|
it "should output interval with month number from a strong month name" do
|
83
|
-
interval.of('January').to_s.
|
103
|
+
expect(interval.of('January').to_s).to eq('* * * 1 *')
|
84
104
|
end
|
85
105
|
|
86
106
|
it "should output interval with comma seperated month numbers from array of symbol month names" do
|
87
|
-
interval.of(:january, :february, :march).to_s.
|
107
|
+
expect(interval.of(:january, :february, :march).to_s).to eq('* * * 1,2,3 *')
|
88
108
|
end
|
89
109
|
|
90
110
|
it "should output interval with comma seperated month numbers from array of short symbol month names" do
|
91
|
-
interval.of(:jan, :feb, :mar).to_s.
|
111
|
+
expect(interval.of(:jan, :feb, :mar).to_s).to eq('* * * 1,2,3 *')
|
92
112
|
end
|
93
113
|
|
94
114
|
it "should output interval with comma seperated month numbers from array of string month names" do
|
95
|
-
interval.of('January', 'February', 'March').to_s.
|
115
|
+
expect(interval.of('January', 'February', 'March').to_s).to eq('* * * 1,2,3 *')
|
96
116
|
end
|
97
117
|
|
98
118
|
it "should output interval from integer inclusive range as dashed month range " do
|
99
|
-
interval.of(1..3).to_s.
|
119
|
+
expect(interval.of(1..3).to_s).to eq('* * * 1-3 *')
|
120
|
+
end
|
121
|
+
|
122
|
+
it "should output interval from string inclusive range as dashed month range " do
|
123
|
+
expect(interval.of('jan'..'mar').to_s).to eq('* * * 1-3 *')
|
100
124
|
end
|
101
125
|
|
102
126
|
it "should output interval from integer exclusive range as dashed month range " do
|
103
|
-
interval.of(1...4).to_s.
|
127
|
+
expect(interval.of(1...4).to_s).to eq('* * * 1-3 *')
|
104
128
|
end
|
105
129
|
end
|
106
130
|
|
107
131
|
describe "days method" do
|
108
132
|
it "should output interval with day number from a symbol day name" do
|
109
|
-
interval.days(:monday).to_s.
|
133
|
+
expect(interval.days(:monday).to_s).to eq('* * * * 1')
|
110
134
|
end
|
111
135
|
|
112
136
|
it "should output interval with day number from a string day name" do
|
113
|
-
interval.days('Mondays').to_s.
|
137
|
+
expect(interval.days('Mondays').to_s).to eq('* * * * 1')
|
114
138
|
end
|
115
139
|
|
116
140
|
it "should output interval with day number from a symbol short day name" do
|
117
|
-
interval.days(:mon).to_s.
|
141
|
+
expect(interval.days(:mon).to_s).to eq('* * * * 1')
|
118
142
|
end
|
119
143
|
|
120
144
|
it "should output interval with day numbers from array of symbol day names" do
|
121
|
-
interval.days(:monday, :wednesday, :friday).to_s.
|
145
|
+
expect(interval.days(:monday, :wednesday, :friday).to_s).to eq('* * * * 1,3,5')
|
122
146
|
end
|
123
147
|
|
124
148
|
it "should output interval with day numbers from array of symbol short day names" do
|
125
|
-
interval.days(:mon, :wed, :fri).to_s.
|
149
|
+
expect(interval.days(:mon, :wed, :fri).to_s).to eq('* * * * 1,3,5')
|
126
150
|
end
|
127
151
|
|
128
152
|
it "should output interval with day numbers from array of string day names" do
|
129
|
-
interval.days('Monday', 'Wednesday', 'Friday').to_s.
|
153
|
+
expect(interval.days('Monday', 'Wednesday', 'Friday').to_s).to eq('* * * * 1,3,5')
|
130
154
|
end
|
131
155
|
|
132
156
|
it "should output interval from integer inclusive range as dashed dow range " do
|
133
|
-
interval.days(1..3).to_s.
|
157
|
+
expect(interval.days(1..3).to_s).to eq('* * * * 1-3')
|
158
|
+
end
|
159
|
+
|
160
|
+
it "should output interval from string inclusive range as dashed dow range " do
|
161
|
+
expect(interval.days('mon'..'wed').to_s).to eq('* * * * 1-3')
|
134
162
|
end
|
135
163
|
|
136
164
|
it "should output interval from integer exclusive range as dashed dow range " do
|
137
|
-
interval.days(1...4).to_s.
|
165
|
+
expect(interval.days(1...4).to_s).to eq('* * * * 1-3')
|
138
166
|
end
|
139
167
|
end
|
140
168
|
|
141
169
|
describe "hourly method" do
|
142
170
|
it "should output interval to run at start of every hour" do
|
143
|
-
interval.hourly.to_s.
|
171
|
+
expect(interval.hourly.to_s).to eq('0 * * * *')
|
144
172
|
end
|
145
173
|
|
146
174
|
it "should only affect the hour and minutes" do
|
147
175
|
interval.day = 1
|
148
176
|
interval.month = 1
|
149
177
|
interval.dow = 1
|
150
|
-
interval.hourly.to_s.
|
178
|
+
expect(interval.hourly.to_s).to eq('0 * 1 1 1')
|
151
179
|
end
|
152
180
|
end
|
153
181
|
|
154
182
|
describe "daily method" do
|
155
183
|
it "should output interval to run at 00:00 every day by default" do
|
156
|
-
interval.daily.to_s.
|
184
|
+
expect(interval.daily.to_s).to eq('0 0 * * *')
|
157
185
|
end
|
158
186
|
|
159
187
|
it "should only affect the hour, minutes and day" do
|
160
188
|
interval.month = 1
|
161
189
|
interval.dow = 1
|
162
|
-
interval.daily.to_s.
|
190
|
+
expect(interval.daily.to_s).to eq('0 0 * 1 1')
|
163
191
|
end
|
164
192
|
|
165
193
|
it "should preserve hour and minutes if set" do
|
166
194
|
interval.min = 10
|
167
195
|
interval.hour = 11
|
168
|
-
interval.daily.to_s.
|
196
|
+
expect(interval.daily.to_s).to eq('10 11 * * *')
|
169
197
|
end
|
170
198
|
end
|
171
199
|
|
172
200
|
describe "midnight method" do
|
173
201
|
it "should output interval to run at 00:00" do
|
174
|
-
interval.midnight.to_s.
|
202
|
+
expect(interval.midnight.to_s).to eq('0 0 * * *')
|
175
203
|
end
|
176
204
|
end
|
177
205
|
|
178
206
|
describe "midday method" do
|
179
207
|
it "should output interval to run at 12:00" do
|
180
|
-
interval.midday.to_s.
|
208
|
+
expect(interval.midday.to_s).to eq('0 12 * * *')
|
181
209
|
end
|
182
210
|
end
|
183
211
|
|
184
212
|
describe "weekly method" do
|
185
213
|
it "should output interval to run on Sunday at 00:00 by default" do
|
186
|
-
interval.weekly.to_s.
|
214
|
+
expect(interval.weekly.to_s).to eq('0 0 * * 0')
|
187
215
|
end
|
188
216
|
|
189
217
|
it "should override day of month and month" do
|
190
218
|
interval.day = 1
|
191
219
|
interval.month = 1
|
192
|
-
interval.weekly.to_s.
|
220
|
+
expect(interval.weekly.to_s).to eq('0 0 * * 0')
|
193
221
|
end
|
194
222
|
|
195
223
|
it "should preserve hour, minute and day of week if set" do
|
196
224
|
interval.min = 10
|
197
225
|
interval.hour = 11
|
198
226
|
interval.dow = 1
|
199
|
-
interval.daily.to_s.
|
227
|
+
expect(interval.daily.to_s).to eq('10 11 * * 1')
|
200
228
|
end
|
201
229
|
end
|
202
230
|
|
203
231
|
describe "monthly method" do
|
204
232
|
it "should output interval to run on the 1st day of every month at 00:00 by default" do
|
205
|
-
interval.monthly.to_s.
|
233
|
+
expect(interval.monthly.to_s).to eq('0 0 1 * *')
|
206
234
|
end
|
207
235
|
|
208
236
|
it "should override day of month and month" do
|
209
237
|
interval.day = 1
|
210
238
|
interval.month = 1
|
211
|
-
interval.monthly.to_s.
|
239
|
+
expect(interval.monthly.to_s).to eq('0 0 1 * *')
|
212
240
|
end
|
213
241
|
|
214
242
|
it "should preserve hour, minute and day if set" do
|
215
243
|
interval.min = 10
|
216
244
|
interval.hour = 11
|
217
245
|
interval.day = 12
|
218
|
-
interval.monthly.to_s.
|
246
|
+
expect(interval.monthly.to_s).to eq('10 11 12 * *')
|
219
247
|
end
|
220
248
|
end
|
221
249
|
|
222
250
|
describe "weekends method" do
|
223
251
|
it "should output interval to run at 00:00 every Saturday and Sunday" do
|
224
|
-
interval.weekends.to_s.
|
252
|
+
expect(interval.weekends.to_s).to eq('0 0 * * 0,6')
|
225
253
|
end
|
226
254
|
end
|
227
255
|
|
228
256
|
describe "weekdays method" do
|
229
257
|
it "should output interval to run at 00:00 every day Monday to Friday" do
|
230
|
-
interval.weekdays.to_s.
|
258
|
+
expect(interval.weekdays.to_s).to eq('0 0 * * 1-5')
|
231
259
|
end
|
232
260
|
end
|
233
261
|
|
234
262
|
describe "every(x).minutes" do
|
235
263
|
it "should output interval for list of minutes differing by arg value" do
|
236
|
-
interval.every(15).minutes.to_s.
|
264
|
+
expect(interval.every(15).minutes.to_s).to eq('0,15,30,45 * * * *')
|
237
265
|
end
|
238
266
|
|
239
267
|
it "should raise error if x not a divisor of 60" do
|
240
|
-
|
268
|
+
expect { interval.every(13).minutes }.to raise_error(ArgumentError)
|
241
269
|
end
|
242
270
|
end
|
243
271
|
|
244
272
|
describe "every(x).hours" do
|
245
273
|
it "should output interval for 0 minute and list of hours differing by arg value" do
|
246
|
-
interval.every(6).hours.to_s.
|
274
|
+
expect(interval.every(6).hours.to_s).to eq('0 0,6,12,18 * * *')
|
247
275
|
end
|
248
276
|
|
249
277
|
it "should raise error if x not a divisor of 24" do
|
250
|
-
|
278
|
+
expect { interval.every(13).minutes }.to raise_error(ArgumentError)
|
251
279
|
end
|
252
280
|
end
|
253
281
|
|
254
282
|
describe "every(x).months" do
|
255
283
|
it "should output interval for 00:00 on 1st day of month and list of months differing by arg value" do
|
256
|
-
interval.every(6).hours.to_s.
|
284
|
+
expect(interval.every(6).hours.to_s).to eq('0 0,6,12,18 * * *')
|
257
285
|
end
|
258
286
|
|
259
287
|
it "should raise error if x not a divisor of 12" do
|
260
|
-
|
288
|
+
expect { interval.every(7).minutes }.to raise_error(ArgumentError)
|
261
289
|
end
|
262
290
|
end
|
263
291
|
|
264
292
|
describe "every(day_name)" do
|
265
293
|
it "should output interval for day symbol as day of week" do
|
266
|
-
interval.every(:sunday).to_s.
|
294
|
+
expect(interval.every(:sunday).to_s).to eq('* * * * 0')
|
267
295
|
end
|
268
296
|
|
269
297
|
it "should output interval for list of days as days of week" do
|
270
|
-
interval.every(:thursay, 'Friday').to_s.
|
298
|
+
expect(interval.every(:thursay, 'Friday').to_s).to eq('* * * * 4,5')
|
271
299
|
end
|
272
300
|
end
|
273
301
|
|
274
302
|
describe "every(month_name)" do
|
275
303
|
it "should output interval for month symbol as month" do
|
276
|
-
interval.every(:january).to_s.
|
304
|
+
expect(interval.every(:january).to_s).to eq('* * * 1 *')
|
277
305
|
end
|
278
306
|
|
279
307
|
it "should output interval for list of months as months" do
|
280
|
-
interval.every(:february, 'March').to_s.
|
308
|
+
expect(interval.every(:february, 'March').to_s).to eq('* * * 2,3 *')
|
281
309
|
end
|
282
310
|
end
|
283
311
|
|
284
312
|
describe "combinations" do
|
285
313
|
it "weekly.at(3.30) should output '30 3 * * 0'" do
|
286
|
-
interval.weekly.at(3.30).to_s.
|
314
|
+
expect(interval.weekly.at(3.30).to_s).to eq('30 3 * * 0')
|
287
315
|
end
|
288
316
|
|
289
317
|
it "monthly.at(3.30) should output '30 3 * * *'" do
|
290
|
-
interval.monthly.at(3.30).to_s.
|
318
|
+
expect(interval.monthly.at(3.30).to_s).to eq('30 3 1 * *')
|
291
319
|
end
|
292
320
|
|
293
321
|
it "monthly.on_the('15th').at(3.30) should output '30 3 15 * *'" do
|
294
|
-
interval.monthly.on_the('15th').at(3.30).to_s.
|
322
|
+
expect(interval.monthly.on_the('15th').at(3.30).to_s).to eq('30 3 15 * *')
|
295
323
|
end
|
296
324
|
|
297
325
|
it "at('11pm').on_days(:monday, :tuesday) should output '0 11 * * 1,2'" do
|
298
|
-
interval.at('11pm').on_days(:monday, :tuesday).to_s.
|
326
|
+
expect(interval.at('11pm').on_days(:monday, :tuesday).to_s).to eq('0 23 * * 1,2')
|
299
327
|
end
|
300
328
|
|
301
329
|
it "on(15).of(:january) should output '* * 15 1 *'" do
|
302
|
-
interval.on(15).of(:january).to_s.
|
330
|
+
expect(interval.on(15).of(:january).to_s).to eq('* * 15 1 *')
|
303
331
|
end
|
304
332
|
|
305
333
|
it "on(15, 16, 17).of(:january) should output '* * 15,16,17 1 *'" do
|
306
|
-
interval.on(15, 16, 17).of(:january).to_s.
|
334
|
+
expect(interval.on(15, 16, 17).of(:january).to_s).to eq('* * 15,16,17 1 *')
|
307
335
|
end
|
308
336
|
|
309
337
|
it "on(15..17).of(:january) should output '* * 15-17 1 *'" do
|
310
|
-
interval.on(15..17).of(:january).to_s.
|
338
|
+
expect(interval.on(15..17).of(:january).to_s).to eq('* * 15-17 1 *')
|
311
339
|
end
|
312
340
|
|
313
341
|
it "on(15, 16, 17).of(:january) should output '* * 15 1,6,12 *'" do
|
314
|
-
interval.on(15).of(:jan, :jun, :dec).to_s.
|
342
|
+
expect(interval.on(15).of(:jan, :jun, :dec).to_s).to eq('* * 15 1,6,12 *')
|
315
343
|
end
|
316
344
|
|
317
345
|
it "at('2.13pm').on_the_('15th').of(:january) should output '13 14 15 1'" do
|
318
|
-
interval.at('2.13pm').on_the(15).of(:january).to_s.
|
346
|
+
expect(interval.at('2.13pm').on_the(15).of(:january).to_s).to eq('13 14 15 1 *')
|
319
347
|
end
|
320
348
|
|
321
349
|
it "every(15).minutes.on_the('15th').of(:january) should output '0,15,30,45 * 15 1 *'" do
|
322
|
-
interval.every(15).minutes.on_the('15th').of(:january).to_s.
|
350
|
+
expect(interval.every(15).minutes.on_the('15th').of(:january).to_s).to eq('0,15,30,45 * 15 1 *')
|
323
351
|
end
|
324
352
|
end
|
325
353
|
|
@@ -327,3 +355,11 @@ describe Cronos::Interval do
|
|
327
355
|
@interval ||= Cronos::Interval.new
|
328
356
|
end
|
329
357
|
end
|
358
|
+
|
359
|
+
describe Cronos::TaskInterval do
|
360
|
+
|
361
|
+
it "should output task at end of interval string" do
|
362
|
+
expect(Cronos::TaskInterval.new('ls').at('12pm').to_s).to eq('0 12 * * * ls')
|
363
|
+
end
|
364
|
+
|
365
|
+
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,63 +1,67 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: cronos
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.4.2
|
5
5
|
platform: ruby
|
6
|
-
authors:
|
6
|
+
authors:
|
7
7
|
- Adam Meehan
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
11
|
+
date: 2022-03-30 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rspec
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '3.0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '3.0'
|
27
|
+
description: A builder DSL for generating cron intervals using a human readable English
|
28
|
+
syntax
|
17
29
|
email: adam.meehan@gmail.com
|
18
30
|
executables: []
|
19
|
-
|
20
31
|
extensions: []
|
21
|
-
|
22
|
-
|
23
|
-
- README.rdoc
|
24
|
-
- LICENSE
|
25
|
-
- TODO
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
26
34
|
- CHANGELOG
|
27
|
-
files:
|
28
35
|
- LICENSE
|
29
36
|
- README.rdoc
|
30
37
|
- Rakefile
|
31
38
|
- TODO
|
32
|
-
- CHANGELOG
|
33
39
|
- lib/cronos.rb
|
34
|
-
-
|
40
|
+
- lib/cronos/version.rb
|
35
41
|
- spec/cronos_spec.rb
|
36
|
-
|
42
|
+
- spec/spec_helper.rb
|
37
43
|
homepage: http://github.com/adzap/cronos
|
38
|
-
|
44
|
+
licenses:
|
45
|
+
- MIT
|
46
|
+
metadata:
|
47
|
+
source_code_uri: https://github.com/adzap/cronos
|
48
|
+
post_install_message:
|
39
49
|
rdoc_options: []
|
40
|
-
|
41
|
-
require_paths:
|
50
|
+
require_paths:
|
42
51
|
- lib
|
43
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
52
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
45
54
|
- - ">="
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version:
|
48
|
-
|
49
|
-
|
50
|
-
requirements:
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '0'
|
57
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
51
59
|
- - ">="
|
52
|
-
- !ruby/object:Gem::Version
|
53
|
-
version:
|
54
|
-
version:
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
55
62
|
requirements: []
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
signing_key:
|
60
|
-
specification_version: 2
|
63
|
+
rubygems_version: 3.0.3.1
|
64
|
+
signing_key:
|
65
|
+
specification_version: 4
|
61
66
|
summary: Tool for generating cron intervals using a natural syntax
|
62
67
|
test_files: []
|
63
|
-
|