whenever 0.8.2 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +1 -0
- data/.travis.yml +20 -7
- data/Appraisals +19 -0
- data/CHANGELOG.md +116 -3
- data/Gemfile +3 -3
- data/LICENSE +2 -2
- data/README.md +133 -32
- data/Rakefile +3 -10
- data/bin/whenever +3 -0
- data/bin/wheneverize +8 -5
- data/gemfiles/activesupport4.1.gemfile +7 -0
- data/gemfiles/activesupport4.2.gemfile +7 -0
- 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/hooks.rb +8 -0
- data/lib/whenever/capistrano/{recipes.rb → v2/recipes.rb} +7 -13
- data/lib/whenever/capistrano/{support.rb → v2/support.rb} +12 -0
- data/lib/whenever/capistrano/v3/tasks/whenever.rake +56 -0
- data/lib/whenever/capistrano.rb +5 -6
- data/lib/whenever/command_line.rb +69 -48
- data/lib/whenever/cron.rb +54 -25
- data/lib/whenever/job.rb +13 -14
- data/lib/whenever/job_list.rb +54 -24
- data/lib/whenever/numeric.rb +13 -0
- data/lib/whenever/numeric_seconds.rb +48 -0
- data/lib/whenever/os.rb +7 -0
- data/lib/whenever/output_redirection.rb +1 -0
- data/lib/whenever/setup.rb +19 -15
- data/lib/whenever/version.rb +2 -2
- data/lib/whenever.rb +19 -14
- data/test/functional/command_line_test.rb +379 -243
- data/test/functional/output_at_test.rb +227 -249
- data/test/functional/output_default_defined_jobs_test.rb +251 -193
- data/test/functional/output_defined_job_test.rb +65 -91
- data/test/functional/output_env_test.rb +22 -26
- data/test/functional/output_jobs_for_roles_test.rb +46 -65
- data/test/functional/output_jobs_with_mailto_test.rb +168 -0
- data/test/functional/output_redirection_test.rb +232 -291
- data/test/test_case.rb +32 -0
- data/test/test_helper.rb +44 -15
- data/test/unit/capistrano_support_test.rb +128 -134
- data/test/unit/cron_test.rb +373 -208
- data/test/unit/executable_test.rb +142 -0
- data/test/unit/job_test.rb +111 -117
- data/whenever.gemspec +7 -4
- metadata +63 -44
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: dc5ff14e6e9d357583f5e20d31fafbcf2dfe3aea8ac756cf9103f51504674e9a
|
4
|
+
data.tar.gz: 446e8398b741a1a9a7ee262b3542efb107d1453259083fef03ea50726227d7dd
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 41f396515f594a4726bd9048783653b0b203e0beb4ea65f6b95faf508061d0fd064bec0a31bbcf6dad6a23f68ec4f3364ae6e8f160eb0539ec6073a6c4960242
|
7
|
+
data.tar.gz: 4fbe2b52fc350ee272d7d03638369b8a6443c1ed6e122be511b9ccf07881c1e559d63587153259343febc89db40aa45bc4ca45cf83af885fd618fd5668ddd1d2
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
@@ -1,8 +1,21 @@
|
|
1
|
+
language: ruby
|
2
|
+
|
3
|
+
before_install:
|
4
|
+
- gem install bundler
|
5
|
+
- unset _JAVA_OPTIONS
|
1
6
|
rvm:
|
2
|
-
-
|
3
|
-
-
|
4
|
-
-
|
5
|
-
-
|
6
|
-
|
7
|
-
|
8
|
-
-
|
7
|
+
- 2.4.6
|
8
|
+
- 2.5.5
|
9
|
+
- 2.6.3
|
10
|
+
- jruby-9.2.6.0
|
11
|
+
|
12
|
+
gemfile:
|
13
|
+
- gemfiles/activesupport4.1.gemfile
|
14
|
+
- gemfiles/activesupport4.2.gemfile
|
15
|
+
- gemfiles/activesupport5.0.gemfile
|
16
|
+
- gemfiles/activesupport5.1.gemfile
|
17
|
+
- gemfiles/activesupport5.2.gemfile
|
18
|
+
|
19
|
+
env:
|
20
|
+
global:
|
21
|
+
- JRUBY_OPTS=--debug
|
data/Appraisals
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
appraise 'activesupport4.1' do
|
2
|
+
gem "activesupport", "~> 4.1.0"
|
3
|
+
end
|
4
|
+
|
5
|
+
appraise 'activesupport4.2' do
|
6
|
+
gem "activesupport", "~> 4.2.0"
|
7
|
+
end
|
8
|
+
|
9
|
+
appraise 'activesupport5.0' do
|
10
|
+
gem "activesupport", "~> 5.0.0"
|
11
|
+
end
|
12
|
+
|
13
|
+
appraise 'activesupport5.1' do
|
14
|
+
gem "activesupport", "~> 5.1.0"
|
15
|
+
end
|
16
|
+
|
17
|
+
appraise 'activesupport5.2' do
|
18
|
+
gem "activesupport", "~> 5.2.0beta2"
|
19
|
+
end
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,119 @@
|
|
1
|
-
###
|
1
|
+
### unreleased
|
2
2
|
|
3
|
-
|
3
|
+
### 1.0.0 / Jun 13, 2019
|
4
|
+
|
5
|
+
* First stable release per SemVer.
|
6
|
+
|
7
|
+
* Removes support for versions of Ruby which are no longer supported by the Ruby project.
|
8
|
+
|
9
|
+
### 0.11.0 / April 23, 2019
|
10
|
+
|
11
|
+
* Add support for mapping Range objects to cron range syntax [Tim Craft](https://github.com/javan/whenever/pull/725)
|
12
|
+
|
13
|
+
* Bugfix: Avoid modifying Capistrano `default_env` when setting the whenever environment. [ta1kt0me](https://github.com/javan/whenever/pull/728)
|
14
|
+
|
15
|
+
* Enable to execute whenever's task independently without setting :release_path or :whenever_path [ta1kt0me](https://github.com/javan/whenever/pull/729)
|
16
|
+
|
17
|
+
* Make error message clearer when parsing cron syntax fails due to a trailing space [ignisf](https://github.com/javan/whenever/pull/744)
|
18
|
+
|
19
|
+
### 0.10.0 / November 19, 2017
|
20
|
+
|
21
|
+
* Modify wheneverize to allow for the creating of 'config' directory when not present
|
22
|
+
|
23
|
+
* Add --crontab-command to whenever binary for overriding the crontab command. [Martin Grandrath]
|
24
|
+
|
25
|
+
* Allow setting the path within which Capistrano will execute whenever. [Samuel Johnson](https://github.com/javan/whenever/pull/619)
|
26
|
+
|
27
|
+
* Allow the use of string literals for month and day-of-week in raw cron syntax.. [Potamianos Gregory](https://github.com/javan/whenever/pull/711)
|
28
|
+
|
29
|
+
* Include Capistrano default environment variables when executing Whenever. [Karl Li](https://github.com/javan/whenever/pull/719)
|
30
|
+
|
31
|
+
* Allow configuring an alternative schedule file in Capistrano. [Shinichi Okamoto](https://github.com/javan/whenever/pull/666)
|
32
|
+
|
33
|
+
* Add customizing email recipient option with the MAILTO environment variable. [Chikahiro Tokoro](https://github.com/javan/whenever/pull/678)
|
34
|
+
|
35
|
+
### 0.9.7 / June 14, 2016
|
36
|
+
|
37
|
+
* Restore compatibility with Capistrano v3; it has a bug which we have to work around [Ben Langfeld, Chris Gunther, Shohei Yamasaki]
|
38
|
+
|
39
|
+
### 0.9.6 / June 13, 2016
|
40
|
+
|
41
|
+
* Bypass symlinks when loading Capistrano v3 code, since these symlinks don't work in recent gem releases [Justin Ramos]
|
42
|
+
|
43
|
+
### 0.9.5 / June 12, 2016
|
44
|
+
|
45
|
+
* Improve documentation [Ben Langfeld, Spencer Fry]
|
46
|
+
|
47
|
+
* Properly support Solaris / SmartOS [Steven Williamson]
|
48
|
+
|
49
|
+
* Drop support for Ruby < 1.9.3. Test newer Ruby versions. [Javan Makhmali, Bartłomiej Kozal]
|
50
|
+
|
51
|
+
* Suport Ruby 2.3.0 and Rails 4 [Vincent Boisard]
|
52
|
+
|
53
|
+
* Set `RAILS_ENV` correctly in schedule when writing crontab from Capistrano [Ben Langfeld, Lorenzo Manacorda]
|
54
|
+
|
55
|
+
* Minor refactoring, avoidance of Ruby warnings, etc [Ben Langfeld, DV Dasari]
|
56
|
+
|
57
|
+
* Correctly pass through date expressions (e.g. `1.day`) inside job definitions [Rafael Sales]
|
58
|
+
|
59
|
+
* Prevent writing invalid cron strings [Danny Fallon, Ben Langfeld]
|
60
|
+
|
61
|
+
* Execute runner with `bundle exec` to ensure presence of app dependencies [Judith Roth]
|
62
|
+
|
63
|
+
|
64
|
+
### 0.9.4 / October 24, 2014
|
65
|
+
|
66
|
+
* Fix duplicated command line arguments when deploying to multiple servers with Cap 3. [betesh]
|
67
|
+
|
68
|
+
* Set `whenever_environment` to the current stage before defaulting to production in Cap 3 tasks. [Karthik T]
|
69
|
+
|
70
|
+
|
71
|
+
### 0.9.3 / October 5, 2014
|
72
|
+
|
73
|
+
* Drop ActiveSupport dependency [James Healy, Javan Makhmali]
|
74
|
+
|
75
|
+
* Drop shoulda for tests
|
76
|
+
|
77
|
+
* Fix `whenever:clear_crontab` Cap 3 task [Javan Makhmali]
|
78
|
+
|
79
|
+
* Avoid using tempfiles [ahoward]
|
80
|
+
|
81
|
+
|
82
|
+
### 0.9.2 / March 4, 2014
|
83
|
+
|
84
|
+
* Fix issues generating arguments for `execute` in Capistrano 3 tasks. [Javan Makhmali]
|
85
|
+
|
86
|
+
|
87
|
+
### 0.9.1 / March 2, 2014
|
88
|
+
|
89
|
+
* Pass `--roles` option to `whenever` in Capistrano 3 tasks. [betesh, Javan Makhmali]
|
90
|
+
|
91
|
+
* Allow setting `:whenever_command` for Capistrano 3. [Javan Makhmali]
|
92
|
+
|
93
|
+
* Allow `:whenever` command to be mapped in SSHKit. [Javan Makhmali]
|
94
|
+
|
95
|
+
|
96
|
+
### 0.9.0 / December 17, 2013
|
97
|
+
|
98
|
+
* Capistrano V3 support. [Philip Hallstrom]
|
99
|
+
|
100
|
+
* Process params in job templates. [Austin Ziegler]
|
101
|
+
|
102
|
+
|
103
|
+
### 0.8.4 / July 22, 2012
|
104
|
+
|
105
|
+
* Don't require schedule file when clearing. [Javan Makhmali]
|
106
|
+
|
107
|
+
* Use bin/rails when available. [Javan Makhmali]
|
108
|
+
|
109
|
+
|
110
|
+
### 0.8.3 / July 11, 2013
|
111
|
+
|
112
|
+
* Improve Cap rollback logic. [Jeroen Jacobs]
|
113
|
+
|
114
|
+
* Allow configuration of the environment variable. [andfx]
|
115
|
+
|
116
|
+
* Output option can be a callable Proc. [Li Xiao]
|
4
117
|
|
5
118
|
|
6
119
|
### 0.8.2 / January 10, 2013
|
@@ -257,4 +370,4 @@
|
|
257
370
|
|
258
371
|
### 0.1.0 / February 15th, 2009
|
259
372
|
|
260
|
-
* Initial release [Javan Makhmali]
|
373
|
+
* Initial release [Javan Makhmali]
|
data/Gemfile
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
source "
|
1
|
+
source "https://rubygems.org"
|
2
2
|
|
3
|
-
# Specify your gem's dependencies in
|
4
|
-
gemspec
|
3
|
+
# Specify your gem's dependencies in whenever.gemspec
|
4
|
+
gemspec
|
data/LICENSE
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
Copyright (c)
|
1
|
+
Copyright (c) 2017 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
@@ -9,7 +9,7 @@ $ gem install whenever
|
|
9
9
|
Or with Bundler in your Gemfile.
|
10
10
|
|
11
11
|
```ruby
|
12
|
-
gem 'whenever', :
|
12
|
+
gem 'whenever', require: false
|
13
13
|
```
|
14
14
|
|
15
15
|
### Getting started
|
@@ -19,26 +19,54 @@ $ cd /apps/my-great-project
|
|
19
19
|
$ wheneverize .
|
20
20
|
```
|
21
21
|
|
22
|
-
This will create an initial `config/schedule.rb` file for you.
|
22
|
+
This will create an initial `config/schedule.rb` file for you (as long as the config folder is already present in your project).
|
23
|
+
|
24
|
+
### The `whenever` command
|
25
|
+
|
26
|
+
```sh
|
27
|
+
$ cd /apps/my-great-project
|
28
|
+
$ whenever
|
29
|
+
```
|
30
|
+
|
31
|
+
This will simply show you your `schedule.rb` file converted to cron syntax. It does not read or write your crontab file; you'll need to do this in order for your jobs to execute:
|
32
|
+
|
33
|
+
```sh
|
34
|
+
$ whenever --update-crontab
|
35
|
+
```
|
36
|
+
|
37
|
+
Other commonly used options include:
|
38
|
+
```sh
|
39
|
+
$ whenever --user app # set a user as which to install the crontab
|
40
|
+
$ whenever --load-file config/my_schedule.rb # set the schedule file
|
41
|
+
$ whenever --crontab-command 'sudo crontab' # override the crontab command
|
42
|
+
```
|
43
|
+
|
44
|
+
You can list installed cron jobs using `crontab -l`.
|
45
|
+
|
46
|
+
Run `whenever --help` for a complete list of options for selecting the schedule to use, setting variables in the schedule, etc.
|
23
47
|
|
24
48
|
### Example schedule.rb file
|
25
49
|
|
26
50
|
```ruby
|
27
|
-
every 3.hours do
|
51
|
+
every 3.hours do # 1.minute 1.day 1.week 1.month 1.year is also supported
|
28
52
|
runner "MyModel.some_process"
|
29
53
|
rake "my:rake:task"
|
30
54
|
command "/usr/bin/my_great_command"
|
31
55
|
end
|
32
56
|
|
33
|
-
every 1.day, :
|
57
|
+
every 1.day, at: '4:30 am' do
|
34
58
|
runner "MyModel.task_to_run_at_four_thirty_in_the_morning"
|
35
59
|
end
|
36
60
|
|
61
|
+
every 1.day, at: ['4:30 am', '6:00 pm'] do
|
62
|
+
runner "Mymodel.task_to_run_in_two_times_every_day"
|
63
|
+
end
|
64
|
+
|
37
65
|
every :hour do # Many shortcuts available: :hour, :day, :month, :year, :reboot
|
38
66
|
runner "SomeModel.ladeeda"
|
39
67
|
end
|
40
68
|
|
41
|
-
every :sunday, :
|
69
|
+
every :sunday, at: '12pm' do # Use any day of the week or :weekend, :weekday
|
42
70
|
runner "Task.do_something_great"
|
43
71
|
end
|
44
72
|
|
@@ -48,7 +76,7 @@ end
|
|
48
76
|
|
49
77
|
# run this task only on servers with the :app role in Capistrano
|
50
78
|
# see Capistrano roles section below
|
51
|
-
every :day, :
|
79
|
+
every :day, at: '12:20am', roles: [:app] do
|
52
80
|
rake "app_server:task"
|
53
81
|
end
|
54
82
|
```
|
@@ -63,7 +91,7 @@ For example:
|
|
63
91
|
job_type :awesome, '/usr/local/bin/awesome :task :fun_level'
|
64
92
|
|
65
93
|
every 2.hours do
|
66
|
-
awesome "party", :
|
94
|
+
awesome "party", fun_level: "extreme"
|
67
95
|
end
|
68
96
|
```
|
69
97
|
|
@@ -73,14 +101,14 @@ The default job types that ship with Whenever are defined like so:
|
|
73
101
|
|
74
102
|
```ruby
|
75
103
|
job_type :command, ":task :output"
|
76
|
-
job_type :rake, "cd :path &&
|
77
|
-
job_type :runner, "cd :path &&
|
78
|
-
job_type :script, "cd :path &&
|
104
|
+
job_type :rake, "cd :path && :environment_variable=:environment bundle exec rake :task --silent :output"
|
105
|
+
job_type :runner, "cd :path && bin/rails runner -e :environment ':task' :output"
|
106
|
+
job_type :script, "cd :path && :environment_variable=:environment bundle exec script/:task :output"
|
79
107
|
```
|
80
108
|
|
81
109
|
Pre-Rails 3 apps and apps that don't use Bundler will redefine the `rake` and `runner` jobs respectively to function correctly.
|
82
110
|
|
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>
|
111
|
+
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
112
|
|
85
113
|
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
114
|
|
@@ -96,9 +124,60 @@ Or set the job_template to nil to have your jobs execute normally.
|
|
96
124
|
set :job_template, nil
|
97
125
|
```
|
98
126
|
|
127
|
+
### Parsing dates and times
|
128
|
+
|
129
|
+
Whenever uses the [Chronic](https://github.com/mojombo/chronic) gem to parse the specified dates and times.
|
130
|
+
|
131
|
+
You can set your custom Chronic configuration if the defaults don't fit you.
|
132
|
+
|
133
|
+
For example, to assume a 24 hour clock instead of the default 12 hour clock:
|
134
|
+
|
135
|
+
```ruby
|
136
|
+
set :chronic_options, hours24: true
|
137
|
+
|
138
|
+
# By default this would run the job every day at 3am
|
139
|
+
every 1.day, at: '3:00' do
|
140
|
+
runner "MyModel.nightly_archive_job"
|
141
|
+
end
|
142
|
+
```
|
143
|
+
|
144
|
+
You can see a list of all available options here: <https://github.com/mojombo/chronic/blob/master/lib/chronic/parser.rb>
|
145
|
+
|
146
|
+
### Customize email recipient with the `MAILTO` environment variable
|
147
|
+
|
148
|
+
Output from the jobs is sent to the email address configured in the `MAILTO` environment variable.
|
149
|
+
|
150
|
+
There are many ways to further configure the recipient.
|
151
|
+
|
152
|
+
Example: A global configuration, overriding the environment's value:
|
153
|
+
|
154
|
+
```ruby
|
155
|
+
env 'MAILTO', 'output_of_cron@example.com'
|
156
|
+
|
157
|
+
every 3.hours do
|
158
|
+
command "/usr/bin/my_great_command"
|
159
|
+
end
|
160
|
+
```
|
161
|
+
|
162
|
+
Example: A `MAILTO` configured for all the jobs in an interval block:
|
163
|
+
|
164
|
+
```ruby
|
165
|
+
every 3.hours, mailto: 'my_super_command@example.com' do
|
166
|
+
command "/usr/bin/my_super_command"
|
167
|
+
end
|
168
|
+
```
|
169
|
+
|
170
|
+
Example: A `MAILTO` configured for a single job:
|
171
|
+
|
172
|
+
```ruby
|
173
|
+
every 3.hours do
|
174
|
+
command "/usr/bin/my_super_command", mailto: 'my_super_command_output@example.com'
|
175
|
+
end
|
176
|
+
```
|
177
|
+
|
99
178
|
### Capistrano integration
|
100
179
|
|
101
|
-
Use the built-in Capistrano recipe for easy crontab updates with deploys.
|
180
|
+
Use the built-in Capistrano recipe for easy crontab updates with deploys. For Capistrano V3, see the next section.
|
102
181
|
|
103
182
|
In your "config/deploy.rb" file:
|
104
183
|
|
@@ -106,7 +185,7 @@ In your "config/deploy.rb" file:
|
|
106
185
|
require "whenever/capistrano"
|
107
186
|
```
|
108
187
|
|
109
|
-
Take a look at the recipe for options you can set. <
|
188
|
+
Take a look at the recipe for options you can set. <https://github.com/javan/whenever/blob/master/lib/whenever/capistrano/v2/recipes.rb>
|
110
189
|
For example, if you're using bundler do this:
|
111
190
|
|
112
191
|
```ruby
|
@@ -123,7 +202,7 @@ require "whenever/capistrano"
|
|
123
202
|
|
124
203
|
The capistrano variable `:stage` should be the one holding your environment name. This will make the correct `:environment` available in your `schedule.rb`.
|
125
204
|
|
126
|
-
If both your environments are on the same server you'll want to namespace them or they'll overwrite each other when you deploy:
|
205
|
+
If both your environments are on the same server you'll want to namespace them, or they'll overwrite each other when you deploy:
|
127
206
|
|
128
207
|
```ruby
|
129
208
|
set :whenever_environment, defer { stage }
|
@@ -131,6 +210,29 @@ set :whenever_identifier, defer { "#{application}_#{stage}" }
|
|
131
210
|
require "whenever/capistrano"
|
132
211
|
```
|
133
212
|
|
213
|
+
If you use a schedule at an alternative path, you may configure it like so:
|
214
|
+
|
215
|
+
```ruby
|
216
|
+
set :whenever_load_file, defer { "#{release_path}/somewhere/else/schedule.rb" }
|
217
|
+
require "whenever/capistrano"
|
218
|
+
```
|
219
|
+
|
220
|
+
### Capistrano V3 Integration
|
221
|
+
|
222
|
+
In your "Capfile" file:
|
223
|
+
|
224
|
+
```ruby
|
225
|
+
require "whenever/capistrano"
|
226
|
+
```
|
227
|
+
|
228
|
+
Take a look at the [load:defaults task](https://github.com/javan/whenever/blob/master/lib/whenever/capistrano/v3/tasks/whenever.rake) (bottom of file) for options you can set. For example, to namespace the crontab entries by application and stage do this in your "config/deploy.rb" file:
|
229
|
+
|
230
|
+
```ruby
|
231
|
+
set :whenever_identifier, ->{ "#{fetch(:application)}_#{fetch(:stage)}" }
|
232
|
+
```
|
233
|
+
|
234
|
+
The Capistrano integration by default expects the `:application` variable to be set in order to scope jobs in the crontab.
|
235
|
+
|
134
236
|
### Capistrano roles
|
135
237
|
|
136
238
|
The first thing to know about the new roles support is that it is entirely
|
@@ -139,10 +241,10 @@ different servers in your capistrano deployment, then you can safely stop readin
|
|
139
241
|
now and everything should just work the same way it always has.
|
140
242
|
|
141
243
|
When you define a job in your schedule.rb file, by default it will be deployed to
|
142
|
-
all servers in the whenever_roles list (which defaults to [:db]).
|
244
|
+
all servers in the whenever_roles list (which defaults to `[:db]`).
|
143
245
|
|
144
246
|
However, if you want to restrict certain jobs to only run on subset of servers,
|
145
|
-
you can add a :
|
247
|
+
you can add a `roles: [...]` argument to their definitions. **Make sure to add
|
146
248
|
that role to the whenever_roles list in your deploy.rb.**
|
147
249
|
|
148
250
|
When you run `cap deploy`, jobs with a :roles list specified will only be added to
|
@@ -151,28 +253,28 @@ the crontabs on servers with one or more of the roles in that list.
|
|
151
253
|
Jobs with no :roles argument will be deployed to all servers in the whenever_roles
|
152
254
|
list. This is to maintain backward compatibility with previous releases of whenever.
|
153
255
|
|
154
|
-
So, for example, with the default whenever_roles of [:db]
|
155
|
-
deployed to all servers with the
|
256
|
+
So, for example, with the default whenever_roles of `[:db]`, a job like this would be
|
257
|
+
deployed to all servers with the `:db` role:
|
156
258
|
|
157
259
|
```ruby
|
158
|
-
every :day, :
|
260
|
+
every :day, at: '12:20am' do
|
159
261
|
rake 'foo:bar'
|
160
262
|
end
|
161
263
|
```
|
162
264
|
|
163
|
-
If we set whenever_roles to [:db, :app] in deploy.rb, and have the following
|
265
|
+
If we set whenever_roles to `[:db, :app]` in deploy.rb, and have the following
|
164
266
|
jobs in schedule.rb:
|
165
267
|
|
166
268
|
```ruby
|
167
|
-
every :day, :
|
269
|
+
every :day, at: '1:37pm', roles: [:app] do
|
168
270
|
rake 'app:task' # will only be added to crontabs of :app servers
|
169
271
|
end
|
170
272
|
|
171
|
-
every :hour, :
|
273
|
+
every :hour, roles: [:db] do
|
172
274
|
rake 'db:task' # will only be added to crontabs of :db servers
|
173
275
|
end
|
174
276
|
|
175
|
-
every :day, :
|
277
|
+
every :day, at: '12:02am' do
|
176
278
|
command "run_this_everywhere" # will be deployed to :db and :app servers
|
177
279
|
end
|
178
280
|
```
|
@@ -193,16 +295,15 @@ If your production environment uses RVM (Ruby Version Manager) you will run into
|
|
193
295
|
|
194
296
|
`rvm_trust_rvmrcs_flag=1`
|
195
297
|
|
196
|
-
This tells rvm to trust all rvmrc files
|
298
|
+
This tells rvm to trust all rvmrc files.
|
197
299
|
|
198
|
-
###
|
300
|
+
### Heroku?
|
199
301
|
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
```
|
302
|
+
No. Heroku does not support cron, instead providing [Heroku Scheduler](https://devcenter.heroku.com/articles/scheduler). If you deploy to Heroku, you should use that rather than Whenever.
|
303
|
+
|
304
|
+
### Testing
|
204
305
|
|
205
|
-
|
306
|
+
[whenever-test](https://github.com/heartbits/whenever-test) is an extension to Whenever for testing a Whenever schedule.
|
206
307
|
|
207
308
|
### Credit
|
208
309
|
|
@@ -221,8 +322,8 @@ It's a little bit dated now, but remains a good introduction.
|
|
221
322
|
|
222
323
|
----
|
223
324
|
|
224
|
-
|
325
|
+
[![Build Status](https://secure.travis-ci.org/javan/whenever.svg)](http://travis-ci.org/javan/whenever)
|
225
326
|
|
226
327
|
----
|
227
328
|
|
228
|
-
Copyright ©
|
329
|
+
Copyright © 2017 Javan Makhmali
|
data/Rakefile
CHANGED
@@ -1,17 +1,10 @@
|
|
1
|
-
|
2
|
-
require 'bundler'
|
3
|
-
rescue LoadError => e
|
4
|
-
warn("warning: Could not load bundler: #{e}")
|
5
|
-
warn(" Some rake tasks will not be defined")
|
6
|
-
else
|
7
|
-
Bundler::GemHelper.install_tasks
|
8
|
-
end
|
9
|
-
|
1
|
+
require 'bundler/gem_tasks'
|
10
2
|
require 'rake/testtask'
|
3
|
+
|
11
4
|
Rake::TestTask.new(:test) do |test|
|
12
5
|
test.libs << 'lib' << 'test'
|
13
6
|
test.pattern = 'test/{functional,unit}/**/*_test.rb'
|
14
7
|
test.verbose = true
|
15
8
|
end
|
16
9
|
|
17
|
-
task :default => :test
|
10
|
+
task :default => :test
|
data/bin/whenever
CHANGED
@@ -35,6 +35,9 @@ OptionParser.new do |opts|
|
|
35
35
|
opts.on('-r', '--roles [role1,role2]', 'Comma-separated list of server roles to generate cron jobs for') do |roles|
|
36
36
|
options[:roles] = roles.split(',').map(&:to_sym) if roles
|
37
37
|
end
|
38
|
+
opts.on('-x', '--crontab-command [command]', 'Default: crontab') do |crontab_command|
|
39
|
+
options[:crontab_command] = crontab_command if crontab_command
|
40
|
+
end
|
38
41
|
opts.on('-v', '--version') { puts "Whenever v#{Whenever::VERSION}"; exit(0) }
|
39
42
|
end.parse!
|
40
43
|
|
data/bin/wheneverize
CHANGED
@@ -18,7 +18,7 @@ OptionParser.new do |opts|
|
|
18
18
|
end
|
19
19
|
|
20
20
|
unless ARGV.empty?
|
21
|
-
if !File.
|
21
|
+
if !File.exist?(ARGV.first)
|
22
22
|
abort "`#{ARGV.first}' does not exist."
|
23
23
|
elsif !File.directory?(ARGV.first)
|
24
24
|
abort "`#{ARGV.first}' is not a directory."
|
@@ -54,13 +54,16 @@ file = 'config/schedule.rb'
|
|
54
54
|
base = ARGV.empty? ? '.' : ARGV.shift
|
55
55
|
|
56
56
|
file = File.join(base, file)
|
57
|
-
if File.
|
57
|
+
if File.exist?(file)
|
58
58
|
warn "[skip] `#{file}' already exists"
|
59
|
-
elsif File.
|
59
|
+
elsif File.exist?(file.downcase)
|
60
60
|
warn "[skip] `#{file.downcase}' exists, which could conflict with `#{file}'"
|
61
|
-
elsif !File.exists?(File.dirname(file))
|
62
|
-
warn "[skip] directory `#{File.dirname(file)}' does not exist"
|
63
61
|
else
|
62
|
+
dir = File.dirname(file)
|
63
|
+
if !File.exist?(dir)
|
64
|
+
warn "[add] creating `#{dir}'"
|
65
|
+
FileUtils.mkdir_p(dir)
|
66
|
+
end
|
64
67
|
puts "[add] writing `#{file}'"
|
65
68
|
File.open(file, "w") { |f| f.write(content) }
|
66
69
|
end
|
@@ -0,0 +1,8 @@
|
|
1
|
+
require "whenever/capistrano/v2/recipes"
|
2
|
+
|
3
|
+
Capistrano::Configuration.instance(:must_exist).load do
|
4
|
+
# Write the new cron jobs near the end.
|
5
|
+
before "deploy:finalize_update", "whenever:update_crontab"
|
6
|
+
# If anything goes wrong, undo.
|
7
|
+
after "deploy:rollback", "whenever:update_crontab"
|
8
|
+
end
|