whenever 0.9.7 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.travis.yml +12 -9
- data/Appraisals +19 -0
- data/CHANGELOG.md +33 -1
- data/Gemfile +1 -1
- data/LICENSE +1 -1
- data/README.md +89 -20
- data/bin/whenever +3 -0
- data/bin/wheneverize +5 -2
- data/gemfiles/activesupport4.1.gemfile +3 -1
- data/gemfiles/activesupport4.2.gemfile +3 -1
- data/gemfiles/activesupport5.0.gemfile +7 -0
- data/gemfiles/activesupport5.1.gemfile +7 -0
- data/gemfiles/activesupport5.2.gemfile +7 -0
- data/lib/whenever/capistrano/v2/recipes.rb +3 -2
- data/lib/whenever/capistrano/v3/tasks/whenever.rake +17 -4
- data/lib/whenever/command_line.rb +39 -19
- data/lib/whenever/cron.rb +43 -15
- data/lib/whenever/job.rb +2 -1
- data/lib/whenever/job_list.rb +50 -20
- data/lib/whenever/numeric.rb +1 -1
- data/lib/whenever/setup.rb +4 -0
- data/lib/whenever/version.rb +1 -1
- data/test/functional/command_line_test.rb +159 -32
- data/test/functional/output_at_test.rb +39 -0
- data/test/functional/output_jobs_with_mailto_test.rb +168 -0
- data/test/test_helper.rb +18 -8
- data/test/unit/cron_test.rb +178 -4
- data/test/unit/executable_test.rb +142 -0
- data/whenever.gemspec +1 -0
- metadata +25 -3
@@ -0,0 +1,168 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class OutputJobsWithMailtoTest < Whenever::TestCase
|
4
|
+
test "defined job with a mailto argument" do
|
5
|
+
output = Whenever.cron \
|
6
|
+
<<-file
|
7
|
+
every 2.hours do
|
8
|
+
command "blahblah", mailto: 'someone@example.com'
|
9
|
+
end
|
10
|
+
file
|
11
|
+
|
12
|
+
output_without_empty_line = lines_without_empty_line(output.lines)
|
13
|
+
|
14
|
+
assert_equal 'MAILTO=someone@example.com', output_without_empty_line.shift
|
15
|
+
assert_equal two_hours + " /bin/bash -l -c 'blahblah'", output_without_empty_line.shift
|
16
|
+
end
|
17
|
+
|
18
|
+
test "defined job with every method's block and a mailto argument" do
|
19
|
+
output = Whenever.cron \
|
20
|
+
<<-file
|
21
|
+
every 2.hours, mailto: 'someone@example.com' do
|
22
|
+
command "blahblah"
|
23
|
+
end
|
24
|
+
file
|
25
|
+
|
26
|
+
output_without_empty_line = lines_without_empty_line(output.lines)
|
27
|
+
|
28
|
+
assert_equal 'MAILTO=someone@example.com', output_without_empty_line.shift
|
29
|
+
assert_equal two_hours + " /bin/bash -l -c 'blahblah'", output_without_empty_line.shift
|
30
|
+
end
|
31
|
+
|
32
|
+
test "defined job which overrided mailto argument in the block" do
|
33
|
+
output = Whenever.cron \
|
34
|
+
<<-file
|
35
|
+
every 2.hours, mailto: 'of_the_block@example.com' do
|
36
|
+
command "blahblah", mailto: 'overrided_in_the_block@example.com'
|
37
|
+
end
|
38
|
+
file
|
39
|
+
|
40
|
+
output_without_empty_line = lines_without_empty_line(output.lines)
|
41
|
+
|
42
|
+
assert_equal 'MAILTO=overrided_in_the_block@example.com', output_without_empty_line.shift
|
43
|
+
assert_equal two_hours + " /bin/bash -l -c 'blahblah'", output_without_empty_line.shift
|
44
|
+
end
|
45
|
+
|
46
|
+
test "defined some jobs with various mailto argument" do
|
47
|
+
output = Whenever.cron \
|
48
|
+
<<-file
|
49
|
+
every 2.hours do
|
50
|
+
command "blahblah"
|
51
|
+
end
|
52
|
+
|
53
|
+
every 2.hours, mailto: 'john@example.com' do
|
54
|
+
command "blahblah_of_john"
|
55
|
+
command "blahblah2_of_john"
|
56
|
+
end
|
57
|
+
|
58
|
+
every 2.hours, mailto: 'sarah@example.com' do
|
59
|
+
command "blahblah_of_sarah"
|
60
|
+
end
|
61
|
+
|
62
|
+
every 2.hours do
|
63
|
+
command "blahblah_of_martin", mailto: 'martin@example.com'
|
64
|
+
command "blahblah2_of_sarah", mailto: 'sarah@example.com'
|
65
|
+
end
|
66
|
+
|
67
|
+
every 2.hours do
|
68
|
+
command "blahblah2"
|
69
|
+
end
|
70
|
+
file
|
71
|
+
|
72
|
+
output_without_empty_line = lines_without_empty_line(output.lines)
|
73
|
+
|
74
|
+
assert_equal two_hours + " /bin/bash -l -c 'blahblah'", output_without_empty_line.shift
|
75
|
+
assert_equal two_hours + " /bin/bash -l -c 'blahblah2'", output_without_empty_line.shift
|
76
|
+
|
77
|
+
assert_equal 'MAILTO=john@example.com', output_without_empty_line.shift
|
78
|
+
assert_equal two_hours + " /bin/bash -l -c 'blahblah_of_john'", output_without_empty_line.shift
|
79
|
+
assert_equal two_hours + " /bin/bash -l -c 'blahblah2_of_john'", output_without_empty_line.shift
|
80
|
+
|
81
|
+
assert_equal 'MAILTO=sarah@example.com', output_without_empty_line.shift
|
82
|
+
assert_equal two_hours + " /bin/bash -l -c 'blahblah_of_sarah'", output_without_empty_line.shift
|
83
|
+
assert_equal two_hours + " /bin/bash -l -c 'blahblah2_of_sarah'", output_without_empty_line.shift
|
84
|
+
|
85
|
+
assert_equal 'MAILTO=martin@example.com', output_without_empty_line.shift
|
86
|
+
assert_equal two_hours + " /bin/bash -l -c 'blahblah_of_martin'", output_without_empty_line.shift
|
87
|
+
end
|
88
|
+
|
89
|
+
test "defined some jobs with no mailto argument jobs and mailto argument jobs(no mailto jobs should be first line of cron output" do
|
90
|
+
output = Whenever.cron \
|
91
|
+
<<-file
|
92
|
+
every 2.hours, mailto: 'john@example.com' do
|
93
|
+
command "blahblah_of_john"
|
94
|
+
command "blahblah2_of_john"
|
95
|
+
end
|
96
|
+
|
97
|
+
every 2.hours do
|
98
|
+
command "blahblah"
|
99
|
+
end
|
100
|
+
file
|
101
|
+
|
102
|
+
output_without_empty_line = lines_without_empty_line(output.lines)
|
103
|
+
|
104
|
+
assert_equal two_hours + " /bin/bash -l -c 'blahblah'", output_without_empty_line.shift
|
105
|
+
|
106
|
+
assert_equal 'MAILTO=john@example.com', output_without_empty_line.shift
|
107
|
+
assert_equal two_hours + " /bin/bash -l -c 'blahblah_of_john'", output_without_empty_line.shift
|
108
|
+
assert_equal two_hours + " /bin/bash -l -c 'blahblah2_of_john'", output_without_empty_line.shift
|
109
|
+
end
|
110
|
+
|
111
|
+
test "defined some jobs with environment mailto define and various mailto argument" do
|
112
|
+
output = Whenever.cron \
|
113
|
+
<<-file
|
114
|
+
env 'MAILTO', 'default@example.com'
|
115
|
+
|
116
|
+
every 2.hours do
|
117
|
+
command "blahblah"
|
118
|
+
end
|
119
|
+
|
120
|
+
every 2.hours, mailto: 'sarah@example.com' do
|
121
|
+
command "blahblah_by_sarah"
|
122
|
+
end
|
123
|
+
|
124
|
+
every 2.hours do
|
125
|
+
command "blahblah_by_john", mailto: 'john@example.com'
|
126
|
+
end
|
127
|
+
|
128
|
+
every 2.hours do
|
129
|
+
command "blahblah2"
|
130
|
+
end
|
131
|
+
file
|
132
|
+
|
133
|
+
output_without_empty_line = lines_without_empty_line(output.lines)
|
134
|
+
|
135
|
+
assert_equal 'MAILTO=default@example.com', output_without_empty_line.shift
|
136
|
+
assert_equal two_hours + " /bin/bash -l -c 'blahblah'", output_without_empty_line.shift
|
137
|
+
assert_equal two_hours + " /bin/bash -l -c 'blahblah2'", output_without_empty_line.shift
|
138
|
+
|
139
|
+
assert_equal 'MAILTO=sarah@example.com', output_without_empty_line.shift
|
140
|
+
assert_equal two_hours + " /bin/bash -l -c 'blahblah_by_sarah'", output_without_empty_line.shift
|
141
|
+
|
142
|
+
assert_equal 'MAILTO=john@example.com', output_without_empty_line.shift
|
143
|
+
assert_equal two_hours + " /bin/bash -l -c 'blahblah_by_john'", output_without_empty_line.shift
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
class OutputJobsWithMailtoForRolesTest < Whenever::TestCase
|
148
|
+
test "one role requested and specified on the job with mailto argument" do
|
149
|
+
output = Whenever.cron roles: [:role1], :string => \
|
150
|
+
<<-file
|
151
|
+
env 'MAILTO', 'default@example.com'
|
152
|
+
|
153
|
+
every 2.hours, :roles => [:role1] do
|
154
|
+
command "blahblah"
|
155
|
+
end
|
156
|
+
|
157
|
+
every 2.hours, mailto: 'sarah@example.com', :roles => [:role2] do
|
158
|
+
command "blahblah_by_sarah"
|
159
|
+
end
|
160
|
+
file
|
161
|
+
|
162
|
+
output_without_empty_line = lines_without_empty_line(output.lines)
|
163
|
+
|
164
|
+
assert_equal 'MAILTO=default@example.com', output_without_empty_line.shift
|
165
|
+
assert_equal two_hours + " /bin/bash -l -c 'blahblah'", output_without_empty_line.shift
|
166
|
+
assert_nil output_without_empty_line.shift
|
167
|
+
end
|
168
|
+
end
|
data/test/test_helper.rb
CHANGED
@@ -8,30 +8,40 @@ module Whenever::TestHelpers
|
|
8
8
|
Whenever::Job.new(options)
|
9
9
|
end
|
10
10
|
|
11
|
-
def parse_time(time = nil, task = nil, at = nil)
|
12
|
-
Whenever::Output::Cron.new(time, task, at).time_in_cron_syntax
|
11
|
+
def parse_time(time = nil, task = nil, at = nil, options = {})
|
12
|
+
Whenever::Output::Cron.new(time, task, at, options).time_in_cron_syntax
|
13
13
|
end
|
14
14
|
|
15
15
|
def two_hours
|
16
16
|
"0 0,2,4,6,8,10,12,14,16,18,20,22 * * *"
|
17
17
|
end
|
18
18
|
|
19
|
-
def
|
20
|
-
cron = parse_time(Whenever.seconds(
|
19
|
+
def assert_months_and_days_and_hours_and_minutes_equals(expected, time, options = {})
|
20
|
+
cron = parse_time(Whenever.seconds(1, :year), 'some task', time, options)
|
21
|
+
minutes, hours, days, months = cron.split(' ')
|
22
|
+
assert_equal expected, [months, days, hours, minutes]
|
23
|
+
end
|
24
|
+
|
25
|
+
def assert_days_and_hours_and_minutes_equals(expected, time, options = {})
|
26
|
+
cron = parse_time(Whenever.seconds(2, :months), 'some task', time, options)
|
21
27
|
minutes, hours, days, _ = cron.split(' ')
|
22
28
|
assert_equal expected, [days, hours, minutes]
|
23
29
|
end
|
24
30
|
|
25
|
-
def assert_hours_and_minutes_equals(expected, time)
|
26
|
-
cron = parse_time(Whenever.seconds(2, :days), 'some task', time)
|
31
|
+
def assert_hours_and_minutes_equals(expected, time, options = {})
|
32
|
+
cron = parse_time(Whenever.seconds(2, :days), 'some task', time, options)
|
27
33
|
minutes, hours, _ = cron.split(' ')
|
28
34
|
assert_equal expected, [hours, minutes]
|
29
35
|
end
|
30
36
|
|
31
|
-
def assert_minutes_equals(expected, time)
|
32
|
-
cron = parse_time(Whenever.seconds(2, :hours), 'some task', time)
|
37
|
+
def assert_minutes_equals(expected, time, options = {})
|
38
|
+
cron = parse_time(Whenever.seconds(2, :hours), 'some task', time, options)
|
33
39
|
assert_equal expected, cron.split(' ')[0]
|
34
40
|
end
|
41
|
+
|
42
|
+
def lines_without_empty_line(lines)
|
43
|
+
lines.map { |line| line.chomp }.reject { |line| line.empty? }
|
44
|
+
end
|
35
45
|
end
|
36
46
|
|
37
47
|
Whenever::TestCase.send(:include, Whenever::TestHelpers)
|
data/test/unit/cron_test.rb
CHANGED
@@ -67,6 +67,38 @@ class CronParseHoursTest < Whenever::TestCase
|
|
67
67
|
assert_minutes_equals "0", 'midnight'
|
68
68
|
assert_minutes_equals "59", '13:59'
|
69
69
|
end
|
70
|
+
|
71
|
+
should "parse correctly when given an 'at' with minutes as a Time and custom Chronic options are set" do
|
72
|
+
assert_minutes_equals "15", '3:15'
|
73
|
+
assert_minutes_equals "15", '3:15', :chronic_options => { :hours24 => true }
|
74
|
+
assert_minutes_equals "15", '3:15', :chronic_options => { :hours24 => false }
|
75
|
+
|
76
|
+
assert_minutes_equals "30", '6:30'
|
77
|
+
assert_minutes_equals "30", '6:30', :chronic_options => { :hours24 => true }
|
78
|
+
assert_minutes_equals "30", '6:30', :chronic_options => { :hours24 => false }
|
79
|
+
end
|
80
|
+
|
81
|
+
should "parse correctly when given an 'at' with minutes as a Range" do
|
82
|
+
assert_minutes_equals "15-30", 15..30
|
83
|
+
end
|
84
|
+
|
85
|
+
should "raise an exception when given an 'at' with an invalid minute value" do
|
86
|
+
assert_raises ArgumentError do
|
87
|
+
parse_time(Whenever.seconds(1, :hour), nil, 60)
|
88
|
+
end
|
89
|
+
|
90
|
+
assert_raises ArgumentError do
|
91
|
+
parse_time(Whenever.seconds(1, :hour), nil, -1)
|
92
|
+
end
|
93
|
+
|
94
|
+
assert_raises ArgumentError do
|
95
|
+
parse_time(Whenever.seconds(1, :hour), nil, 0..60)
|
96
|
+
end
|
97
|
+
|
98
|
+
assert_raises ArgumentError do
|
99
|
+
parse_time(Whenever.seconds(1, :hour), nil, -1..59)
|
100
|
+
end
|
101
|
+
end
|
70
102
|
end
|
71
103
|
|
72
104
|
class CronParseDaysTest < Whenever::TestCase
|
@@ -90,6 +122,17 @@ class CronParseDaysTest < Whenever::TestCase
|
|
90
122
|
assert_hours_and_minutes_equals %w(23 59), 'March 21 11:59 pM'
|
91
123
|
end
|
92
124
|
|
125
|
+
should "parse correctly when given an 'at' with hours, minutes as a Time and custom Chronic options are set" do
|
126
|
+
# first param is an array with [hours, minutes]
|
127
|
+
assert_hours_and_minutes_equals %w(15 15), '3:15'
|
128
|
+
assert_hours_and_minutes_equals %w(3 15), '3:15', :chronic_options => { :hours24 => true }
|
129
|
+
assert_hours_and_minutes_equals %w(15 15), '3:15', :chronic_options => { :hours24 => false }
|
130
|
+
|
131
|
+
assert_hours_and_minutes_equals %w(6 30), '6:30'
|
132
|
+
assert_hours_and_minutes_equals %w(6 30), '6:30', :chronic_options => { :hours24 => true }
|
133
|
+
assert_hours_and_minutes_equals %w(6 30), '6:30', :chronic_options => { :hours24 => false }
|
134
|
+
end
|
135
|
+
|
93
136
|
should "parse correctly when given an 'at' with hours as an Integer" do
|
94
137
|
# first param is an array with [hours, minutes]
|
95
138
|
assert_hours_and_minutes_equals %w(1 0), 1
|
@@ -98,6 +141,28 @@ class CronParseDaysTest < Whenever::TestCase
|
|
98
141
|
assert_hours_and_minutes_equals %w(19 0), 19
|
99
142
|
assert_hours_and_minutes_equals %w(23 0), 23
|
100
143
|
end
|
144
|
+
|
145
|
+
should "parse correctly when given an 'at' with hours as a Range" do
|
146
|
+
assert_hours_and_minutes_equals %w(3-23 0), 3..23
|
147
|
+
end
|
148
|
+
|
149
|
+
should "raise an exception when given an 'at' with an invalid hour value" do
|
150
|
+
assert_raises ArgumentError do
|
151
|
+
parse_time(Whenever.seconds(1, :day), nil, 24)
|
152
|
+
end
|
153
|
+
|
154
|
+
assert_raises ArgumentError do
|
155
|
+
parse_time(Whenever.seconds(1, :day), nil, -1)
|
156
|
+
end
|
157
|
+
|
158
|
+
assert_raises ArgumentError do
|
159
|
+
parse_time(Whenever.seconds(1, :day), nil, 0..24)
|
160
|
+
end
|
161
|
+
|
162
|
+
assert_raises ArgumentError do
|
163
|
+
parse_time(Whenever.seconds(1, :day), nil, -1..23)
|
164
|
+
end
|
165
|
+
end
|
101
166
|
end
|
102
167
|
|
103
168
|
class CronParseMonthsTest < Whenever::TestCase
|
@@ -132,12 +197,120 @@ class CronParseMonthsTest < Whenever::TestCase
|
|
132
197
|
assert_days_and_hours_and_minutes_equals %w(23 0 0), 'march 22nd at midnight' # looks like midnight means the next day
|
133
198
|
end
|
134
199
|
|
200
|
+
should "parse correctly when given an 'at' with days, hours, minutes as a Time and custom Chronic options are set" do
|
201
|
+
# first param is an array with [days, hours, minutes]
|
202
|
+
assert_days_and_hours_and_minutes_equals %w(22 15 45), 'February 22nd 3:45'
|
203
|
+
assert_days_and_hours_and_minutes_equals %w(22 15 45), '02/22 3:45'
|
204
|
+
assert_days_and_hours_and_minutes_equals %w(22 3 45), 'February 22nd 3:45', :chronic_options => { :hours24 => true }
|
205
|
+
assert_days_and_hours_and_minutes_equals %w(22 15 45), 'February 22nd 3:45', :chronic_options => { :hours24 => false }
|
206
|
+
|
207
|
+
assert_days_and_hours_and_minutes_equals %w(3 8 15), '02/03 8:15'
|
208
|
+
assert_days_and_hours_and_minutes_equals %w(3 8 15), '02/03 8:15', :chronic_options => { :endian_precedence => :middle }
|
209
|
+
assert_days_and_hours_and_minutes_equals %w(2 8 15), '02/03 8:15', :chronic_options => { :endian_precedence => :little }
|
210
|
+
|
211
|
+
assert_days_and_hours_and_minutes_equals %w(4 4 50), '03/04 4:50', :chronic_options => { :endian_precedence => :middle, :hours24 => true }
|
212
|
+
assert_days_and_hours_and_minutes_equals %w(4 16 50), '03/04 4:50', :chronic_options => { :endian_precedence => :middle, :hours24 => false }
|
213
|
+
assert_days_and_hours_and_minutes_equals %w(3 4 50), '03/04 4:50', :chronic_options => { :endian_precedence => :little, :hours24 => true }
|
214
|
+
assert_days_and_hours_and_minutes_equals %w(3 16 50), '03/04 4:50', :chronic_options => { :endian_precedence => :little, :hours24 => false }
|
215
|
+
end
|
216
|
+
|
135
217
|
should "parse correctly when given an 'at' with days as an Integer" do
|
136
218
|
# first param is an array with [days, hours, minutes]
|
137
219
|
assert_days_and_hours_and_minutes_equals %w(1 0 0), 1
|
138
220
|
assert_days_and_hours_and_minutes_equals %w(15 0 0), 15
|
139
221
|
assert_days_and_hours_and_minutes_equals %w(29 0 0), 29
|
140
222
|
end
|
223
|
+
|
224
|
+
should "parse correctly when given an 'at' with days as a Range" do
|
225
|
+
assert_days_and_hours_and_minutes_equals %w(1-7 0 0), 1..7
|
226
|
+
end
|
227
|
+
|
228
|
+
should "raise an exception when given an 'at' with an invalid day value" do
|
229
|
+
assert_raises ArgumentError do
|
230
|
+
parse_time(Whenever.seconds(1, :month), nil, 32)
|
231
|
+
end
|
232
|
+
|
233
|
+
assert_raises ArgumentError do
|
234
|
+
parse_time(Whenever.seconds(1, :month), nil, -1)
|
235
|
+
end
|
236
|
+
|
237
|
+
assert_raises ArgumentError do
|
238
|
+
parse_time(Whenever.seconds(1, :month), nil, 0..30)
|
239
|
+
end
|
240
|
+
|
241
|
+
assert_raises ArgumentError do
|
242
|
+
parse_time(Whenever.seconds(1, :month), nil, 1..32)
|
243
|
+
end
|
244
|
+
end
|
245
|
+
end
|
246
|
+
|
247
|
+
class CronParseYearTest < Whenever::TestCase
|
248
|
+
should "parse correctly" do
|
249
|
+
assert_equal '0 0 1 1 *', parse_time(Whenever.seconds(1, :year))
|
250
|
+
end
|
251
|
+
|
252
|
+
should "parse year with a date and/or time" do
|
253
|
+
# should set the day and month to 1 if no date is given
|
254
|
+
assert_equal '0 17 1 1 *', parse_time(Whenever.seconds(1, :year), nil, "5pm")
|
255
|
+
# should use the date if one is given
|
256
|
+
assert_equal '0 2 23 2 *', parse_time(Whenever.seconds(1, :year), nil, "February 23rd at 2am")
|
257
|
+
# should use an iteger as the month
|
258
|
+
assert_equal '0 0 1 5 *', parse_time(Whenever.seconds(1, :year), nil, 5)
|
259
|
+
end
|
260
|
+
|
261
|
+
should "parse correctly when given an 'at' with days, hours, minutes as a Time" do
|
262
|
+
# first param is an array with [months, days, hours, minutes]
|
263
|
+
assert_months_and_days_and_hours_and_minutes_equals %w(1 1 3 45), 'January 1st 3:45am'
|
264
|
+
assert_months_and_days_and_hours_and_minutes_equals %w(2 11 23 0), 'Feb 11 11PM'
|
265
|
+
assert_months_and_days_and_hours_and_minutes_equals %w(3 22 1 1), 'march 22nd at 1:01 am'
|
266
|
+
assert_months_and_days_and_hours_and_minutes_equals %w(3 23 0 0), 'march 22nd at midnight' # looks like midnight means the next day
|
267
|
+
end
|
268
|
+
|
269
|
+
should "parse correctly when given an 'at' with days, hours, minutes as a Time and custom Chronic options are set" do
|
270
|
+
# first param is an array with [months, days, hours, minutes]
|
271
|
+
assert_months_and_days_and_hours_and_minutes_equals %w(2 22 15 45), 'February 22nd 3:45'
|
272
|
+
assert_months_and_days_and_hours_and_minutes_equals %w(2 22 15 45), '02/22 3:45'
|
273
|
+
assert_months_and_days_and_hours_and_minutes_equals %w(2 22 3 45), 'February 22nd 3:45', :chronic_options => { :hours24 => true }
|
274
|
+
assert_months_and_days_and_hours_and_minutes_equals %w(2 22 15 45), 'February 22nd 3:45', :chronic_options => { :hours24 => false }
|
275
|
+
|
276
|
+
assert_months_and_days_and_hours_and_minutes_equals %w(2 3 8 15), '02/03 8:15'
|
277
|
+
assert_months_and_days_and_hours_and_minutes_equals %w(2 3 8 15), '02/03 8:15', :chronic_options => { :endian_precedence => :middle }
|
278
|
+
assert_months_and_days_and_hours_and_minutes_equals %w(3 2 8 15), '02/03 8:15', :chronic_options => { :endian_precedence => :little }
|
279
|
+
|
280
|
+
assert_months_and_days_and_hours_and_minutes_equals %w(3 4 4 50), '03/04 4:50', :chronic_options => { :endian_precedence => :middle, :hours24 => true }
|
281
|
+
assert_months_and_days_and_hours_and_minutes_equals %w(3 4 16 50), '03/04 4:50', :chronic_options => { :endian_precedence => :middle, :hours24 => false }
|
282
|
+
assert_months_and_days_and_hours_and_minutes_equals %w(4 3 4 50), '03/04 4:50', :chronic_options => { :endian_precedence => :little, :hours24 => true }
|
283
|
+
assert_months_and_days_and_hours_and_minutes_equals %w(4 3 16 50), '03/04 4:50', :chronic_options => { :endian_precedence => :little, :hours24 => false }
|
284
|
+
end
|
285
|
+
|
286
|
+
should "parse correctly when given an 'at' with month as an Integer" do
|
287
|
+
# first param is an array with [months, days, hours, minutes]
|
288
|
+
assert_months_and_days_and_hours_and_minutes_equals %w(1 1 0 0), 1
|
289
|
+
assert_months_and_days_and_hours_and_minutes_equals %w(5 1 0 0), 5
|
290
|
+
assert_months_and_days_and_hours_and_minutes_equals %w(12 1 0 0), 12
|
291
|
+
end
|
292
|
+
|
293
|
+
should "parse correctly when given an 'at' with month as a Range" do
|
294
|
+
assert_months_and_days_and_hours_and_minutes_equals %w(1-3 1 0 0), 1..3
|
295
|
+
end
|
296
|
+
|
297
|
+
should "raise an exception when given an 'at' with an invalid month value" do
|
298
|
+
assert_raises ArgumentError do
|
299
|
+
parse_time(Whenever.seconds(1, :year), nil, 13)
|
300
|
+
end
|
301
|
+
|
302
|
+
assert_raises ArgumentError do
|
303
|
+
parse_time(Whenever.seconds(1, :year), nil, -1)
|
304
|
+
end
|
305
|
+
|
306
|
+
assert_raises ArgumentError do
|
307
|
+
parse_time(Whenever.seconds(1, :year), nil, 0..12)
|
308
|
+
end
|
309
|
+
|
310
|
+
assert_raises ArgumentError do
|
311
|
+
parse_time(Whenever.seconds(1, :year), nil, 1..13)
|
312
|
+
end
|
313
|
+
end
|
141
314
|
end
|
142
315
|
|
143
316
|
class CronParseDaysOfWeekTest < Whenever::TestCase
|
@@ -191,10 +364,10 @@ class CronParseShortcutsTest < Whenever::TestCase
|
|
191
364
|
end
|
192
365
|
|
193
366
|
should "convert time-based shortcuts to times" do
|
194
|
-
assert_equal '0 0 1 * *',
|
195
|
-
assert_equal '0 0 * * *',
|
196
|
-
assert_equal '0 * * * *',
|
197
|
-
assert_equal '0 0 1
|
367
|
+
assert_equal '0 0 1 * *', parse_time(:month)
|
368
|
+
assert_equal '0 0 * * *', parse_time(:day)
|
369
|
+
assert_equal '0 * * * *', parse_time(:hour)
|
370
|
+
assert_equal '0 0 1 1 *', parse_time(:year)
|
198
371
|
assert_equal '0 0 1,8,15,22 * *', parse_time(:week)
|
199
372
|
end
|
200
373
|
|
@@ -235,6 +408,7 @@ class CronParseRawTest < Whenever::TestCase
|
|
235
408
|
should "return the same cron sytax" do
|
236
409
|
crons = ['0 0 27-31 * *', '* * * * *', '2/3 1,9,22 11-26 1-6 *', '*/5 6-23 * * *',
|
237
410
|
"*\t*\t*\t*\t*",
|
411
|
+
'7 17 * * FRI', '7 17 * * Mon-Fri', '30 12 * Jun *', '30 12 * Jun-Aug *',
|
238
412
|
'@reboot', '@yearly', '@annually', '@monthly', '@weekly',
|
239
413
|
'@daily', '@midnight', '@hourly']
|
240
414
|
crons.each do |cron|
|
@@ -0,0 +1,142 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
describe 'Executable' do
|
4
|
+
describe 'bin/wheneverize' do
|
5
|
+
describe 'ARGV is not empty' do
|
6
|
+
describe 'file does not exist' do
|
7
|
+
file = '/tmp/this_does_not_exist'
|
8
|
+
|
9
|
+
it 'prints STDERR' do
|
10
|
+
out, err = capture_subprocess_io do
|
11
|
+
system('wheneverize', file)
|
12
|
+
end
|
13
|
+
|
14
|
+
assert_empty(out)
|
15
|
+
assert_match(/`#{file}' does not exist./, err)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe 'file exists, but not a directory' do
|
20
|
+
file = '/tmp/this_is_a_file.txt'
|
21
|
+
before { FileUtils.touch(file) }
|
22
|
+
|
23
|
+
it 'prints STDERR' do
|
24
|
+
begin
|
25
|
+
out, err = capture_subprocess_io do
|
26
|
+
system('wheneverize', file)
|
27
|
+
end
|
28
|
+
|
29
|
+
assert_empty(out)
|
30
|
+
assert_match(/`#{file}' is not a directory./, err)
|
31
|
+
ensure
|
32
|
+
FileUtils.rm(file)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
describe 'file is a directory, but another param(s) are given as well' do
|
38
|
+
file = '/tmp/this_is_a_directory'
|
39
|
+
before { FileUtils.mkdir(file) }
|
40
|
+
|
41
|
+
it 'prints STDERR' do
|
42
|
+
begin
|
43
|
+
out, err = capture_subprocess_io do
|
44
|
+
system('wheneverize', file, 'another', 'parameters')
|
45
|
+
end
|
46
|
+
|
47
|
+
assert_empty(out)
|
48
|
+
assert_match(/#{"Too many arguments; please specify only the " \
|
49
|
+
"directory to wheneverize."}/, err)
|
50
|
+
ensure
|
51
|
+
FileUtils.rmdir(file)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
describe 'ARGV is empty' do
|
58
|
+
dir = '.'
|
59
|
+
file = 'config/schedule.rb'
|
60
|
+
path = File.join(dir, file)
|
61
|
+
|
62
|
+
describe 'config file already exists' do
|
63
|
+
before do
|
64
|
+
FileUtils.mkdir(File.dirname(path))
|
65
|
+
FileUtils.touch(path)
|
66
|
+
end
|
67
|
+
|
68
|
+
it 'prints STDOUT and STDERR' do
|
69
|
+
begin
|
70
|
+
out, err = capture_subprocess_io do
|
71
|
+
system('wheneverize')
|
72
|
+
end
|
73
|
+
|
74
|
+
assert_match(/\[done\] wheneverized!/, out)
|
75
|
+
assert_match(/\[skip\] `#{path}' already exists/, err)
|
76
|
+
ensure
|
77
|
+
FileUtils.rm_rf(File.dirname(path))
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
describe 'config directory does not exist' do
|
83
|
+
it 'prints STDOUT and STDERR' do
|
84
|
+
begin
|
85
|
+
out, err = capture_subprocess_io do
|
86
|
+
system('wheneverize')
|
87
|
+
end
|
88
|
+
|
89
|
+
assert_match(/\[add\] creating `#{File.dirname(path)}'\n/, err)
|
90
|
+
assert_match(/\[done\] wheneverized!/, out)
|
91
|
+
ensure
|
92
|
+
FileUtils.rm_rf(File.dirname(path))
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
describe 'config directory exists, but file does not' do
|
98
|
+
before { FileUtils.mkdir(File.dirname(path)) }
|
99
|
+
|
100
|
+
it 'writes config file and prints STDOUT' do
|
101
|
+
begin
|
102
|
+
out, err = capture_subprocess_io do
|
103
|
+
system('wheneverize')
|
104
|
+
end
|
105
|
+
|
106
|
+
assert_empty(err)
|
107
|
+
assert_match(
|
108
|
+
/\[add\] writing `#{path}'\n\[done\] wheneverized!/,
|
109
|
+
out
|
110
|
+
)
|
111
|
+
|
112
|
+
assert_match((<<-FILE
|
113
|
+
# Use this file to easily define all of your cron jobs.
|
114
|
+
#
|
115
|
+
# It's helpful, but not entirely necessary to understand cron before proceeding.
|
116
|
+
# http://en.wikipedia.org/wiki/Cron
|
117
|
+
|
118
|
+
# Example:
|
119
|
+
#
|
120
|
+
# set :output, "/path/to/my/cron_log.log"
|
121
|
+
#
|
122
|
+
# every 2.hours do
|
123
|
+
# command "/usr/bin/some_great_command"
|
124
|
+
# runner "MyModel.some_method"
|
125
|
+
# rake "some:great:rake:task"
|
126
|
+
# end
|
127
|
+
#
|
128
|
+
# every 4.days do
|
129
|
+
# runner "AnotherModel.prune_old_records"
|
130
|
+
# end
|
131
|
+
|
132
|
+
# Learn more: http://github.com/javan/whenever
|
133
|
+
FILE
|
134
|
+
), IO.read(path))
|
135
|
+
ensure
|
136
|
+
FileUtils.rm_rf(File.dirname(path))
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
data/whenever.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: whenever
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Javan Makhmali
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-06-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: chronic
|
@@ -80,6 +80,20 @@ dependencies:
|
|
80
80
|
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: appraisal
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
83
97
|
description: Clean ruby syntax for writing and deploying cron jobs.
|
84
98
|
email:
|
85
99
|
- javan@javan.us
|
@@ -91,6 +105,7 @@ extra_rdoc_files: []
|
|
91
105
|
files:
|
92
106
|
- ".gitignore"
|
93
107
|
- ".travis.yml"
|
108
|
+
- Appraisals
|
94
109
|
- CHANGELOG.md
|
95
110
|
- Gemfile
|
96
111
|
- LICENSE
|
@@ -100,6 +115,9 @@ files:
|
|
100
115
|
- bin/wheneverize
|
101
116
|
- gemfiles/activesupport4.1.gemfile
|
102
117
|
- gemfiles/activesupport4.2.gemfile
|
118
|
+
- gemfiles/activesupport5.0.gemfile
|
119
|
+
- gemfiles/activesupport5.1.gemfile
|
120
|
+
- gemfiles/activesupport5.2.gemfile
|
103
121
|
- lib/whenever.rb
|
104
122
|
- lib/whenever/capistrano.rb
|
105
123
|
- lib/whenever/capistrano/v2/hooks.rb
|
@@ -122,11 +140,13 @@ files:
|
|
122
140
|
- test/functional/output_defined_job_test.rb
|
123
141
|
- test/functional/output_env_test.rb
|
124
142
|
- test/functional/output_jobs_for_roles_test.rb
|
143
|
+
- test/functional/output_jobs_with_mailto_test.rb
|
125
144
|
- test/functional/output_redirection_test.rb
|
126
145
|
- test/test_case.rb
|
127
146
|
- test/test_helper.rb
|
128
147
|
- test/unit/capistrano_support_test.rb
|
129
148
|
- test/unit/cron_test.rb
|
149
|
+
- test/unit/executable_test.rb
|
130
150
|
- test/unit/job_test.rb
|
131
151
|
- whenever.gemspec
|
132
152
|
homepage: https://github.com/javan/whenever
|
@@ -149,7 +169,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
149
169
|
version: '0'
|
150
170
|
requirements: []
|
151
171
|
rubyforge_project:
|
152
|
-
rubygems_version: 2.
|
172
|
+
rubygems_version: 2.7.3
|
153
173
|
signing_key:
|
154
174
|
specification_version: 4
|
155
175
|
summary: Cron jobs in ruby.
|
@@ -160,7 +180,9 @@ test_files:
|
|
160
180
|
- test/functional/output_defined_job_test.rb
|
161
181
|
- test/functional/output_env_test.rb
|
162
182
|
- test/functional/output_jobs_for_roles_test.rb
|
183
|
+
- test/functional/output_jobs_with_mailto_test.rb
|
163
184
|
- test/functional/output_redirection_test.rb
|
164
185
|
- test/unit/capistrano_support_test.rb
|
165
186
|
- test/unit/cron_test.rb
|
187
|
+
- test/unit/executable_test.rb
|
166
188
|
- test/unit/job_test.rb
|