whenever-benlangfeld 0.9.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +6 -0
- data/.travis.yml +18 -0
- data/CHANGELOG.md +333 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +260 -0
- data/Rakefile +10 -0
- data/bin/whenever +41 -0
- data/bin/wheneverize +68 -0
- data/gemfiles/activesupport4.1.gemfile +5 -0
- data/gemfiles/activesupport4.2.gemfile +5 -0
- data/lib/whenever.rb +34 -0
- data/lib/whenever/capistrano.rb +7 -0
- data/lib/whenever/capistrano/v2/hooks.rb +8 -0
- data/lib/whenever/capistrano/v2/recipes.rb +48 -0
- data/lib/whenever/capistrano/v2/support.rb +53 -0
- data/lib/whenever/capistrano/v3/tasks/whenever.rake +45 -0
- data/lib/whenever/command_line.rb +135 -0
- data/lib/whenever/cron.rb +153 -0
- data/lib/whenever/job.rb +54 -0
- data/lib/whenever/job_list.rb +155 -0
- 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 +57 -0
- data/lib/whenever/setup.rb +26 -0
- data/lib/whenever/tasks/whenever.rake +1 -0
- data/lib/whenever/version.rb +3 -0
- data/test/functional/command_line_test.rb +331 -0
- data/test/functional/output_at_test.rb +207 -0
- data/test/functional/output_default_defined_jobs_test.rb +296 -0
- data/test/functional/output_defined_job_test.rb +85 -0
- data/test/functional/output_env_test.rb +29 -0
- data/test/functional/output_jobs_for_roles_test.rb +65 -0
- data/test/functional/output_redirection_test.rb +248 -0
- data/test/test_case.rb +32 -0
- data/test/test_helper.rb +37 -0
- data/test/unit/capistrano_support_test.rb +147 -0
- data/test/unit/cron_test.rb +244 -0
- data/test/unit/job_test.rb +114 -0
- data/whenever.gemspec +27 -0
- metadata +167 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 66a0e3268620d29c398978993a97da442409fb3e
|
4
|
+
data.tar.gz: 333e726d5ebc84bc6d1d8eb995698428b60df301
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c048fe6258fb797dd108f0cb81e3c2bedf9ea9393b775c7446e9eeecb8d9b84c41fdd8f5756392c9333f0f6b589cf059adb9ec79182029fb0200cdd11430c5bf
|
7
|
+
data.tar.gz: 6c64d46e05f4755b36f6ad0da8d2e23d17182a5011280101caa323639072ba1092c6c442243734adb4944d62453262864104fa65e8979c3910e85a4d1101124a
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
language: ruby
|
2
|
+
script: bundle exec rake
|
3
|
+
|
4
|
+
before_install:
|
5
|
+
- gem install bundler
|
6
|
+
|
7
|
+
rvm:
|
8
|
+
- 1.9.3
|
9
|
+
- 2.0.0
|
10
|
+
- 2.1.0
|
11
|
+
- 2.2.0
|
12
|
+
- 2.3.0
|
13
|
+
- jruby
|
14
|
+
|
15
|
+
gemfile:
|
16
|
+
- Gemfile
|
17
|
+
- gemfiles/activesupport4.1.gemfile
|
18
|
+
- gemfiles/activesupport4.2.gemfile
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,333 @@
|
|
1
|
+
### develop
|
2
|
+
|
3
|
+
### 0.9.5 / June 12, 2016
|
4
|
+
|
5
|
+
* Improve documentation [Ben Langfeld, Spencer Fry]
|
6
|
+
|
7
|
+
* Properly support Solaris / SmartOS [Steven Williamson]
|
8
|
+
|
9
|
+
* Drop support for Ruby < 1.9.3. Test newer Ruby versions. [Javan Makhmali, Bartłomiej Kozal]
|
10
|
+
|
11
|
+
* Suport Ruby 2.3.0 and Rails 4 [Vincent Boisard]
|
12
|
+
|
13
|
+
* Set `RAILS_ENV` correctly in schedule when writing crontab from Capistrano [Ben Langfeld, Lorenzo Manacorda]
|
14
|
+
|
15
|
+
* Minor refactoring, avoidance of Ruby warnings, etc [Ben Langfeld, DV Dasari]
|
16
|
+
|
17
|
+
* Correctly pass through date expressions (e.g. `1.day`) inside job definitions [Rafael Sales]
|
18
|
+
|
19
|
+
* Prevent writing invalid cron strings [Danny Fallon, Ben Langfeld]
|
20
|
+
|
21
|
+
* Execute runner with `bundle exec` to ensure presence of app dependencies [Judith Roth]
|
22
|
+
|
23
|
+
|
24
|
+
### 0.9.4 / October 24, 2014
|
25
|
+
|
26
|
+
* Fix duplicated command line arguments when deploying to multiple servers with Cap 3. [betesh]
|
27
|
+
|
28
|
+
* Set `whenever_environment` to the current stage before defaulting to production in Cap 3 tasks. [Karthik T]
|
29
|
+
|
30
|
+
|
31
|
+
### 0.9.3 / October 5, 2014
|
32
|
+
|
33
|
+
* Drop ActiveSupport dependency [James Healy, Javan Makhmali]
|
34
|
+
|
35
|
+
* Drop shoulda for tests
|
36
|
+
|
37
|
+
* Fix `whenever:clear_crontab` Cap 3 task [Javan Makhmali]
|
38
|
+
|
39
|
+
* Avoid using tempfiles [ahoward]
|
40
|
+
|
41
|
+
|
42
|
+
### 0.9.2 / March 4, 2014
|
43
|
+
|
44
|
+
* Fix issues generating arguments for `execute` in Capistrano 3 tasks. [Javan Makhmali]
|
45
|
+
|
46
|
+
|
47
|
+
### 0.9.1 / March 2, 2014
|
48
|
+
|
49
|
+
* Pass `--roles` option to `whenever` in Capistrano 3 tasks. [betesh, Javan Makhmali]
|
50
|
+
|
51
|
+
* Allow setting `:whenever_command` for Capistrano 3. [Javan Makhmali]
|
52
|
+
|
53
|
+
* Allow `:whenever` command to be mapped in SSHKit. [Javan Makhmali]
|
54
|
+
|
55
|
+
|
56
|
+
### 0.9.0 / December 17, 2013
|
57
|
+
|
58
|
+
* Capistrano V3 support. [Philip Hallstrom]
|
59
|
+
|
60
|
+
* Process params in job templates. [Austin Ziegler]
|
61
|
+
|
62
|
+
|
63
|
+
### 0.8.4 / July 22, 2012
|
64
|
+
|
65
|
+
* Don't require schedule file when clearing. [Javan Makhmali]
|
66
|
+
|
67
|
+
* Use bin/rails when available. [Javan Makhmali]
|
68
|
+
|
69
|
+
|
70
|
+
### 0.8.3 / July 11, 2013
|
71
|
+
|
72
|
+
* Improve Cap rollback logic. [Jeroen Jacobs]
|
73
|
+
|
74
|
+
* Allow configuration of the environment variable. [andfx]
|
75
|
+
|
76
|
+
* Output option can be a callable Proc. [Li Xiao]
|
77
|
+
|
78
|
+
|
79
|
+
### 0.8.2 / January 10, 2013
|
80
|
+
|
81
|
+
* Fix Capistrano host options. [Igor Yamolov, Wes Morgan]
|
82
|
+
|
83
|
+
* Improve JRuby test support. [Igor Yamolov]
|
84
|
+
|
85
|
+
* Use correct release path in Cap task. [Wes Morgan]
|
86
|
+
|
87
|
+
|
88
|
+
### 0.8.1 / December 22nd, 2012
|
89
|
+
|
90
|
+
* Fix multiserver roles bug. [Wes Morgan]
|
91
|
+
|
92
|
+
* Refactor Cap recipes and add tests for them. [Wes Morgan]
|
93
|
+
|
94
|
+
* Fix file not found error when running under JRuby. [Wes Morgan]
|
95
|
+
|
96
|
+
* Stop interpolating template attributes with no corresponding value. [Vincent Boisard]
|
97
|
+
|
98
|
+
* Support for raw cron separated by tabs. [Étienne Barrié]
|
99
|
+
|
100
|
+
|
101
|
+
### 0.8.0 / November 8th, 2012
|
102
|
+
|
103
|
+
* Separate Capistrano recipes to allow custom execution. [Bogdan Gusiev]
|
104
|
+
|
105
|
+
* Execute `whenever:update_crontab` before `deploy:finalize_update`, not `deploy:restart`. [Michal Wrobel]
|
106
|
+
|
107
|
+
* Added a new `script` job type. [Ján Suchal]
|
108
|
+
|
109
|
+
* Use correct path in Cap task. [Alex Dean]
|
110
|
+
|
111
|
+
* Fix that setup.rb and schedule.rb were eval'd together. [Niklas H]
|
112
|
+
|
113
|
+
* New Capistrano roles feature. [Wes Morgan]
|
114
|
+
|
115
|
+
* Stop clearing the crontab during a deploy. [Javan Makhmali]
|
116
|
+
|
117
|
+
* Bump Chronic gem dependency. [rainchen]
|
118
|
+
|
119
|
+
|
120
|
+
### 0.7.3 / February 23rd, 2012
|
121
|
+
|
122
|
+
* Make included Capistrano task compatible with both new and old versions of Cap. [Giacomo Macrì]
|
123
|
+
|
124
|
+
|
125
|
+
### 0.7.2 / December 23rd, 2011
|
126
|
+
|
127
|
+
* Accept @reboot and friends as raw cron syntax. [Felix Buenemann]
|
128
|
+
|
129
|
+
* Fix clear_crontab task so it will work both standalone and during deploy. [Justin Giancola]
|
130
|
+
|
131
|
+
|
132
|
+
### 0.7.1 / December 19th, 2011
|
133
|
+
|
134
|
+
* Require thread before active_support for compatibility with Rails < 2.3.11 and RubyGems >= 1.6.0. [Micah Geisel]
|
135
|
+
|
136
|
+
* More advanced role filtering in Cap task. [Brad Gessler]
|
137
|
+
|
138
|
+
* Added whenever_variables as a configuration variable in Cap task. [Steve Agalloco]
|
139
|
+
|
140
|
+
* Escape percent signs and reject newlines in jobs. [Amir Yalon]
|
141
|
+
|
142
|
+
* Escape paths so spaces don't trip up cron. [Javan Makhmali]
|
143
|
+
|
144
|
+
* Fix ambiguous handling of 1.month with :at. #99 [Javan Makhmali]
|
145
|
+
|
146
|
+
|
147
|
+
### 0.7.0 / September 2nd, 2011
|
148
|
+
|
149
|
+
* Use mojombo's chronic, it's active again. [Javan Makhmali]
|
150
|
+
|
151
|
+
* Capistrano task enhancements. [Chris Griego]
|
152
|
+
|
153
|
+
* wheneverize command defaults to '.' directory. [Andrew Nesbitt]
|
154
|
+
|
155
|
+
* rake job_type uses bundler if detected. [Michał Szajbe]
|
156
|
+
|
157
|
+
* Indicate filename in exceptions stemming from schedule file. [Javan Makhmali]
|
158
|
+
|
159
|
+
* Don't require rubygems, bundler where possible. [Oleg Pudeyev]
|
160
|
+
|
161
|
+
* Documentation and code cleanup. [many nice people]
|
162
|
+
|
163
|
+
|
164
|
+
### 0.6.8 / May 24th, 2011
|
165
|
+
|
166
|
+
* Convert most shortcuts to seconds. every :day -> every 1.day. #129 [Javan Makhmali]
|
167
|
+
|
168
|
+
* Allow commas in raw cron syntax. #130 [Marco Bergantin, Javan Makhmali]
|
169
|
+
|
170
|
+
* Output no update message as comments. #135 [Javan Makhmali]
|
171
|
+
|
172
|
+
* require 'thread' to support Rubygems >= 1.6.0. #132 [Javan Makhmali]
|
173
|
+
|
174
|
+
|
175
|
+
### 0.6.7 / March 23rd, 2011
|
176
|
+
|
177
|
+
* Fix issue with comment block being corrupted during subsequent insertion of duplicate entries to the crontab. #123 [Jeremy (@lingmann)]
|
178
|
+
|
179
|
+
* Removed -i from default job template. #118 [Javan Makhmali]
|
180
|
+
|
181
|
+
|
182
|
+
### 0.6.6 / March 8th, 2011
|
183
|
+
|
184
|
+
* Fix unclosed identifier bug. #119 [Javan Makhmali]
|
185
|
+
|
186
|
+
|
187
|
+
### 0.6.5 / March 8th, 2011
|
188
|
+
|
189
|
+
* Preserve whitespace at the end of crontab file. #95 [Rich Meyers]
|
190
|
+
|
191
|
+
* Setting nil or blank environment variables now properly formats output. [T.J. VanSlyke]
|
192
|
+
|
193
|
+
* Allow raw cron sytax, added -i to bash job template, general cleanup. [Javan Makhmali]
|
194
|
+
|
195
|
+
|
196
|
+
### 0.6.2 / October 26th, 2010
|
197
|
+
|
198
|
+
* --clear-crontab option completely removes entries. #63 [Javan Makhmali]
|
199
|
+
|
200
|
+
* Set default :environment and :path earlier in the new setup.rb (formerly job_types/default.rb). [Javan Makhmali]
|
201
|
+
|
202
|
+
* Converted README and CHANGELOG to markdown. [Javan Makhmali]
|
203
|
+
|
204
|
+
|
205
|
+
### 0.6.1 / October 20th, 2010
|
206
|
+
|
207
|
+
* Detect script/rails file and change runner to Rails 3 style if found. [Javan Makhmali]
|
208
|
+
|
209
|
+
* Created a new :job_template system that can be applied to all commands. Wraps all in bash -l -c 'command..' by default now for better RVM support. Stopped automatically setting the PATH too. [Javan Makhmali]
|
210
|
+
|
211
|
+
* Added a built-in Capistrano recipe. [Javan Makhmali]
|
212
|
+
|
213
|
+
|
214
|
+
### 0.5.3 / September 24th, 2010
|
215
|
+
|
216
|
+
* Better regexes for replacing Whenever blocks in the crontab. #45 [Javan Makhmali]
|
217
|
+
|
218
|
+
* Preserving backslashes when updating existing crontab. #82 [Javan Makhmali]
|
219
|
+
|
220
|
+
|
221
|
+
### 0.5.2 / September 15th, 2010
|
222
|
+
|
223
|
+
* Quotes automatically escaped in jobs. [Jay Adkisson]
|
224
|
+
|
225
|
+
* Added --cut option to the command line to allow pruning of the crontab. [Peer Allan]
|
226
|
+
|
227
|
+
* Switched to aaronh-chronic which is ruby 1.9.2 compatible. [Aaron Hurley, Javan Makhmali]
|
228
|
+
|
229
|
+
* Lots of internal reorganizing; tests broken into unit and functional. [Javan Makhmali]
|
230
|
+
|
231
|
+
|
232
|
+
### 0.5.0 / June 28th, 2010
|
233
|
+
|
234
|
+
* New job_type API for writing custom jobs. Internals use this to define command, runner, and rake. [Javan Makhmali - inspired by idlefingers (Damien)]
|
235
|
+
|
236
|
+
* Jobs < 1.hour can specify an :at. [gorenje]
|
237
|
+
|
238
|
+
* --clear option to remove crontab entries for a specific [identifier]. [mraidel (Michael Raidel)]
|
239
|
+
|
240
|
+
|
241
|
+
### 0.4.2 / April 26th, 2010
|
242
|
+
|
243
|
+
* runners now cd into the app's directory and then execute. [Michael Guterl]
|
244
|
+
|
245
|
+
* Fix STDERR output redirection to file to append instead of overwrite. [weplay]
|
246
|
+
|
247
|
+
* Move require of tempfile lib to file that actually uses it. [Finn Smith]
|
248
|
+
|
249
|
+
* bugfix: comparison Time with 0 failed. #32 [Dan Hixon]
|
250
|
+
|
251
|
+
|
252
|
+
### 0.4.1 / November 30th, 2009
|
253
|
+
|
254
|
+
* exit(0) instead of just exit to make JRuby happy. [Elan Meng]
|
255
|
+
|
256
|
+
* Fixed activesupport deprecation warning by requiring active_support. #37 [Andrew Nesbitt]
|
257
|
+
|
258
|
+
|
259
|
+
### 0.4.0 / October 20th, 2009
|
260
|
+
|
261
|
+
* New output option replaces the old cron_log option for output redirection and is much more flexible. #31 [Peer Allan]
|
262
|
+
|
263
|
+
* Reorganized the lib files (http://weblog.rubyonrails.org/2009/9/1/gem-packaging-best-practices) and switched to Jeweler from Echoe.
|
264
|
+
|
265
|
+
|
266
|
+
### 0.3.7 / September 4th, 2009
|
267
|
+
|
268
|
+
* No longer tries (and fails) to combine @shortcut jobs. #20 [Javan Makhmali]
|
269
|
+
|
270
|
+
|
271
|
+
### 0.3.6 / June 15th, 2009
|
272
|
+
|
273
|
+
* Setting a PATH in the crontab automatically based on the user's PATH. [Javan Makhmali]
|
274
|
+
|
275
|
+
|
276
|
+
### 0.3.5 / June 13th, 2009
|
277
|
+
|
278
|
+
* Added ability to accept lists of every's and at's and intelligently group them. (ex: every 'monday, wednesday', :at => ['3pm', '6am']). [Sam Ruby]
|
279
|
+
|
280
|
+
* Fixed issue with new lines. #18 [Javan Makhmali]
|
281
|
+
|
282
|
+
### 0.3.1 / June 25th, 2009
|
283
|
+
|
284
|
+
* Removed activesupport gem dependency. #1 [Javan Makhmali]
|
285
|
+
|
286
|
+
* Switched to numeric days of the week for Solaris support (and probably others). #8 [Roger Ertesvåg]
|
287
|
+
|
288
|
+
|
289
|
+
### 0.3.0 / June 2nd, 2009
|
290
|
+
|
291
|
+
* Added ability to set variables on the fly from the command line (ex: whenever --set environment=staging). [Javan Makhmali]
|
292
|
+
|
293
|
+
|
294
|
+
### 0.2.2 / April 30th, 2009
|
295
|
+
|
296
|
+
* Days of week jobs can now accept an :at directive (ex: every :monday, :at => '5pm'). [David Eisinger]
|
297
|
+
|
298
|
+
* Fixed command line test so it runs without a config/schedule.rb present. [Javan Makhmali]
|
299
|
+
|
300
|
+
* Raising an exception if someone tries to specify an :at with a cron shortcut (:day, :reboot, etc) so there are no false hopes. [Javan Makhmali]
|
301
|
+
|
302
|
+
|
303
|
+
### 0.1.7 / March 5th, 2009
|
304
|
+
|
305
|
+
* Added ability to update the crontab file non-destuctively instead of only overwriting it. [Javan Makhmali -- Inspired by code submitted individually from: Tien Dung (tiendung), Tom Lea (cwninja), Kyle Maxwell (fizx), and Andrew Timberlake (andrewtimberlake) on github]
|
306
|
+
|
307
|
+
|
308
|
+
### 0.1.5 / February 19th, 2009
|
309
|
+
|
310
|
+
* Fixed load path so Whenever's files don't conflict with anything in Rails. Thanks Ryan Koopmans. [Javan Makhmali]
|
311
|
+
|
312
|
+
|
313
|
+
### 0.1.4 / February 17th, 2009
|
314
|
+
|
315
|
+
* Added --load-file and --user opts to whenever binary. [Javan Makhmali]
|
316
|
+
|
317
|
+
|
318
|
+
### 0.1.3 / February 16th, 2009
|
319
|
+
|
320
|
+
* Added 'rake' helper for defining scheduled rake tasks. [Javan Makhmali]
|
321
|
+
|
322
|
+
* Renamed :cron_environment and :cron_path to :enviroment and :path for better (word) compatibility with rake tasks. [Javan Makhmali]
|
323
|
+
|
324
|
+
* Improved test load paths so tests can be run individually. [Javan Makhmali]
|
325
|
+
|
326
|
+
* Got rid of already initialized constant warning. [Javan Makhmali]
|
327
|
+
|
328
|
+
* Requiring specific gem versions: Chronic >=0.2.3 and activesupport >= 1.3.0 [Javan Makhmali]
|
329
|
+
|
330
|
+
|
331
|
+
### 0.1.0 / February 15th, 2009
|
332
|
+
|
333
|
+
* Initial release [Javan Makhmali]
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2016 Javan Makhmali
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person
|
4
|
+
obtaining a copy of this software and associated documentation
|
5
|
+
files (the "Software"), to deal in the Software without
|
6
|
+
restriction, including without limitation the rights to use,
|
7
|
+
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
8
|
+
copies of the Software, and to permit persons to whom the
|
9
|
+
Software is furnished to do so, subject to the following
|
10
|
+
conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be
|
13
|
+
included in all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
17
|
+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
19
|
+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
20
|
+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
21
|
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
22
|
+
OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,260 @@
|
|
1
|
+
Whenever is a Ruby gem that provides a clear syntax for writing and deploying cron jobs.
|
2
|
+
|
3
|
+
### Installation
|
4
|
+
|
5
|
+
```sh
|
6
|
+
$ gem install whenever
|
7
|
+
```
|
8
|
+
|
9
|
+
Or with Bundler in your Gemfile.
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'whenever', :require => false
|
13
|
+
```
|
14
|
+
|
15
|
+
### Getting started
|
16
|
+
|
17
|
+
```sh
|
18
|
+
$ cd /apps/my-great-project
|
19
|
+
$ wheneverize .
|
20
|
+
```
|
21
|
+
|
22
|
+
This will create an initial `config/schedule.rb` file for you.
|
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
|
+
You can list installed cron jobs using `crontab -l`.
|
38
|
+
|
39
|
+
Run `whenever --help` for a complete list of options for selecting the schedule to use, setting variables in the schedule, selecting a user as which to install the crontab, etc.
|
40
|
+
|
41
|
+
### Example schedule.rb file
|
42
|
+
|
43
|
+
```ruby
|
44
|
+
every 3.hours do
|
45
|
+
runner "MyModel.some_process"
|
46
|
+
rake "my:rake:task"
|
47
|
+
command "/usr/bin/my_great_command"
|
48
|
+
end
|
49
|
+
|
50
|
+
every 1.day, :at => '4:30 am' do
|
51
|
+
runner "MyModel.task_to_run_at_four_thirty_in_the_morning"
|
52
|
+
end
|
53
|
+
|
54
|
+
every :hour do # Many shortcuts available: :hour, :day, :month, :year, :reboot
|
55
|
+
runner "SomeModel.ladeeda"
|
56
|
+
end
|
57
|
+
|
58
|
+
every :sunday, :at => '12pm' do # Use any day of the week or :weekend, :weekday
|
59
|
+
runner "Task.do_something_great"
|
60
|
+
end
|
61
|
+
|
62
|
+
every '0 0 27-31 * *' do
|
63
|
+
command "echo 'you can use raw cron syntax too'"
|
64
|
+
end
|
65
|
+
|
66
|
+
# run this task only on servers with the :app role in Capistrano
|
67
|
+
# see Capistrano roles section below
|
68
|
+
every :day, :at => '12:20am', :roles => [:app] do
|
69
|
+
rake "app_server:task"
|
70
|
+
end
|
71
|
+
```
|
72
|
+
|
73
|
+
### Define your own job types
|
74
|
+
|
75
|
+
Whenever ships with three pre-defined job types: command, runner, and rake. You can define your own with `job_type`.
|
76
|
+
|
77
|
+
For example:
|
78
|
+
|
79
|
+
```ruby
|
80
|
+
job_type :awesome, '/usr/local/bin/awesome :task :fun_level'
|
81
|
+
|
82
|
+
every 2.hours do
|
83
|
+
awesome "party", :fun_level => "extreme"
|
84
|
+
end
|
85
|
+
```
|
86
|
+
|
87
|
+
Would run `/usr/local/bin/awesome party extreme` every two hours. `:task` is always replaced with the first argument, and any additional `:whatevers` are replaced with the options passed in or by variables that have been defined with `set`.
|
88
|
+
|
89
|
+
The default job types that ship with Whenever are defined like so:
|
90
|
+
|
91
|
+
```ruby
|
92
|
+
job_type :command, ":task :output"
|
93
|
+
job_type :rake, "cd :path && :environment_variable=:environment bundle exec rake :task --silent :output"
|
94
|
+
job_type :runner, "cd :path && bin/rails runner -e :environment ':task' :output"
|
95
|
+
job_type :script, "cd :path && :environment_variable=:environment bundle exec script/:task :output"
|
96
|
+
```
|
97
|
+
|
98
|
+
Pre-Rails 3 apps and apps that don't use Bundler will redefine the `rake` and `runner` jobs respectively to function correctly.
|
99
|
+
|
100
|
+
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>
|
101
|
+
|
102
|
+
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>
|
103
|
+
|
104
|
+
You can change this by setting your own `:job_template`.
|
105
|
+
|
106
|
+
```ruby
|
107
|
+
set :job_template, "bash -l -c ':job'"
|
108
|
+
```
|
109
|
+
|
110
|
+
Or set the job_template to nil to have your jobs execute normally.
|
111
|
+
|
112
|
+
```ruby
|
113
|
+
set :job_template, nil
|
114
|
+
```
|
115
|
+
|
116
|
+
### Capistrano integration
|
117
|
+
|
118
|
+
Use the built-in Capistrano recipe for easy crontab updates with deploys. For Capistrano V3, see the next section.
|
119
|
+
|
120
|
+
In your "config/deploy.rb" file:
|
121
|
+
|
122
|
+
```ruby
|
123
|
+
require "whenever/capistrano"
|
124
|
+
```
|
125
|
+
|
126
|
+
Take a look at the recipe for options you can set. <https://github.com/javan/whenever/blob/master/lib/whenever/capistrano/v2/recipes.rb>
|
127
|
+
For example, if you're using bundler do this:
|
128
|
+
|
129
|
+
```ruby
|
130
|
+
set :whenever_command, "bundle exec whenever"
|
131
|
+
require "whenever/capistrano"
|
132
|
+
```
|
133
|
+
|
134
|
+
If you are using different environments (such as staging, production), then you may want to do this:
|
135
|
+
|
136
|
+
```ruby
|
137
|
+
set :whenever_environment, defer { stage }
|
138
|
+
require "whenever/capistrano"
|
139
|
+
```
|
140
|
+
|
141
|
+
The capistrano variable `:stage` should be the one holding your environment name. This will make the correct `:environment` available in your `schedule.rb`.
|
142
|
+
|
143
|
+
If both your environments are on the same server you'll want to namespace them or they'll overwrite each other when you deploy:
|
144
|
+
|
145
|
+
```ruby
|
146
|
+
set :whenever_environment, defer { stage }
|
147
|
+
set :whenever_identifier, defer { "#{application}_#{stage}" }
|
148
|
+
require "whenever/capistrano"
|
149
|
+
```
|
150
|
+
|
151
|
+
### Capistrano V3 Integration
|
152
|
+
|
153
|
+
In your "Capfile" file:
|
154
|
+
|
155
|
+
```ruby
|
156
|
+
require "whenever/capistrano"
|
157
|
+
```
|
158
|
+
|
159
|
+
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:
|
160
|
+
|
161
|
+
```ruby
|
162
|
+
set :whenever_identifier, ->{ "#{fetch(:application)}_#{fetch(:stage)}" }
|
163
|
+
```
|
164
|
+
|
165
|
+
The Capistrano integration by default expects the `:application` variable to be set in order to scope jobs in the crontab.
|
166
|
+
|
167
|
+
### Capistrano roles
|
168
|
+
|
169
|
+
The first thing to know about the new roles support is that it is entirely
|
170
|
+
optional and backwards-compatible. If you don't need different jobs running on
|
171
|
+
different servers in your capistrano deployment, then you can safely stop reading
|
172
|
+
now and everything should just work the same way it always has.
|
173
|
+
|
174
|
+
When you define a job in your schedule.rb file, by default it will be deployed to
|
175
|
+
all servers in the whenever_roles list (which defaults to [:db]).
|
176
|
+
|
177
|
+
However, if you want to restrict certain jobs to only run on subset of servers,
|
178
|
+
you can add a :roles => [...] argument to their definitions. **Make sure to add
|
179
|
+
that role to the whenever_roles list in your deploy.rb.**
|
180
|
+
|
181
|
+
When you run `cap deploy`, jobs with a :roles list specified will only be added to
|
182
|
+
the crontabs on servers with one or more of the roles in that list.
|
183
|
+
|
184
|
+
Jobs with no :roles argument will be deployed to all servers in the whenever_roles
|
185
|
+
list. This is to maintain backward compatibility with previous releases of whenever.
|
186
|
+
|
187
|
+
So, for example, with the default whenever_roles of [:db], a job like this would be
|
188
|
+
deployed to all servers with the :db role:
|
189
|
+
|
190
|
+
```ruby
|
191
|
+
every :day, :at => '12:20am' do
|
192
|
+
rake 'foo:bar'
|
193
|
+
end
|
194
|
+
```
|
195
|
+
|
196
|
+
If we set whenever_roles to [:db, :app] in deploy.rb, and have the following
|
197
|
+
jobs in schedule.rb:
|
198
|
+
|
199
|
+
```ruby
|
200
|
+
every :day, :at => '1:37pm', :roles => [:app] do
|
201
|
+
rake 'app:task' # will only be added to crontabs of :app servers
|
202
|
+
end
|
203
|
+
|
204
|
+
every :hour, :roles => [:db] do
|
205
|
+
rake 'db:task' # will only be added to crontabs of :db servers
|
206
|
+
end
|
207
|
+
|
208
|
+
every :day, :at => '12:02am' do
|
209
|
+
command "run_this_everywhere" # will be deployed to :db and :app servers
|
210
|
+
end
|
211
|
+
```
|
212
|
+
|
213
|
+
Here are the basic rules:
|
214
|
+
|
215
|
+
1. If a server's role isn't listed in whenever_roles, it will *never* have jobs
|
216
|
+
added to its crontab.
|
217
|
+
1. If a server's role is listed in the whenever_roles, then it will have all
|
218
|
+
jobs added to its crontab that either list that role in their :roles arg or
|
219
|
+
that don't have a :roles arg.
|
220
|
+
1. If a job has a :roles arg but that role isn't in the whenever_roles list,
|
221
|
+
that job *will not* be deployed to any server.
|
222
|
+
|
223
|
+
### RVM Integration
|
224
|
+
|
225
|
+
If your production environment uses RVM (Ruby Version Manager) you will run into a gotcha that causes your cron jobs to hang. This is not directly related to Whenever, and can be tricky to debug. Your .rvmrc files must be trusted or else the cron jobs will hang waiting for the file to be trusted. A solution is to disable the prompt by adding this line to your user rvm file in `~/.rvmrc`
|
226
|
+
|
227
|
+
`rvm_trust_rvmrcs_flag=1`
|
228
|
+
|
229
|
+
This tells rvm to trust all rvmrc files.
|
230
|
+
|
231
|
+
### Heroku?
|
232
|
+
|
233
|
+
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.
|
234
|
+
|
235
|
+
### Testing
|
236
|
+
|
237
|
+
[whenever-test](https://github.com/heartbits/whenever-test) is an extension to Whenever for testing a Whenever schedule.
|
238
|
+
|
239
|
+
### Credit
|
240
|
+
|
241
|
+
Whenever was created for use at Inkling (<http://inklingmarkets.com>). Their take on it: <http://blog.inklingmarkets.com/2009/02/whenever-easy-way-to-do-cron-jobs-from.html>
|
242
|
+
|
243
|
+
Thanks to all the contributors who have made it even better: <http://github.com/javan/whenever/contributors>
|
244
|
+
|
245
|
+
### Discussion / Feedback / Issues / Bugs
|
246
|
+
|
247
|
+
For general discussion and questions, please use the google group: <http://groups.google.com/group/whenever-gem>
|
248
|
+
|
249
|
+
If you've found a genuine bug or issue, please use the Issues section on github: <http://github.com/javan/whenever/issues>
|
250
|
+
|
251
|
+
Ryan Bates created a great Railscast about Whenever: <http://railscasts.com/episodes/164-cron-in-ruby>
|
252
|
+
It's a little bit dated now, but remains a good introduction.
|
253
|
+
|
254
|
+
----
|
255
|
+
|
256
|
+
[![Build Status](https://secure.travis-ci.org/javan/whenever.png)](http://travis-ci.org/javan/whenever)
|
257
|
+
|
258
|
+
----
|
259
|
+
|
260
|
+
Copyright © 2016 Javan Makhmali
|