lowang-whenever 0.7.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ .DS_Store
2
+ pkg
3
+ doc
4
+ .*.sw[a-z]
5
+ Gemfile.lock
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ rvm:
2
+ - 1.8.7
3
+ - 1.9.2
4
+ - ree
5
+ - jruby
data/CHANGELOG.md ADDED
@@ -0,0 +1,187 @@
1
+ ### 0.7.0 / September 2nd, 2011
2
+
3
+ * Use mojombo's chronic, it's active again. [Javan Makhmali]
4
+
5
+ * Capistrano task enhancements. [Chris Griego]
6
+
7
+ * wheneverize command defaults to '.' directory. [Andrew Nesbitt]
8
+
9
+ * rake job_type uses bundler if detected. [Michał Szajbe]
10
+
11
+ * Indicate filename in exceptions stemming from schedule file. [Javan Makhmali]
12
+
13
+ * Don't require rubygems, bundler where possible. [Oleg Pudeyev]
14
+
15
+ * Documentation and code cleanup. [many nice people]
16
+
17
+
18
+ ### 0.6.8 / May 24th, 2011
19
+
20
+ * Convert most shortcuts to seconds. every :day -> every 1.day. #129 [Javan Makhmali]
21
+
22
+ * Allow commas in raw cron syntax. #130 [Marco Bergantin, Javan Makhmali]
23
+
24
+ * Output no update message as comments. #135 [Javan Makhmali]
25
+
26
+ * require 'thread' to support Rubygems >= 1.6.0. #132 [Javan Makhmali]
27
+
28
+
29
+ ### 0.6.7 / March 23rd, 2011
30
+
31
+ * Fix issue with comment block being corrupted during subsequent insertion of duplicate entries to the crontab. #123 [Jeremy (@lingmann)]
32
+
33
+ * Removed -i from default job template. #118 [Javan Makhmali]
34
+
35
+
36
+ ### 0.6.6 / March 8th, 2011
37
+
38
+ * Fix unclosed identifier bug. #119 [Javan Makhmali]
39
+
40
+
41
+ ### 0.6.5 / March 8th, 2011
42
+
43
+ * Preserve whitespace at the end of crontab file. #95 [Rich Meyers]
44
+
45
+ * Setting nil or blank environment variables now properly formats output. [T.J. VanSlyke]
46
+
47
+ * Allow raw cron sytax, added -i to bash job template, general cleanup. [Javan Makhmali]
48
+
49
+
50
+ ### 0.6.2 / October 26th, 2010
51
+
52
+ * --clear-crontab option completely removes entries. #63 [Javan Makhmali]
53
+
54
+ * Set default :environment and :path earlier in the new setup.rb (formerly job_types/default.rb). [Javan Makhmali]
55
+
56
+ * Converted README and CHANGELOG to markdown. [Javan Makhmali]
57
+
58
+
59
+ ### 0.6.1 / October 20th, 2010
60
+
61
+ * Detect script/rails file and change runner to Rails 3 style if found. [Javan Makhmali]
62
+
63
+ * 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]
64
+
65
+ * Added a built-in Capistrano recipe. [Javan Makhmali]
66
+
67
+
68
+ ### 0.5.3 / September 24th, 2010
69
+
70
+ * Better regexes for replacing Whenever blocks in the crontab. #45 [Javan Makhmali]
71
+
72
+ * Preserving backslashes when updating existing crontab. #82 [Javan Makhmali]
73
+
74
+
75
+ ### 0.5.2 / September 15th, 2010
76
+
77
+ * Quotes automatically escaped in jobs. [Jay Adkisson]
78
+
79
+ * Added --cut option to the command line to allow pruning of the crontab. [Peer Allan]
80
+
81
+ * Switched to aaronh-chronic which is ruby 1.9.2 compatible. [Aaron Hurley, Javan Makhmali]
82
+
83
+ * Lots of internal reorganizing; tests broken into unit and functional. [Javan Makhmali]
84
+
85
+
86
+ ### 0.5.0 / June 28th, 2010
87
+
88
+ * New job_type API for writing custom jobs. Internals use this to define command, runner, and rake. [Javan Makhmali - inspired by idlefingers (Damien)]
89
+
90
+ * Jobs < 1.hour can specify an :at. [gorenje]
91
+
92
+ * --clear option to remove crontab entries for a specific [identifier]. [mraidel (Michael Raidel)]
93
+
94
+
95
+ ### 0.4.2 / April 26th, 2010
96
+
97
+ * runners now cd into the app's directory and then execute. [Michael Guterl]
98
+
99
+ * Fix STDERR output redirection to file to append instead of overwrite. [weplay]
100
+
101
+ * Move require of tempfile lib to file that actually uses it. [Finn Smith]
102
+
103
+ * bugfix: comparison Time with 0 failed. #32 [Dan Hixon]
104
+
105
+
106
+ ### 0.4.1 / November 30th, 2009
107
+
108
+ * exit(0) instead of just exit to make JRuby happy. [Elan Meng]
109
+
110
+ * Fixed activesupport deprecation warning by requiring active_support. #37 [Andrew Nesbitt]
111
+
112
+
113
+ ### 0.4.0 / October 20th, 2009
114
+
115
+ * New output option replaces the old cron_log option for output redirection and is much more flexible. #31 [Peer Allan]
116
+
117
+ * Reorganized the lib files (http://weblog.rubyonrails.org/2009/9/1/gem-packaging-best-practices) and switched to Jeweler from Echoe.
118
+
119
+
120
+ ### 0.3.7 / September 4th, 2009
121
+
122
+ * No longer tries (and fails) to combine @shortcut jobs. #20 [Javan Makhmali]
123
+
124
+
125
+ ### 0.3.6 / June 15th, 2009
126
+
127
+ * Setting a PATH in the crontab automatically based on the user's PATH. [Javan Makhmali]
128
+
129
+
130
+ ### 0.3.5 / June 13th, 2009
131
+
132
+ * Added ability to accept lists of every's and at's and intelligently group them. (ex: every 'monday, wednesday', :at => ['3pm', '6am']). [Sam Ruby]
133
+
134
+ * Fixed issue with new lines. #18 [Javan Makhmali]
135
+
136
+ ### 0.3.1 / June 25th, 2009
137
+
138
+ * Removed activesupport gem dependency. #1 [Javan Makhmali]
139
+
140
+ * Switched to numeric days of the week for Solaris support (and probably others). #8 [Roger Ertesvåg]
141
+
142
+
143
+ ### 0.3.0 / June 2nd, 2009
144
+
145
+ * Added ability to set variables on the fly from the command line (ex: whenever --set environment=staging). [Javan Makhmali]
146
+
147
+
148
+ ### 0.2.2 / April 30th, 2009
149
+
150
+ * Days of week jobs can now accept an :at directive (ex: every :monday, :at => '5pm'). [David Eisinger]
151
+
152
+ * Fixed command line test so it runs without a config/schedule.rb present. [Javan Makhmali]
153
+
154
+ * 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]
155
+
156
+
157
+ ### 0.1.7 / March 5th, 2009
158
+
159
+ * 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]
160
+
161
+
162
+ ### 0.1.5 / February 19th, 2009
163
+
164
+ * Fixed load path so Whenever's files don't conflict with anything in Rails. Thanks Ryan Koopmans. [Javan Makhmali]
165
+
166
+
167
+ ### 0.1.4 / February 17th, 2009
168
+
169
+ * Added --load-file and --user opts to whenever binary. [Javan Makhmali]
170
+
171
+
172
+ ### 0.1.3 / February 16th, 2009
173
+
174
+ * Added 'rake' helper for defining scheduled rake tasks. [Javan Makhmali]
175
+
176
+ * Renamed :cron_environment and :cron_path to :enviroment and :path for better (word) compatibility with rake tasks. [Javan Makhmali]
177
+
178
+ * Improved test load paths so tests can be run individually. [Javan Makhmali]
179
+
180
+ * Got rid of already initialized constant warning. [Javan Makhmali]
181
+
182
+ * Requiring specific gem versions: Chronic >=0.2.3 and activesupport >= 1.3.0 [Javan Makhmali]
183
+
184
+
185
+ ### 0.1.0 / February 15th, 2009
186
+
187
+ * Initial release [Javan Makhmali]
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in newever.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2011 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,165 @@
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
+ ### Example schedule.rb file
25
+
26
+ ```ruby
27
+ every 3.hours do
28
+ runner "MyModel.some_process"
29
+ rake "my:rake:task"
30
+ command "/usr/bin/my_great_command"
31
+ end
32
+
33
+ every 1.day, :at => '4:30 am' do
34
+ runner "MyModel.task_to_run_at_four_thirty_in_the_morning"
35
+ end
36
+
37
+ every :hour do # Many shortcuts available: :hour, :day, :month, :year, :reboot
38
+ runner "SomeModel.ladeeda"
39
+ end
40
+
41
+ every :sunday, :at => '12pm' do # Use any day of the week or :weekend, :weekday
42
+ runner "Task.do_something_great"
43
+ end
44
+
45
+ every '0 0 27-31 * *' do
46
+ command "echo 'you can use raw cron syntax too'"
47
+ end
48
+ ```
49
+
50
+ ### Define your own job types
51
+
52
+ Whenever ships with three pre-defined job types: command, runner, and rake. You can define your own with `job_type`.
53
+
54
+ For example:
55
+
56
+ ```ruby
57
+ job_type :awesome, '/usr/local/bin/awesome :task :fun_level'
58
+
59
+ every 2.hours do
60
+ awesome "party", :fun_level => "extreme"
61
+ end
62
+ ```
63
+
64
+ 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`.
65
+
66
+ The default job types that ship with Whenever are defined like so:
67
+
68
+ ```ruby
69
+ job_type :command, ":task :output"
70
+ job_type :rake, "cd :path && RAILS_ENV=:environment bundle exec rake :task --silent :output"
71
+ job_type :runner, "cd :path && script/rails runner -e :environment ':task' :output"
72
+ ```
73
+
74
+ Pre-Rails 3 apps and apps that don't use Bundler will redefine the `rake` and `runner` jobs respectively to function correctly.
75
+
76
+ 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>
77
+
78
+ 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>
79
+
80
+ You can change this by setting your own `:job_template`.
81
+
82
+ ```ruby
83
+ set :job_template, "bash -l -c ':job'"
84
+ ```
85
+
86
+ Or set the job_template to nil to have your jobs execute normally.
87
+
88
+ ```ruby
89
+ set :job_template, nil
90
+ ```
91
+
92
+ ### Capistrano integration
93
+
94
+ Use the built-in Capistrano recipe for easy crontab updates with deploys.
95
+
96
+ In your "config/deploy.rb" file:
97
+
98
+ ```ruby
99
+ require "whenever/capistrano"
100
+ ```
101
+
102
+ Take a look at the recipe for options you can set. <http://github.com/javan/whenever/blob/master/lib/whenever/capistrano.rb>
103
+ For example, if you're using bundler do this:
104
+
105
+ ```ruby
106
+ set :whenever_command, "bundle exec whenever"
107
+ require "whenever/capistrano"
108
+ ```
109
+
110
+ If you are using different environments (such as staging, production), then you may want to do this:
111
+
112
+ ```ruby
113
+ set :whenever_environment, defer { stage }
114
+ require "whenever/capistrano"
115
+ ```
116
+
117
+ The capistrano variable `:stage` should be the one holding your environment name. This will make the correct `:environment` available in your `schedule.rb`.
118
+
119
+ If both your environments are on the same server you'll want to namespace them or they'll overwrite each other when you deploy:
120
+
121
+ ```ruby
122
+ set :whenever_environment, defer { stage }
123
+ set :whenever_identifier, defer { "#{application}_#{stage}" }
124
+ require "whenever/capistrano"
125
+ ```
126
+
127
+ ### RVM Integration
128
+
129
+ 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`
130
+
131
+ `rvm_trust_rvmrcs_flag=1`
132
+
133
+ This tells rvm to trust all rvmrc files, which is documented here: http://wayneeseguin.beginrescueend.com/2010/08/22/ruby-environment-version-manager-rvm-1-0-0/
134
+
135
+ ### The `whenever` command
136
+
137
+ ```sh
138
+ $ cd /apps/my-great-project
139
+ $ whenever
140
+ ```
141
+
142
+ This will simply show you your `schedule.rb` file converted to cron syntax. It does not read or write your crontab file. Run `whenever --help` for a complete list of options.
143
+
144
+ ### Credit
145
+
146
+ 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>
147
+
148
+ Thanks to all the contributors who have made it even better: <http://github.com/javan/whenever/contributors>
149
+
150
+ ### Discussion / Feedback / Issues / Bugs
151
+
152
+ For general discussion and questions, please use the google group: <http://groups.google.com/group/whenever-gem>
153
+
154
+ If you've found a genuine bug or issue, please use the Issues section on github: <http://github.com/javan/whenever/issues>
155
+
156
+ Ryan Bates created a great Railscast about Whenever: <http://railscasts.com/episodes/164-cron-in-ruby>
157
+ It's a little bit dated now, but remains a good introduction.
158
+
159
+ ----
160
+
161
+ Compatible with Ruby 1.8.7-1.9.2, JRuby, and Rubinius. [![Build Status](https://secure.travis-ci.org/javan/whenever.png)](http://travis-ci.org/javan/whenever)
162
+
163
+ ----
164
+
165
+ Copyright &copy; 2011 Javan Makhmali
data/Rakefile ADDED
@@ -0,0 +1,17 @@
1
+ begin
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
+
10
+ require 'rake/testtask'
11
+ Rake::TestTask.new(:test) do |test|
12
+ test.libs << 'lib' << 'test'
13
+ test.pattern = 'test/{functional,unit}/**/*_test.rb'
14
+ test.verbose = true
15
+ end
16
+
17
+ task :default => :test
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.0
data/bin/whenever ADDED
@@ -0,0 +1,38 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'optparse'
4
+ require 'whenever'
5
+ require 'whenever/version'
6
+
7
+ options = {}
8
+
9
+ OptionParser.new do |opts|
10
+ opts.banner = "Usage: whenever [options]"
11
+ opts.on('-i', '--update-crontab [identifier]', 'Default: full path to schedule.rb file') do |identifier|
12
+ options[:update] = true
13
+ options[:identifier] = identifier if identifier
14
+ end
15
+ opts.on('-w', '--write-crontab [identifier]', 'Default: full path to schedule.rb file') do |identifier|
16
+ options[:write] = true
17
+ options[:identifier] = identifier if identifier
18
+ end
19
+ opts.on('-c', '--clear-crontab [identifier]') do |identifier|
20
+ options[:clear] = true
21
+ options[:identifier] = identifier if identifier
22
+ end
23
+ opts.on('-s', '--set [variables]', 'Example: --set \'environment=staging&path=/my/sweet/path\'') do |set|
24
+ options[:set] = set if set
25
+ end
26
+ opts.on('-f', '--load-file [schedule file]', 'Default: config/schedule.rb') do |file|
27
+ options[:file] = file if file
28
+ end
29
+ opts.on('-u', '--user [user]', 'Default: current user') do |user|
30
+ options[:user] = user if user
31
+ end
32
+ opts.on('-k', '--cut [lines]', 'Cut lines from the top of the cronfile') do |lines|
33
+ options[:cut] = lines.to_i if lines
34
+ end
35
+ opts.on('-v', '--version') { puts "Whenever v#{Whenever::VERSION}"; exit(0) }
36
+ end.parse!
37
+
38
+ Whenever::CommandLine.execute(options)