whenever 0.8.2 → 0.8.3
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/.travis.yml +1 -0
- data/CHANGELOG.md +10 -1
- data/LICENSE +2 -2
- data/README.md +3 -3
- data/lib/whenever/capistrano/recipes.rb +2 -9
- data/lib/whenever/capistrano/support.rb +12 -0
- data/lib/whenever/job.rb +8 -7
- data/lib/whenever/output_redirection.rb +1 -0
- data/lib/whenever/setup.rb +6 -4
- data/lib/whenever/version.rb +2 -2
- data/test/functional/output_default_defined_jobs_test.rb +53 -0
- data/test/functional/output_jobs_for_roles_test.rb +2 -1
- data/test/functional/output_redirection_test.rb +19 -0
- data/test/unit/capistrano_support_test.rb +16 -0
- data/whenever.gemspec +1 -0
- metadata +31 -29
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ca12a3bcee3b722d97603d4b68c6dbb1a9340bde
|
4
|
+
data.tar.gz: 4c14d0e96f2fc3e2fff8f4b1d06217184d6d2a5a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 43e5babdecdfe28f925233cf41c04f2caae3b6796c433a30baa265d47c0b82f3d7fe570ee6b84e64ac3e5b4f9e28b252265361c78e24f2699466399ce0d43bde
|
7
|
+
data.tar.gz: 6ab32597cd5cfc23ee23e16e072589cbfc33fad7da0ac460707fadb60a01b3dc41c28862b8903be785aa588681ecd410e648ddc052ce138f8ec5dddecb990112
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -3,6 +3,15 @@
|
|
3
3
|
* Time zone support
|
4
4
|
|
5
5
|
|
6
|
+
### 0.8.3 / July 11, 2013
|
7
|
+
|
8
|
+
* Improve Cap rollback logic. [Jeroen Jacobs]
|
9
|
+
|
10
|
+
* Allow configuration of the environment variable. [andfx]
|
11
|
+
|
12
|
+
* Output option can be a callable Proc. [Li Xiao]
|
13
|
+
|
14
|
+
|
6
15
|
### 0.8.2 / January 10, 2013
|
7
16
|
|
8
17
|
* Fix Capistrano host options. [Igor Yamolov, Wes Morgan]
|
@@ -257,4 +266,4 @@
|
|
257
266
|
|
258
267
|
### 0.1.0 / February 15th, 2009
|
259
268
|
|
260
|
-
* Initial release [Javan Makhmali]
|
269
|
+
* Initial release [Javan Makhmali]
|
data/LICENSE
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
Copyright (c)
|
1
|
+
Copyright (c) 2013 Javan Makhmali
|
2
2
|
|
3
3
|
Permission is hereby granted, free of charge, to any person
|
4
4
|
obtaining a copy of this software and associated documentation
|
@@ -19,4 +19,4 @@ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
|
19
19
|
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
20
20
|
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
21
21
|
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
22
|
-
OTHER DEALINGS IN THE SOFTWARE.
|
22
|
+
OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
CHANGED
@@ -73,14 +73,14 @@ The default job types that ship with Whenever are defined like so:
|
|
73
73
|
|
74
74
|
```ruby
|
75
75
|
job_type :command, ":task :output"
|
76
|
-
job_type :rake, "cd :path &&
|
76
|
+
job_type :rake, "cd :path && :environment_variable=:environment bundle exec rake :task --silent :output"
|
77
77
|
job_type :runner, "cd :path && script/rails runner -e :environment ':task' :output"
|
78
|
-
job_type :script, "cd :path &&
|
78
|
+
job_type :script, "cd :path && :environment_variable=:environment bundle exec script/:task :output"
|
79
79
|
```
|
80
80
|
|
81
81
|
Pre-Rails 3 apps and apps that don't use Bundler will redefine the `rake` and `runner` jobs respectively to function correctly.
|
82
82
|
|
83
|
-
If a `:path` is not set it will default to the directory in which `whenever` was executed. `:environment` will default to 'production'. `:output` will be replaced with your output redirection settings which you can read more about here: <http://github.com/javan/whenever/wiki/Output-redirection-aka-logging-your-cron-jobs>
|
83
|
+
If a `:path` is not set it will default to the directory in which `whenever` was executed. `:environment_variable` will default to 'RAILS_ENV'. `:environment` will default to 'production'. `:output` will be replaced with your output redirection settings which you can read more about here: <http://github.com/javan/whenever/wiki/Output-redirection-aka-logging-your-cron-jobs>
|
84
84
|
|
85
85
|
All jobs are by default run with `bash -l -c 'command...'`. Among other things, this allows your cron jobs to play nice with RVM by loading the entire environment instead of cron's somewhat limited environment. Read more: <http://blog.scoutapp.com/articles/2010/09/07/rvm-and-cron-in-production>
|
86
86
|
|
@@ -22,18 +22,11 @@ Capistrano::Configuration.instance(:must_exist).load do
|
|
22
22
|
}
|
23
23
|
|
24
24
|
if whenever_servers.any?
|
25
|
+
args = whenever_prepare_for_rollback(args) if task_call_frames[0].task.fully_qualified_name == 'deploy:rollback'
|
25
26
|
whenever_run_commands(args)
|
26
27
|
|
27
28
|
on_rollback do
|
28
|
-
|
29
|
-
# rollback to the previous release's crontab
|
30
|
-
args[:path] = fetch(:previous_release)
|
31
|
-
else
|
32
|
-
# clear the crontab if no previous release
|
33
|
-
args[:path] = fetch(:release_path)
|
34
|
-
args[:flags] = fetch(:whenever_clear_flags)
|
35
|
-
end
|
36
|
-
|
29
|
+
args = whenever_prepare_for_rollback(args)
|
37
30
|
whenever_run_commands(args)
|
38
31
|
end
|
39
32
|
end
|
@@ -22,6 +22,18 @@ module Whenever
|
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
|
+
def whenever_prepare_for_rollback args
|
26
|
+
if fetch(:previous_release)
|
27
|
+
# rollback to the previous release's crontab
|
28
|
+
args[:path] = fetch(:previous_release)
|
29
|
+
else
|
30
|
+
# clear the crontab if no previous release
|
31
|
+
args[:path] = fetch(:release_path)
|
32
|
+
args[:flags] = fetch(:whenever_clear_flags)
|
33
|
+
end
|
34
|
+
args
|
35
|
+
end
|
36
|
+
|
25
37
|
def whenever_run_commands(args)
|
26
38
|
unless [:command, :path, :flags].all? { |a| args.include?(a) }
|
27
39
|
raise ArgumentError, ":command, :path, & :flags are required"
|
data/lib/whenever/job.rb
CHANGED
@@ -6,13 +6,14 @@ module Whenever
|
|
6
6
|
|
7
7
|
def initialize(options = {})
|
8
8
|
@options = options
|
9
|
-
@at
|
10
|
-
@template
|
11
|
-
@job_template
|
12
|
-
@roles
|
13
|
-
@options[:output]
|
14
|
-
@options[:
|
15
|
-
@options[:
|
9
|
+
@at = options.delete(:at)
|
10
|
+
@template = options.delete(:template)
|
11
|
+
@job_template = options.delete(:job_template) || ":job"
|
12
|
+
@roles = Array.wrap(options.delete(:roles))
|
13
|
+
@options[:output] = options.has_key?(:output) ? Whenever::Output::Redirection.new(options[:output]).to_s : ''
|
14
|
+
@options[:environment_variable] ||= "RAILS_ENV"
|
15
|
+
@options[:environment] ||= :production
|
16
|
+
@options[:path] = Shellwords.shellescape(@options[:path] || Whenever.path)
|
16
17
|
end
|
17
18
|
|
18
19
|
def output
|
data/lib/whenever/setup.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# Environment variable defaults to RAILS_ENV
|
2
|
+
set :environment_variable, "RAILS_ENV"
|
1
3
|
# Environment defaults to production
|
2
4
|
set :environment, "production"
|
3
5
|
# Path defaults to the directory `whenever` was run from
|
@@ -11,11 +13,11 @@ job_type :command, ":task :output"
|
|
11
13
|
|
12
14
|
# Run rake through bundler if possible
|
13
15
|
if Whenever.bundler?
|
14
|
-
job_type :rake, "cd :path &&
|
15
|
-
job_type :script, "cd :path &&
|
16
|
+
job_type :rake, "cd :path && :environment_variable=:environment bundle exec rake :task --silent :output"
|
17
|
+
job_type :script, "cd :path && :environment_variable=:environment bundle exec script/:task :output"
|
16
18
|
else
|
17
|
-
job_type :rake, "cd :path &&
|
18
|
-
job_type :script, "cd :path &&
|
19
|
+
job_type :rake, "cd :path && :environment_variable=:environment rake :task --silent :output"
|
20
|
+
job_type :script, "cd :path && :environment_variable=:environment script/:task :output"
|
19
21
|
end
|
20
22
|
|
21
23
|
# Create a runner job that's appropriate for the Rails version,
|
data/lib/whenever/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
1
|
module Whenever
|
2
|
-
VERSION = '0.8.
|
3
|
-
end
|
2
|
+
VERSION = '0.8.3'
|
3
|
+
end
|
@@ -179,6 +179,41 @@ class OutputDefaultDefinedJobsTest < Test::Unit::TestCase
|
|
179
179
|
end
|
180
180
|
end
|
181
181
|
|
182
|
+
context "A rake command that sets the environment variable" do
|
183
|
+
setup do
|
184
|
+
@output = Whenever.cron \
|
185
|
+
<<-file
|
186
|
+
set :job_template, nil
|
187
|
+
set :path, '/my/path'
|
188
|
+
set :environment_variable, 'RAKE_ENV'
|
189
|
+
every 2.hours do
|
190
|
+
rake "blahblah"
|
191
|
+
end
|
192
|
+
file
|
193
|
+
end
|
194
|
+
|
195
|
+
should "output the rake command using that environment variable" do
|
196
|
+
assert_match two_hours + ' cd /my/path && RAKE_ENV=production bundle exec rake blahblah --silent', @output
|
197
|
+
end
|
198
|
+
end
|
199
|
+
|
200
|
+
context "A rake command that overrides the environment variable" do
|
201
|
+
setup do
|
202
|
+
@output = Whenever.cron \
|
203
|
+
<<-file
|
204
|
+
set :job_template, nil
|
205
|
+
set :path, '/my/path'
|
206
|
+
set :environment_variable, 'RAKE_ENV'
|
207
|
+
every 2.hours do
|
208
|
+
rake "blahblah", :environment_variable => 'SOME_ENV'
|
209
|
+
end
|
210
|
+
file
|
211
|
+
end
|
212
|
+
|
213
|
+
should "output the rake command using that environment variable" do
|
214
|
+
assert_match two_hours + ' cd /my/path && SOME_ENV=production bundle exec rake blahblah --silent', @output
|
215
|
+
end
|
216
|
+
end
|
182
217
|
|
183
218
|
# script
|
184
219
|
|
@@ -235,4 +270,22 @@ class OutputDefaultDefinedJobsTest < Test::Unit::TestCase
|
|
235
270
|
end
|
236
271
|
end
|
237
272
|
|
273
|
+
context "A script command that uses an environment variable" do
|
274
|
+
setup do
|
275
|
+
@output = Whenever.cron \
|
276
|
+
<<-file
|
277
|
+
set :job_template, nil
|
278
|
+
set :environment_variable, 'RAKE_ENV'
|
279
|
+
set :path, '/my/path'
|
280
|
+
every 2.hours do
|
281
|
+
script "blahblah"
|
282
|
+
end
|
283
|
+
file
|
284
|
+
end
|
285
|
+
|
286
|
+
should "output the script command using that environment variable" do
|
287
|
+
assert_match two_hours + ' cd /my/path && RAKE_ENV=production bundle exec script/blahblah', @output
|
288
|
+
end
|
289
|
+
end
|
290
|
+
|
238
291
|
end
|
@@ -78,7 +78,8 @@ class OutputJobsForRolesTest < Test::Unit::TestCase
|
|
78
78
|
end
|
79
79
|
|
80
80
|
should "output both jobs" do
|
81
|
-
|
81
|
+
assert_match two_hours + " /bin/bash -l -c 'role1_cmd'", @output
|
82
|
+
assert_match "0 * * * * /bin/bash -l -c 'role2_cmd'", @output
|
82
83
|
end
|
83
84
|
end
|
84
85
|
end
|
@@ -304,4 +304,23 @@ class OutputRedirectionTest < Test::Unit::TestCase
|
|
304
304
|
assert_match /^.+ .+ .+ .+ blahblah >> cron.log 2>&1$/, @output
|
305
305
|
end
|
306
306
|
end
|
307
|
+
|
308
|
+
|
309
|
+
context "A command when the standard output is set to a lambda" do
|
310
|
+
setup do
|
311
|
+
@output = Whenever.cron \
|
312
|
+
<<-file
|
313
|
+
set :job_template, nil
|
314
|
+
set :output, lambda { "2>&1 | logger -t whenever_cron" }
|
315
|
+
every 2.hours do
|
316
|
+
command "blahblah"
|
317
|
+
end
|
318
|
+
file
|
319
|
+
end
|
320
|
+
|
321
|
+
should "output the command by result of the lambda evaluated" do
|
322
|
+
assert_match /^.+ .+ .+ .+ blahblah 2>&1 | logger -t whenever_cron$/, @output
|
323
|
+
end
|
324
|
+
end
|
325
|
+
|
307
326
|
end
|
@@ -78,6 +78,22 @@ class CapistranoSupportTest < Test::Unit::TestCase
|
|
78
78
|
end
|
79
79
|
end
|
80
80
|
|
81
|
+
context "#whenever_prepare_for_rollback" do
|
82
|
+
should "set path to previous_release if there is a previous release" do
|
83
|
+
args = {}
|
84
|
+
@capistrano.stubs(:fetch).with(:previous_release).returns("/some/path/20121221010000")
|
85
|
+
assert_equal({:path => "/some/path/20121221010000"}, @capistrano.whenever_prepare_for_rollback(args))
|
86
|
+
end
|
87
|
+
|
88
|
+
should "set path to release_path and flags to whenever_clear_flags if there is no previous release" do
|
89
|
+
args = {}
|
90
|
+
@capistrano.stubs(:fetch).with(:previous_release).returns(nil)
|
91
|
+
@capistrano.stubs(:fetch).with(:release_path).returns("/some/path/20121221010000")
|
92
|
+
@capistrano.stubs(:fetch).with(:whenever_clear_flags).returns("--clear-crontab whenever_identifier")
|
93
|
+
assert_equal({:path => "/some/path/20121221010000", :flags => "--clear-crontab whenever_identifier"}, @capistrano.whenever_prepare_for_rollback(args))
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
81
97
|
context "#whenever_run_commands" do
|
82
98
|
should "require :command arg" do
|
83
99
|
assert_raise ArgumentError do
|
data/whenever.gemspec
CHANGED
@@ -19,6 +19,7 @@ Gem::Specification.new do |s|
|
|
19
19
|
s.add_dependency "chronic", ">= 0.6.3"
|
20
20
|
s.add_dependency "activesupport", ">= 2.3.4"
|
21
21
|
|
22
|
+
s.add_development_dependency "shoulda-matchers", "2.0.0"
|
22
23
|
s.add_development_dependency "shoulda", ">= 2.1.1"
|
23
24
|
s.add_development_dependency "mocha", ">= 0.9.5"
|
24
25
|
s.add_development_dependency "rake"
|
metadata
CHANGED
@@ -1,94 +1,97 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: whenever
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.8.
|
5
|
-
prerelease:
|
4
|
+
version: 0.8.3
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Javan Makhmali
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date: 2013-
|
11
|
+
date: 2013-07-11 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: chronic
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - '>='
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: 0.6.3
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
|
-
- -
|
24
|
+
- - '>='
|
28
25
|
- !ruby/object:Gem::Version
|
29
26
|
version: 0.6.3
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: activesupport
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
|
-
- -
|
31
|
+
- - '>='
|
36
32
|
- !ruby/object:Gem::Version
|
37
33
|
version: 2.3.4
|
38
34
|
type: :runtime
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
|
-
- -
|
38
|
+
- - '>='
|
44
39
|
- !ruby/object:Gem::Version
|
45
40
|
version: 2.3.4
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: shoulda-matchers
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 2.0.0
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 2.0.0
|
46
55
|
- !ruby/object:Gem::Dependency
|
47
56
|
name: shoulda
|
48
57
|
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
58
|
requirements:
|
51
|
-
- -
|
59
|
+
- - '>='
|
52
60
|
- !ruby/object:Gem::Version
|
53
61
|
version: 2.1.1
|
54
62
|
type: :development
|
55
63
|
prerelease: false
|
56
64
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
65
|
requirements:
|
59
|
-
- -
|
66
|
+
- - '>='
|
60
67
|
- !ruby/object:Gem::Version
|
61
68
|
version: 2.1.1
|
62
69
|
- !ruby/object:Gem::Dependency
|
63
70
|
name: mocha
|
64
71
|
requirement: !ruby/object:Gem::Requirement
|
65
|
-
none: false
|
66
72
|
requirements:
|
67
|
-
- -
|
73
|
+
- - '>='
|
68
74
|
- !ruby/object:Gem::Version
|
69
75
|
version: 0.9.5
|
70
76
|
type: :development
|
71
77
|
prerelease: false
|
72
78
|
version_requirements: !ruby/object:Gem::Requirement
|
73
|
-
none: false
|
74
79
|
requirements:
|
75
|
-
- -
|
80
|
+
- - '>='
|
76
81
|
- !ruby/object:Gem::Version
|
77
82
|
version: 0.9.5
|
78
83
|
- !ruby/object:Gem::Dependency
|
79
84
|
name: rake
|
80
85
|
requirement: !ruby/object:Gem::Requirement
|
81
|
-
none: false
|
82
86
|
requirements:
|
83
|
-
- -
|
87
|
+
- - '>='
|
84
88
|
- !ruby/object:Gem::Version
|
85
89
|
version: '0'
|
86
90
|
type: :development
|
87
91
|
prerelease: false
|
88
92
|
version_requirements: !ruby/object:Gem::Requirement
|
89
|
-
none: false
|
90
93
|
requirements:
|
91
|
-
- -
|
94
|
+
- - '>='
|
92
95
|
- !ruby/object:Gem::Version
|
93
96
|
version: '0'
|
94
97
|
description: Clean ruby syntax for writing and deploying cron jobs.
|
@@ -134,27 +137,26 @@ files:
|
|
134
137
|
- whenever.gemspec
|
135
138
|
homepage: ''
|
136
139
|
licenses: []
|
140
|
+
metadata: {}
|
137
141
|
post_install_message:
|
138
142
|
rdoc_options: []
|
139
143
|
require_paths:
|
140
144
|
- lib
|
141
145
|
required_ruby_version: !ruby/object:Gem::Requirement
|
142
|
-
none: false
|
143
146
|
requirements:
|
144
|
-
- -
|
147
|
+
- - '>='
|
145
148
|
- !ruby/object:Gem::Version
|
146
149
|
version: '0'
|
147
150
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
148
|
-
none: false
|
149
151
|
requirements:
|
150
|
-
- -
|
152
|
+
- - '>='
|
151
153
|
- !ruby/object:Gem::Version
|
152
154
|
version: '0'
|
153
155
|
requirements: []
|
154
156
|
rubyforge_project:
|
155
|
-
rubygems_version:
|
157
|
+
rubygems_version: 2.0.2
|
156
158
|
signing_key:
|
157
|
-
specification_version:
|
159
|
+
specification_version: 4
|
158
160
|
summary: Cron jobs in ruby.
|
159
161
|
test_files:
|
160
162
|
- test/functional/command_line_test.rb
|