whenever 0.6.1 → 0.7.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.
- data/.gitignore +1 -0
- data/.travis.yml +5 -0
- data/{CHANGELOG.rdoc → CHANGELOG.md} +76 -18
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +165 -0
- data/Rakefile +10 -28
- data/bin/whenever +2 -2
- data/bin/wheneverize +9 -10
- data/lib/whenever/capistrano.rb +48 -17
- data/lib/whenever/command_line.rb +18 -10
- data/lib/whenever/cron.rb +27 -12
- data/lib/whenever/job.rb +0 -2
- data/lib/whenever/job_list.rb +11 -17
- data/lib/whenever/output_redirection.rb +0 -2
- data/lib/whenever/setup.rb +24 -0
- data/lib/whenever/version.rb +2 -2
- data/lib/whenever.rb +27 -7
- data/test/functional/command_line_test.rb +22 -30
- data/test/functional/output_at_test.rb +20 -3
- data/test/functional/output_default_defined_jobs_test.rb +39 -2
- data/test/functional/output_env_test.rb +11 -1
- data/test/test_helper.rb +0 -2
- data/test/unit/cron_test.rb +21 -6
- data/whenever.gemspec +26 -81
- metadata +87 -95
- data/README.rdoc +0 -139
- data/lib/whenever/base.rb +0 -11
- data/lib/whenever/job_types/default.rb +0 -11
data/lib/whenever/cron.rb
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
module Whenever
|
|
2
2
|
module Output
|
|
3
3
|
class Cron
|
|
4
|
+
REGEX = /^.+ .+ .+ .+ .+.?$/
|
|
4
5
|
|
|
5
6
|
attr_accessor :time, :task
|
|
6
7
|
|
|
@@ -10,9 +11,14 @@ module Whenever
|
|
|
10
11
|
@at = at.is_a?(String) ? (Chronic.parse(at) || 0) : (at || 0)
|
|
11
12
|
end
|
|
12
13
|
|
|
13
|
-
def self.enumerate(item)
|
|
14
|
+
def self.enumerate(item, detect_cron = true)
|
|
14
15
|
if item and item.is_a?(String)
|
|
15
|
-
items =
|
|
16
|
+
items =
|
|
17
|
+
if detect_cron && item =~ REGEX
|
|
18
|
+
[item]
|
|
19
|
+
else
|
|
20
|
+
item.split(',')
|
|
21
|
+
end
|
|
16
22
|
else
|
|
17
23
|
items = item
|
|
18
24
|
items = [items] unless items and items.respond_to?(:each)
|
|
@@ -22,7 +28,7 @@ module Whenever
|
|
|
22
28
|
|
|
23
29
|
def self.output(times, job)
|
|
24
30
|
enumerate(times).each do |time|
|
|
25
|
-
enumerate(job.at).each do |at|
|
|
31
|
+
enumerate(job.at, false).each do |at|
|
|
26
32
|
yield new(time, job.output, at).output
|
|
27
33
|
end
|
|
28
34
|
end
|
|
@@ -34,6 +40,7 @@ module Whenever
|
|
|
34
40
|
|
|
35
41
|
def time_in_cron_syntax
|
|
36
42
|
case @time
|
|
43
|
+
when REGEX then @time # raw cron sytax given
|
|
37
44
|
when Symbol then parse_symbol
|
|
38
45
|
when String then parse_as_string
|
|
39
46
|
else parse_time
|
|
@@ -44,16 +51,25 @@ module Whenever
|
|
|
44
51
|
|
|
45
52
|
def parse_symbol
|
|
46
53
|
shortcut = case @time
|
|
47
|
-
when :reboot
|
|
48
|
-
when :year
|
|
49
|
-
when :
|
|
50
|
-
|
|
51
|
-
when :
|
|
52
|
-
when :
|
|
53
|
-
when :
|
|
54
|
+
when :reboot then '@reboot'
|
|
55
|
+
when :year then 12.months
|
|
56
|
+
when :yearly,
|
|
57
|
+
:annually then '@annually'
|
|
58
|
+
when :day then 1.day
|
|
59
|
+
when :daily then '@daily'
|
|
60
|
+
when :midnight then '@midnight'
|
|
61
|
+
when :month then 1.month
|
|
62
|
+
when :monthly then '@monthly'
|
|
63
|
+
when :week then 1.week
|
|
64
|
+
when :weekly then '@weekly'
|
|
65
|
+
when :hour then 1.hour
|
|
66
|
+
when :hourly then '@hourly'
|
|
54
67
|
end
|
|
55
68
|
|
|
56
|
-
if shortcut
|
|
69
|
+
if shortcut.is_a?(Numeric)
|
|
70
|
+
@time = shortcut
|
|
71
|
+
parse_time
|
|
72
|
+
elsif shortcut
|
|
57
73
|
if @at.is_a?(Time) || (@at.is_a?(Numeric) && @at > 0)
|
|
58
74
|
raise ArgumentError, "You cannot specify an ':at' when using the shortcuts for times."
|
|
59
75
|
else
|
|
@@ -126,7 +142,6 @@ module Whenever
|
|
|
126
142
|
|
|
127
143
|
output[0, max_occurances].join(',')
|
|
128
144
|
end
|
|
129
|
-
|
|
130
145
|
end
|
|
131
146
|
end
|
|
132
147
|
end
|
data/lib/whenever/job.rb
CHANGED
data/lib/whenever/job_list.rb
CHANGED
|
@@ -1,27 +1,22 @@
|
|
|
1
1
|
module Whenever
|
|
2
2
|
class JobList
|
|
3
|
-
|
|
4
3
|
def initialize(options)
|
|
5
4
|
@jobs, @env, @set_variables, @pre_set_variables = {}, {}, {}, {}
|
|
6
5
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
config = options
|
|
10
|
-
when Hash
|
|
11
|
-
config = if options[:string]
|
|
12
|
-
options[:string]
|
|
13
|
-
elsif options[:file]
|
|
14
|
-
File.read(options[:file])
|
|
15
|
-
end
|
|
16
|
-
pre_set(options[:set])
|
|
6
|
+
if options.is_a? String
|
|
7
|
+
options = { :string => options }
|
|
17
8
|
end
|
|
9
|
+
|
|
10
|
+
pre_set(options[:set])
|
|
18
11
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
12
|
+
setup = File.read("#{File.expand_path(File.dirname(__FILE__))}/setup.rb")
|
|
13
|
+
schedule = if options[:string]
|
|
14
|
+
options[:string]
|
|
15
|
+
elsif options[:file]
|
|
16
|
+
File.read(options[:file])
|
|
22
17
|
end
|
|
23
18
|
|
|
24
|
-
eval
|
|
19
|
+
instance_eval(setup + schedule, options[:file] || '<eval>')
|
|
25
20
|
end
|
|
26
21
|
|
|
27
22
|
def set(variable, value)
|
|
@@ -91,7 +86,7 @@ module Whenever
|
|
|
91
86
|
|
|
92
87
|
output = []
|
|
93
88
|
@env.each do |key, val|
|
|
94
|
-
output << "#{key}=#{val}\n"
|
|
89
|
+
output << "#{key}=#{val.blank? ? '""' : val}\n"
|
|
95
90
|
end
|
|
96
91
|
output << "\n"
|
|
97
92
|
|
|
@@ -146,6 +141,5 @@ module Whenever
|
|
|
146
141
|
|
|
147
142
|
shortcut_jobs.join + combine(regular_jobs).join
|
|
148
143
|
end
|
|
149
|
-
|
|
150
144
|
end
|
|
151
145
|
end
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# Environment defaults to production
|
|
2
|
+
set :environment, "production"
|
|
3
|
+
# Path defaults to the directory `whenever` was run from
|
|
4
|
+
set :path, Whenever.path
|
|
5
|
+
|
|
6
|
+
# All jobs are wrapped in this template.
|
|
7
|
+
# http://blog.scoutapp.com/articles/2010/09/07/rvm-and-cron-in-production
|
|
8
|
+
set :job_template, "/bin/bash -l -c ':job'"
|
|
9
|
+
|
|
10
|
+
job_type :command, ":task :output"
|
|
11
|
+
|
|
12
|
+
# Run rake through bundler if possible
|
|
13
|
+
if Whenever.bundler?
|
|
14
|
+
job_type :rake, "cd :path && RAILS_ENV=:environment bundle exec rake :task --silent :output"
|
|
15
|
+
else
|
|
16
|
+
job_type :rake, "cd :path && RAILS_ENV=:environment rake :task --silent :output"
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
# Create a runner job that's appropriate for the Rails version,
|
|
20
|
+
if Whenever.rails3?
|
|
21
|
+
job_type :runner, "cd :path && script/rails runner -e :environment ':task' :output"
|
|
22
|
+
else
|
|
23
|
+
job_type :runner, "cd :path && script/runner -e :environment ':task' :output"
|
|
24
|
+
end
|
data/lib/whenever/version.rb
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
module Whenever
|
|
2
|
-
VERSION = '0.
|
|
3
|
-
end
|
|
2
|
+
VERSION = '0.7.0'
|
|
3
|
+
end
|
data/lib/whenever.rb
CHANGED
|
@@ -1,10 +1,30 @@
|
|
|
1
1
|
require 'chronic'
|
|
2
2
|
require 'active_support/all'
|
|
3
|
+
require 'thread'
|
|
3
4
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
5
|
+
module Whenever
|
|
6
|
+
autoload :JobList, 'whenever/job_list'
|
|
7
|
+
autoload :Job, 'whenever/job'
|
|
8
|
+
autoload :CommandLine, 'whenever/command_line'
|
|
9
|
+
|
|
10
|
+
module Output
|
|
11
|
+
autoload :Cron, 'whenever/cron'
|
|
12
|
+
autoload :Redirection, 'whenever/output_redirection'
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def self.cron(options)
|
|
16
|
+
Whenever::JobList.new(options).generate_cron_output
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def self.path
|
|
20
|
+
Dir.pwd
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def self.rails3?
|
|
24
|
+
File.exists?(File.join(path, 'script', 'rails'))
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def self.bundler?
|
|
28
|
+
File.exists?(File.join(path, 'Gemfile'))
|
|
29
|
+
end
|
|
30
|
+
end
|
|
@@ -120,35 +120,18 @@ NEW_CRON
|
|
|
120
120
|
end
|
|
121
121
|
|
|
122
122
|
should "append the similarly named command" do
|
|
123
|
-
assert_equal @existing + "\n
|
|
123
|
+
assert_equal @existing + "\n" + @new, @command.send(:updated_crontab)
|
|
124
124
|
end
|
|
125
125
|
end
|
|
126
126
|
|
|
127
|
-
context "A command line
|
|
127
|
+
context "A command line clear" do
|
|
128
128
|
setup do
|
|
129
129
|
File.expects(:exists?).with('config/schedule.rb').returns(true)
|
|
130
130
|
@command = Whenever::CommandLine.new(:clear => true, :identifier => 'My identifier')
|
|
131
131
|
@task = "#{two_hours} /my/command"
|
|
132
132
|
end
|
|
133
133
|
|
|
134
|
-
should "
|
|
135
|
-
existing = '# Existing crontab'
|
|
136
|
-
@command.expects(:read_crontab).at_least_once.returns(existing)
|
|
137
|
-
|
|
138
|
-
new_cron = <<-EXPECTED
|
|
139
|
-
#{existing}
|
|
140
|
-
|
|
141
|
-
# Begin Whenever generated tasks for: My identifier
|
|
142
|
-
# End Whenever generated tasks for: My identifier
|
|
143
|
-
EXPECTED
|
|
144
|
-
|
|
145
|
-
assert_equal new_cron, @command.send(:updated_crontab)
|
|
146
|
-
|
|
147
|
-
@command.expects(:write_crontab).with(new_cron).returns(true)
|
|
148
|
-
assert @command.run
|
|
149
|
-
end
|
|
150
|
-
|
|
151
|
-
should "delete an existing block if the identifier matches" do
|
|
134
|
+
should "clear an existing block if the identifier matches" do
|
|
152
135
|
existing = <<-EXISTING_CRON
|
|
153
136
|
# Something
|
|
154
137
|
|
|
@@ -162,20 +145,17 @@ This shouldn't get replaced
|
|
|
162
145
|
EXISTING_CRON
|
|
163
146
|
|
|
164
147
|
@command.expects(:read_crontab).at_least_once.returns(existing)
|
|
165
|
-
|
|
148
|
+
|
|
166
149
|
new_cron = <<-NEW_CRON
|
|
167
150
|
# Something
|
|
168
151
|
|
|
169
|
-
# Begin Whenever generated tasks for: My identifier
|
|
170
|
-
# End Whenever generated tasks for: My identifier
|
|
171
|
-
|
|
172
152
|
# Begin Whenever generated tasks for: Other identifier
|
|
173
153
|
This shouldn't get replaced
|
|
174
154
|
# End Whenever generated tasks for: Other identifier
|
|
175
155
|
NEW_CRON
|
|
176
|
-
|
|
156
|
+
|
|
177
157
|
assert_equal new_cron, @command.send(:updated_crontab)
|
|
178
|
-
|
|
158
|
+
|
|
179
159
|
@command.expects(:write_crontab).with(new_cron).returns(true)
|
|
180
160
|
assert @command.run
|
|
181
161
|
end
|
|
@@ -301,8 +281,7 @@ My whenever job that was already here
|
|
|
301
281
|
# End Whenever generated tasks for: My identifier
|
|
302
282
|
EXISTING_CRON
|
|
303
283
|
|
|
304
|
-
|
|
305
|
-
assert_equal existing.strip, @command.send(:prepare, existing)
|
|
284
|
+
assert_equal existing, @command.send(:prepare, existing)
|
|
306
285
|
end
|
|
307
286
|
|
|
308
287
|
should "trim off the top lines of the file" do
|
|
@@ -322,8 +301,21 @@ My whenever job that was already here
|
|
|
322
301
|
# End Whenever generated tasks for: My identifier
|
|
323
302
|
NEW_CRON
|
|
324
303
|
|
|
325
|
-
|
|
326
|
-
|
|
304
|
+
assert_equal new_cron, @command.send(:prepare, existing)
|
|
305
|
+
end
|
|
306
|
+
|
|
307
|
+
should "preserve terminating newlines in files" do
|
|
308
|
+
@command = Whenever::CommandLine.new(:update => true, :identifier => 'My identifier')
|
|
309
|
+
existing = <<-EXISTING_CRON
|
|
310
|
+
# Begin Whenever generated tasks for: My identifier
|
|
311
|
+
My whenever job that was already here
|
|
312
|
+
# End Whenever generated tasks for: My identifier
|
|
313
|
+
|
|
314
|
+
# A non-Whenever task
|
|
315
|
+
My non-whenever job that was already here
|
|
316
|
+
EXISTING_CRON
|
|
317
|
+
|
|
318
|
+
assert_equal existing, @command.send(:prepare, existing)
|
|
327
319
|
end
|
|
328
320
|
end
|
|
329
321
|
|
|
@@ -114,7 +114,7 @@ class OutputAtTest < Test::Unit::TestCase
|
|
|
114
114
|
end
|
|
115
115
|
|
|
116
116
|
should "output the rake task using one entry because the times are aligned" do
|
|
117
|
-
assert_match '2 5,15 * * 1,3,5 cd /your/path && RAILS_ENV=production rake blah:blah --silent', @output
|
|
117
|
+
assert_match '2 5,15 * * 1,3,5 cd /your/path && RAILS_ENV=production bundle exec rake blah:blah --silent', @output
|
|
118
118
|
end
|
|
119
119
|
end
|
|
120
120
|
|
|
@@ -166,7 +166,7 @@ class OutputAtTest < Test::Unit::TestCase
|
|
|
166
166
|
<<-file
|
|
167
167
|
set :job_template, nil
|
|
168
168
|
set :path, '/your/path'
|
|
169
|
-
every :
|
|
169
|
+
every :daily do
|
|
170
170
|
rake "blah:blah"
|
|
171
171
|
runner "runner_1"
|
|
172
172
|
command "command_1"
|
|
@@ -177,7 +177,7 @@ class OutputAtTest < Test::Unit::TestCase
|
|
|
177
177
|
end
|
|
178
178
|
|
|
179
179
|
should "output all of the commands @daily" do
|
|
180
|
-
assert_match '@daily cd /your/path && RAILS_ENV=production rake blah:blah --silent', @output
|
|
180
|
+
assert_match '@daily cd /your/path && RAILS_ENV=production bundle exec rake blah:blah --silent', @output
|
|
181
181
|
assert_match %(@daily cd /your/path && script/runner -e production 'runner_1'), @output
|
|
182
182
|
assert_match '@daily command_1', @output
|
|
183
183
|
assert_match %(@daily cd /your/path && script/runner -e production 'runner_2'), @output
|
|
@@ -248,4 +248,21 @@ class OutputAtTest < Test::Unit::TestCase
|
|
|
248
248
|
assert_match '27,29,31,33,35,37,39,41,43,45,47,49,51,53,55,57,59 * * * * blahblah', @output
|
|
249
249
|
end
|
|
250
250
|
end
|
|
251
|
+
|
|
252
|
+
context "using raw cron syntax" do
|
|
253
|
+
setup do
|
|
254
|
+
@output = Whenever.cron \
|
|
255
|
+
<<-file
|
|
256
|
+
set :job_template, nil
|
|
257
|
+
every '0 0 27,31 * *' do
|
|
258
|
+
command "blahblah"
|
|
259
|
+
end
|
|
260
|
+
file
|
|
261
|
+
end
|
|
262
|
+
|
|
263
|
+
should "output the command using the same cron syntax" do
|
|
264
|
+
assert_match '0 0 27,31 * * blahblah', @output
|
|
265
|
+
end
|
|
266
|
+
end
|
|
267
|
+
|
|
251
268
|
end
|
|
@@ -51,6 +51,25 @@ class OutputDefaultDefinedJobsTest < Test::Unit::TestCase
|
|
|
51
51
|
assert_no_match /bash/, @output
|
|
52
52
|
end
|
|
53
53
|
end
|
|
54
|
+
|
|
55
|
+
context "A plain command that is conditional on default environent and path" do
|
|
56
|
+
setup do
|
|
57
|
+
Whenever.expects(:path).at_least_once.returns('/what/you/want')
|
|
58
|
+
@output = Whenever.cron \
|
|
59
|
+
<<-file
|
|
60
|
+
set :job_template, nil
|
|
61
|
+
if environment == 'production' && path == '/what/you/want'
|
|
62
|
+
every 2.hours do
|
|
63
|
+
command "blahblah"
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
file
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
should "output the command" do
|
|
70
|
+
assert_match /blahblah/, @output
|
|
71
|
+
end
|
|
72
|
+
end
|
|
54
73
|
|
|
55
74
|
# runner
|
|
56
75
|
|
|
@@ -91,7 +110,7 @@ class OutputDefaultDefinedJobsTest < Test::Unit::TestCase
|
|
|
91
110
|
context "A runner for a Rails 3 app" do
|
|
92
111
|
setup do
|
|
93
112
|
Whenever.expects(:path).at_least_once.returns('/my/path')
|
|
94
|
-
|
|
113
|
+
Whenever.expects(:rails3?).returns(true)
|
|
95
114
|
@output = Whenever.cron \
|
|
96
115
|
<<-file
|
|
97
116
|
set :job_template, nil
|
|
@@ -121,6 +140,24 @@ class OutputDefaultDefinedJobsTest < Test::Unit::TestCase
|
|
|
121
140
|
end
|
|
122
141
|
|
|
123
142
|
should "output the rake command using that path" do
|
|
143
|
+
assert_match two_hours + ' cd /my/path && RAILS_ENV=production bundle exec rake blahblah --silent', @output
|
|
144
|
+
end
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
context "A rake for a non-bundler app" do
|
|
148
|
+
setup do
|
|
149
|
+
Whenever.expects(:path).at_least_once.returns('/my/path')
|
|
150
|
+
Whenever.expects(:bundler?).returns(false)
|
|
151
|
+
@output = Whenever.cron \
|
|
152
|
+
<<-file
|
|
153
|
+
set :job_template, nil
|
|
154
|
+
every 2.hours do
|
|
155
|
+
rake 'blahblah'
|
|
156
|
+
end
|
|
157
|
+
file
|
|
158
|
+
end
|
|
159
|
+
|
|
160
|
+
should "not use invoke through bundler" do
|
|
124
161
|
assert_match two_hours + ' cd /my/path && RAILS_ENV=production rake blahblah --silent', @output
|
|
125
162
|
end
|
|
126
163
|
end
|
|
@@ -138,7 +175,7 @@ class OutputDefaultDefinedJobsTest < Test::Unit::TestCase
|
|
|
138
175
|
end
|
|
139
176
|
|
|
140
177
|
should "output the rake command using that path" do
|
|
141
|
-
assert_match two_hours + ' cd /some/other/path && RAILS_ENV=production rake blahblah --silent', @output
|
|
178
|
+
assert_match two_hours + ' cd /some/other/path && RAILS_ENV=production bundle exec rake blahblah --silent', @output
|
|
142
179
|
end
|
|
143
180
|
end
|
|
144
181
|
|
|
@@ -8,6 +8,8 @@ class OutputEnvTest < Test::Unit::TestCase
|
|
|
8
8
|
<<-file
|
|
9
9
|
env :MYVAR, 'blah'
|
|
10
10
|
env 'MAILTO', "someone@example.com"
|
|
11
|
+
env :BLANKVAR, ''
|
|
12
|
+
env :NILVAR, nil
|
|
11
13
|
file
|
|
12
14
|
end
|
|
13
15
|
|
|
@@ -18,6 +20,14 @@ class OutputEnvTest < Test::Unit::TestCase
|
|
|
18
20
|
should "output MAILTO environment variable" do
|
|
19
21
|
assert_match "MAILTO=someone@example.com", @output
|
|
20
22
|
end
|
|
23
|
+
|
|
24
|
+
should "output BLANKVAR environment variable" do
|
|
25
|
+
assert_match "BLANKVAR=\"\"", @output
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
should "output NILVAR environment variable" do
|
|
29
|
+
assert_match "NILVAR=\"\"", @output
|
|
30
|
+
end
|
|
21
31
|
end
|
|
22
32
|
|
|
23
|
-
end
|
|
33
|
+
end
|
data/test/test_helper.rb
CHANGED
data/test/unit/cron_test.rb
CHANGED
|
@@ -174,20 +174,26 @@ class CronTest < Test::Unit::TestCase
|
|
|
174
174
|
context "When parsing time using the cron shortcuts" do
|
|
175
175
|
should "parse a :symbol into the correct shortcut" do
|
|
176
176
|
assert_equal '@reboot', parse_time(:reboot)
|
|
177
|
-
assert_equal '@annually', parse_time(:
|
|
177
|
+
assert_equal '@annually', parse_time(:annually)
|
|
178
178
|
assert_equal '@annually', parse_time(:yearly)
|
|
179
|
-
assert_equal '@daily', parse_time(:day)
|
|
180
179
|
assert_equal '@daily', parse_time(:daily)
|
|
181
180
|
assert_equal '@midnight', parse_time(:midnight)
|
|
182
|
-
assert_equal '@monthly', parse_time(:month)
|
|
183
181
|
assert_equal '@monthly', parse_time(:monthly)
|
|
184
|
-
assert_equal '@
|
|
182
|
+
assert_equal '@weekly', parse_time(:weekly)
|
|
185
183
|
assert_equal '@hourly', parse_time(:hourly)
|
|
186
184
|
end
|
|
187
185
|
|
|
186
|
+
should "convert time-based shortcuts to times" do
|
|
187
|
+
assert_equal '0 0 1 * *', parse_time(:month)
|
|
188
|
+
assert_equal '0 0 * * *', parse_time(:day)
|
|
189
|
+
assert_equal '0 * * * *', parse_time(:hour)
|
|
190
|
+
assert_equal '0 0 1 12 *', parse_time(:year)
|
|
191
|
+
assert_equal '0 0 1,8,15,22 * *', parse_time(:week)
|
|
192
|
+
end
|
|
193
|
+
|
|
188
194
|
should "raise an exception if a valid shortcut is given but also an :at" do
|
|
189
195
|
assert_raises ArgumentError do
|
|
190
|
-
parse_time(:
|
|
196
|
+
parse_time(:hourly, nil, "1:00 am")
|
|
191
197
|
end
|
|
192
198
|
|
|
193
199
|
assert_raises ArgumentError do
|
|
@@ -195,7 +201,16 @@ class CronTest < Test::Unit::TestCase
|
|
|
195
201
|
end
|
|
196
202
|
|
|
197
203
|
assert_raises ArgumentError do
|
|
198
|
-
parse_time(:
|
|
204
|
+
parse_time(:daily, nil, '4:20pm')
|
|
205
|
+
end
|
|
206
|
+
end
|
|
207
|
+
end
|
|
208
|
+
|
|
209
|
+
context "When given raw cron sytax" do
|
|
210
|
+
should "return the same cron sytax" do
|
|
211
|
+
crons = ['0 0 27-31 * *', '* * * * *', '2/3 1,9,22 11-26 1-6 *']
|
|
212
|
+
crons.each do |cron|
|
|
213
|
+
assert_equal cron, parse_time(cron)
|
|
199
214
|
end
|
|
200
215
|
end
|
|
201
216
|
end
|
data/whenever.gemspec
CHANGED
|
@@ -1,86 +1,31 @@
|
|
|
1
|
-
# Generated by jeweler
|
|
2
|
-
# DO NOT EDIT THIS FILE DIRECTLY
|
|
3
|
-
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
|
4
1
|
# -*- encoding: utf-8 -*-
|
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
|
3
|
+
require "whenever/version"
|
|
5
4
|
|
|
6
5
|
Gem::Specification.new do |s|
|
|
7
|
-
s.name
|
|
8
|
-
s.version
|
|
9
|
-
|
|
10
|
-
s.
|
|
11
|
-
s.
|
|
12
|
-
s.
|
|
13
|
-
s.
|
|
14
|
-
s.
|
|
15
|
-
s.
|
|
16
|
-
s.
|
|
17
|
-
|
|
18
|
-
]
|
|
19
|
-
s.files = [
|
|
20
|
-
".gitignore",
|
|
21
|
-
"CHANGELOG.rdoc",
|
|
22
|
-
"README.rdoc",
|
|
23
|
-
"Rakefile",
|
|
24
|
-
"bin/whenever",
|
|
25
|
-
"bin/wheneverize",
|
|
26
|
-
"lib/whenever.rb",
|
|
27
|
-
"lib/whenever/base.rb",
|
|
28
|
-
"lib/whenever/capistrano.rb",
|
|
29
|
-
"lib/whenever/command_line.rb",
|
|
30
|
-
"lib/whenever/cron.rb",
|
|
31
|
-
"lib/whenever/job.rb",
|
|
32
|
-
"lib/whenever/job_list.rb",
|
|
33
|
-
"lib/whenever/job_types/default.rb",
|
|
34
|
-
"lib/whenever/output_redirection.rb",
|
|
35
|
-
"lib/whenever/version.rb",
|
|
36
|
-
"test/functional/command_line_test.rb",
|
|
37
|
-
"test/functional/output_at_test.rb",
|
|
38
|
-
"test/functional/output_default_defined_jobs_test.rb",
|
|
39
|
-
"test/functional/output_defined_job_test.rb",
|
|
40
|
-
"test/functional/output_env_test.rb",
|
|
41
|
-
"test/functional/output_redirection_test.rb",
|
|
42
|
-
"test/test_helper.rb",
|
|
43
|
-
"test/unit/cron_test.rb",
|
|
44
|
-
"test/unit/job_test.rb",
|
|
45
|
-
"whenever.gemspec"
|
|
46
|
-
]
|
|
47
|
-
s.homepage = %q{http://github.com/javan/whenever}
|
|
48
|
-
s.rdoc_options = ["--charset=UTF-8"]
|
|
6
|
+
s.name = "whenever"
|
|
7
|
+
s.version = Whenever::VERSION
|
|
8
|
+
s.platform = Gem::Platform::RUBY
|
|
9
|
+
s.authors = ["Javan Makhmali"]
|
|
10
|
+
s.email = ["javan@javan.us"]
|
|
11
|
+
s.homepage = ""
|
|
12
|
+
s.summary = %q{Cron jobs in ruby.}
|
|
13
|
+
s.description = %q{Clean ruby syntax for writing and deploying cron jobs.}
|
|
14
|
+
s.files = `git ls-files`.split("\n")
|
|
15
|
+
s.test_files = `git ls-files -- test/{functional,unit}/*`.split("\n")
|
|
16
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
|
49
17
|
s.require_paths = ["lib"]
|
|
50
|
-
|
|
51
|
-
s.
|
|
52
|
-
s.
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
if s.respond_to? :specification_version then
|
|
65
|
-
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
|
66
|
-
s.specification_version = 3
|
|
67
|
-
|
|
68
|
-
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
|
69
|
-
s.add_runtime_dependency(%q<aaronh-chronic>, [">= 0.3.9"])
|
|
70
|
-
s.add_runtime_dependency(%q<activesupport>, [">= 2.3.4"])
|
|
71
|
-
s.add_development_dependency(%q<shoulda>, [">= 2.1.1"])
|
|
72
|
-
s.add_development_dependency(%q<mocha>, [">= 0.9.5"])
|
|
73
|
-
else
|
|
74
|
-
s.add_dependency(%q<aaronh-chronic>, [">= 0.3.9"])
|
|
75
|
-
s.add_dependency(%q<activesupport>, [">= 2.3.4"])
|
|
76
|
-
s.add_dependency(%q<shoulda>, [">= 2.1.1"])
|
|
77
|
-
s.add_dependency(%q<mocha>, [">= 0.9.5"])
|
|
78
|
-
end
|
|
79
|
-
else
|
|
80
|
-
s.add_dependency(%q<aaronh-chronic>, [">= 0.3.9"])
|
|
81
|
-
s.add_dependency(%q<activesupport>, [">= 2.3.4"])
|
|
82
|
-
s.add_dependency(%q<shoulda>, [">= 2.1.1"])
|
|
83
|
-
s.add_dependency(%q<mocha>, [">= 0.9.5"])
|
|
84
|
-
end
|
|
18
|
+
|
|
19
|
+
s.add_dependency "chronic", "~> 0.6.3"
|
|
20
|
+
s.add_dependency "activesupport", ">= 2.3.4"
|
|
21
|
+
|
|
22
|
+
s.add_development_dependency "shoulda", ">= 2.1.1"
|
|
23
|
+
s.add_development_dependency "mocha", ">= 0.9.5"
|
|
24
|
+
s.add_development_dependency "rake"
|
|
25
|
+
|
|
26
|
+
# I'm not sure why this isn't installed along with activesupport,
|
|
27
|
+
# but for whatever reason running `bundle install` doesn't install
|
|
28
|
+
# i18n so I'm adding it here for now.
|
|
29
|
+
# https://github.com/rails/rails/blob/master/activesupport/activesupport.gemspec#L19 ?
|
|
30
|
+
s.add_development_dependency "i18n"
|
|
85
31
|
end
|
|
86
|
-
|