whenever 0.6.8 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +5 -0
- data/CHANGELOG.md +17 -0
- data/LICENSE +22 -0
- data/README.md +90 -75
- data/Rakefile +8 -2
- data/bin/whenever +2 -2
- data/bin/wheneverize +9 -10
- data/lib/whenever.rb +16 -8
- data/lib/whenever/capistrano.rb +48 -18
- data/lib/whenever/command_line.rb +0 -2
- data/lib/whenever/cron.rb +0 -1
- data/lib/whenever/job.rb +0 -2
- data/lib/whenever/job_list.rb +10 -13
- data/lib/whenever/output_redirection.rb +0 -2
- data/lib/whenever/setup.rb +9 -3
- data/lib/whenever/version.rb +1 -1
- data/test/functional/output_at_test.rb +2 -2
- data/test/functional/output_default_defined_jobs_test.rb +20 -2
- data/test/test_helper.rb +0 -2
- data/whenever.gemspec +13 -4
- metadata +77 -92
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,20 @@
|
|
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
|
+
|
1
18
|
### 0.6.8 / May 24th, 2011
|
2
19
|
|
3
20
|
* Convert most shortcuts to seconds. every :day -> every 1.day. #129 [Javan Makhmali]
|
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
CHANGED
@@ -1,47 +1,51 @@
|
|
1
|
-
### Introduction
|
2
|
-
|
3
1
|
Whenever is a Ruby gem that provides a clear syntax for writing and deploying cron jobs.
|
4
2
|
|
5
3
|
### Installation
|
6
|
-
|
7
|
-
|
4
|
+
|
5
|
+
```sh
|
6
|
+
$ gem install whenever
|
7
|
+
```
|
8
8
|
|
9
9
|
Or with Bundler in your Gemfile.
|
10
10
|
|
11
|
-
|
11
|
+
```ruby
|
12
|
+
gem 'whenever', :require => false
|
13
|
+
```
|
12
14
|
|
13
15
|
### Getting started
|
14
16
|
|
15
|
-
|
16
|
-
|
17
|
+
```sh
|
18
|
+
$ cd /apps/my-great-project
|
19
|
+
$ wheneverize .
|
20
|
+
```
|
17
21
|
|
18
|
-
This will create an initial
|
22
|
+
This will create an initial `config/schedule.rb` file for you.
|
19
23
|
|
20
24
|
### Example schedule.rb file
|
21
|
-
|
22
|
-
every 3.hours do
|
23
|
-
runner "MyModel.some_process"
|
24
|
-
rake "my:rake:task"
|
25
|
-
command "/usr/bin/my_great_command"
|
26
|
-
end
|
27
25
|
|
28
|
-
|
29
|
-
|
30
|
-
|
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
|
31
32
|
|
32
|
-
|
33
|
-
|
34
|
-
|
33
|
+
every 1.day, :at => '4:30 am' do
|
34
|
+
runner "MyModel.task_to_run_at_four_thirty_in_the_morning"
|
35
|
+
end
|
35
36
|
|
36
|
-
|
37
|
-
|
38
|
-
|
37
|
+
every :hour do # Many shortcuts available: :hour, :day, :month, :year, :reboot
|
38
|
+
runner "SomeModel.ladeeda"
|
39
|
+
end
|
39
40
|
|
40
|
-
|
41
|
-
|
42
|
-
|
41
|
+
every :sunday, :at => '12pm' do # Use any day of the week or :weekend, :weekday
|
42
|
+
runner "Task.do_something_great"
|
43
|
+
end
|
43
44
|
|
44
|
-
|
45
|
+
every '0 0 27-31 * *' do
|
46
|
+
command "echo 'you can use raw cron syntax too'"
|
47
|
+
end
|
48
|
+
```
|
45
49
|
|
46
50
|
### Define your own job types
|
47
51
|
|
@@ -49,23 +53,25 @@ Whenever ships with three pre-defined job types: command, runner, and rake. You
|
|
49
53
|
|
50
54
|
For example:
|
51
55
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
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
|
+
```
|
57
63
|
|
58
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`.
|
59
65
|
|
60
66
|
The default job types that ship with Whenever are defined like so:
|
61
67
|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
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
|
+
```
|
67
73
|
|
68
|
-
|
74
|
+
Pre-Rails 3 apps and apps that don't use Bundler will redefine the `rake` and `runner` jobs respectively to function correctly.
|
69
75
|
|
70
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>
|
71
77
|
|
@@ -73,13 +79,15 @@ All jobs are by default run with `bash -l -c 'command...'`. Among other things,
|
|
73
79
|
|
74
80
|
You can change this by setting your own `:job_template`.
|
75
81
|
|
76
|
-
|
82
|
+
```ruby
|
83
|
+
set :job_template, "bash -l -c ':job'"
|
84
|
+
```
|
77
85
|
|
78
86
|
Or set the job_template to nil to have your jobs execute normally.
|
79
87
|
|
80
|
-
|
81
|
-
|
82
|
-
|
88
|
+
```ruby
|
89
|
+
set :job_template, nil
|
90
|
+
```
|
83
91
|
|
84
92
|
### Capistrano integration
|
85
93
|
|
@@ -87,27 +95,51 @@ Use the built-in Capistrano recipe for easy crontab updates with deploys.
|
|
87
95
|
|
88
96
|
In your "config/deploy.rb" file:
|
89
97
|
|
90
|
-
|
98
|
+
```ruby
|
99
|
+
require "whenever/capistrano"
|
100
|
+
```
|
91
101
|
|
92
102
|
Take a look at the recipe for options you can set. <http://github.com/javan/whenever/blob/master/lib/whenever/capistrano.rb>
|
93
103
|
For example, if you're using bundler do this:
|
94
104
|
|
95
|
-
|
96
|
-
|
105
|
+
```ruby
|
106
|
+
set :whenever_command, "bundle exec whenever"
|
107
|
+
require "whenever/capistrano"
|
108
|
+
```
|
97
109
|
|
98
110
|
If you are using different environments (such as staging, production), then you may want to do this:
|
99
111
|
|
100
|
-
|
101
|
-
|
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`.
|
102
118
|
|
103
|
-
|
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/
|
104
134
|
|
105
135
|
### The `whenever` command
|
106
136
|
|
107
|
-
|
108
|
-
|
137
|
+
```sh
|
138
|
+
$ cd /apps/my-great-project
|
139
|
+
$ whenever
|
140
|
+
```
|
109
141
|
|
110
|
-
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.
|
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.
|
111
143
|
|
112
144
|
### Credit
|
113
145
|
|
@@ -124,27 +156,10 @@ If you've found a genuine bug or issue, please use the Issues section on github:
|
|
124
156
|
Ryan Bates created a great Railscast about Whenever: <http://railscasts.com/episodes/164-cron-in-ruby>
|
125
157
|
It's a little bit dated now, but remains a good introduction.
|
126
158
|
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
restriction, including without limitation the rights to use,
|
135
|
-
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
136
|
-
copies of the Software, and to permit persons to whom the
|
137
|
-
Software is furnished to do so, subject to the following
|
138
|
-
conditions:
|
139
|
-
|
140
|
-
The above copyright notice and this permission notice shall be
|
141
|
-
included in all copies or substantial portions of the Software.
|
142
|
-
|
143
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
144
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
145
|
-
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
146
|
-
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
147
|
-
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
148
|
-
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
149
|
-
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
150
|
-
OTHER DEALINGS IN THE SOFTWARE.
|
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 © 2011 Javan Makhmali
|
data/Rakefile
CHANGED
@@ -1,5 +1,11 @@
|
|
1
|
-
|
2
|
-
|
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
|
3
9
|
|
4
10
|
require 'rake/testtask'
|
5
11
|
Rake::TestTask.new(:test) do |test|
|
data/bin/whenever
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
require 'rubygems'
|
4
3
|
require 'optparse'
|
5
4
|
require 'whenever'
|
5
|
+
require 'whenever/version'
|
6
6
|
|
7
7
|
options = {}
|
8
8
|
|
@@ -20,7 +20,7 @@ OptionParser.new do |opts|
|
|
20
20
|
options[:clear] = true
|
21
21
|
options[:identifier] = identifier if identifier
|
22
22
|
end
|
23
|
-
opts.on('-s', '--set [variables]', 'Example: --set environment=staging&path=/my/sweet/path') do |set|
|
23
|
+
opts.on('-s', '--set [variables]', 'Example: --set \'environment=staging&path=/my/sweet/path\'') do |set|
|
24
24
|
options[:set] = set if set
|
25
25
|
end
|
26
26
|
opts.on('-f', '--load-file [schedule file]', 'Default: config/schedule.rb') do |file|
|
data/bin/wheneverize
CHANGED
@@ -17,17 +17,16 @@ OptionParser.new do |opts|
|
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
20
|
+
unless ARGV.empty?
|
21
|
+
if !File.exists?(ARGV.first)
|
22
|
+
abort "`#{ARGV.first}' does not exist."
|
23
|
+
elsif !File.directory?(ARGV.first)
|
24
|
+
abort "`#{ARGV.first}' is not a directory."
|
25
|
+
elsif ARGV.length > 1
|
26
|
+
abort "Too many arguments; please specify only the directory to wheneverize."
|
27
|
+
end
|
28
28
|
end
|
29
29
|
|
30
|
-
|
31
30
|
content = <<-FILE
|
32
31
|
# Use this file to easily define all of your cron jobs.
|
33
32
|
#
|
@@ -52,7 +51,7 @@ content = <<-FILE
|
|
52
51
|
FILE
|
53
52
|
|
54
53
|
file = 'config/schedule.rb'
|
55
|
-
base = ARGV.shift
|
54
|
+
base = ARGV.empty? ? '.' : ARGV.shift
|
56
55
|
|
57
56
|
file = File.join(base, file)
|
58
57
|
if File.exists?(file)
|
data/lib/whenever.rb
CHANGED
@@ -2,14 +2,15 @@ require 'chronic'
|
|
2
2
|
require 'active_support/all'
|
3
3
|
require 'thread'
|
4
4
|
|
5
|
-
require 'whenever/job_list'
|
6
|
-
require 'whenever/job'
|
7
|
-
require 'whenever/cron'
|
8
|
-
require 'whenever/output_redirection'
|
9
|
-
require 'whenever/command_line'
|
10
|
-
require 'whenever/version'
|
11
|
-
|
12
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
|
13
14
|
|
14
15
|
def self.cron(options)
|
15
16
|
Whenever::JobList.new(options).generate_cron_output
|
@@ -19,4 +20,11 @@ module Whenever
|
|
19
20
|
Dir.pwd
|
20
21
|
end
|
21
22
|
|
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
|
data/lib/whenever/capistrano.rb
CHANGED
@@ -1,32 +1,62 @@
|
|
1
1
|
Capistrano::Configuration.instance(:must_exist).load do
|
2
|
-
|
3
2
|
_cset(:whenever_roles) { :db }
|
4
3
|
_cset(:whenever_command) { "whenever" }
|
5
|
-
_cset(:whenever_identifier) { application }
|
6
|
-
_cset(:whenever_environment) { "production" }
|
7
|
-
_cset(:whenever_update_flags) { "--update-crontab #{whenever_identifier} --set environment=#{whenever_environment}" }
|
8
|
-
_cset(:whenever_clear_flags) { "--clear-crontab #{whenever_identifier}" }
|
9
|
-
|
4
|
+
_cset(:whenever_identifier) { fetch :application }
|
5
|
+
_cset(:whenever_environment) { fetch :rails_env, "production" }
|
6
|
+
_cset(:whenever_update_flags) { "--update-crontab #{fetch :whenever_identifier} --set environment=#{fetch :whenever_environment}" }
|
7
|
+
_cset(:whenever_clear_flags) { "--clear-crontab #{fetch :whenever_identifier}" }
|
8
|
+
|
10
9
|
# Disable cron jobs at the begining of a deploy.
|
11
10
|
after "deploy:update_code", "whenever:clear_crontab"
|
12
11
|
# Write the new cron jobs near the end.
|
13
12
|
after "deploy:symlink", "whenever:update_crontab"
|
14
13
|
# If anything goes wrong, undo.
|
15
14
|
after "deploy:rollback", "whenever:update_crontab"
|
16
|
-
|
15
|
+
|
17
16
|
namespace :whenever do
|
18
|
-
desc
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
17
|
+
desc <<-DESC
|
18
|
+
Update application's crontab entries using Whenever. You can configure \
|
19
|
+
the command used to invoke Whenever by setting the :whenever_command \
|
20
|
+
variable, which can be used with Bundler to set the command to \
|
21
|
+
"bundle exec whenever". You can configure the identifier used by setting \
|
22
|
+
the :whenever_identifier variable, which defaults to the same value configured \
|
23
|
+
for the :application variable. You can configure the environment by setting \
|
24
|
+
the :whenever_environment variable, which defaults to the same value \
|
25
|
+
configured for the :rails_env variable which itself defaults to "production". \
|
26
|
+
Finally, you can completely override all arguments to the Whenever command \
|
27
|
+
by setting the :whenever_update_flags variable. Additionally you can configure \
|
28
|
+
which servers the crontab is updated on by setting the :whenever_roles variable.
|
29
|
+
DESC
|
30
|
+
task :update_crontab do
|
31
|
+
options = { :roles => fetch(:whenever_roles) }
|
32
|
+
|
33
|
+
if find_servers(options).any?
|
34
|
+
on_rollback do
|
35
|
+
if fetch :previous_release
|
36
|
+
run "cd #{fetch :previous_release} && #{fetch :whenever_command} #{fetch :whenever_update_flags}", options
|
37
|
+
else
|
38
|
+
run "cd #{fetch :release_path} && #{fetch :whenever_command} #{fetch :whenever_clear_flags}", options
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
run "cd #{fetch :current_path} && #{fetch :whenever_command} #{fetch :whenever_update_flags}", options
|
43
|
+
end
|
23
44
|
end
|
24
45
|
|
25
|
-
desc
|
26
|
-
|
27
|
-
|
28
|
-
|
46
|
+
desc <<-DESC
|
47
|
+
Clear application's crontab entries using Whenever. You can configure \
|
48
|
+
the command used to invoke Whenever by setting the :whenever_command \
|
49
|
+
variable, which can be used with Bundler to set the command to \
|
50
|
+
"bundle exec whenever". You can configure the identifier used by setting \
|
51
|
+
the :whenever_identifier variable, which defaults to the same value configured \
|
52
|
+
for the :application variable. Finally, you can completely override all \
|
53
|
+
arguments to the Whenever command by setting the :whenever_clear_flags variable. \
|
54
|
+
Additionally you can configure which servers the crontab is cleared on by setting \
|
55
|
+
the :whenever_roles variable.
|
56
|
+
DESC
|
57
|
+
task :clear_crontab do
|
58
|
+
options = { :roles => whenever_roles }
|
59
|
+
run "cd #{fetch :release_path} && #{fetch :whenever_command} #{fetch :whenever_clear_flags}", options if find_servers(options).any?
|
29
60
|
end
|
30
61
|
end
|
31
|
-
|
32
|
-
end
|
62
|
+
end
|
data/lib/whenever/cron.rb
CHANGED
data/lib/whenever/job.rb
CHANGED
data/lib/whenever/job_list.rb
CHANGED
@@ -1,24 +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
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])
|
17
|
+
end
|
20
18
|
|
21
|
-
|
19
|
+
instance_eval(setup + schedule, options[:file] || '<eval>')
|
22
20
|
end
|
23
21
|
|
24
22
|
def set(variable, value)
|
@@ -143,6 +141,5 @@ module Whenever
|
|
143
141
|
|
144
142
|
shortcut_jobs.join + combine(regular_jobs).join
|
145
143
|
end
|
146
|
-
|
147
144
|
end
|
148
145
|
end
|
data/lib/whenever/setup.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
#
|
1
|
+
# Environment defaults to production
|
2
2
|
set :environment, "production"
|
3
3
|
# Path defaults to the directory `whenever` was run from
|
4
4
|
set :path, Whenever.path
|
@@ -8,10 +8,16 @@ set :path, Whenever.path
|
|
8
8
|
set :job_template, "/bin/bash -l -c ':job'"
|
9
9
|
|
10
10
|
job_type :command, ":task :output"
|
11
|
-
|
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
|
12
18
|
|
13
19
|
# Create a runner job that's appropriate for the Rails version,
|
14
|
-
if
|
20
|
+
if Whenever.rails3?
|
15
21
|
job_type :runner, "cd :path && script/rails runner -e :environment ':task' :output"
|
16
22
|
else
|
17
23
|
job_type :runner, "cd :path && script/runner -e :environment ':task' :output"
|
data/lib/whenever/version.rb
CHANGED
@@ -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
|
|
@@ -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
|
@@ -110,7 +110,7 @@ class OutputDefaultDefinedJobsTest < Test::Unit::TestCase
|
|
110
110
|
context "A runner for a Rails 3 app" do
|
111
111
|
setup do
|
112
112
|
Whenever.expects(:path).at_least_once.returns('/my/path')
|
113
|
-
|
113
|
+
Whenever.expects(:rails3?).returns(true)
|
114
114
|
@output = Whenever.cron \
|
115
115
|
<<-file
|
116
116
|
set :job_template, nil
|
@@ -140,6 +140,24 @@ class OutputDefaultDefinedJobsTest < Test::Unit::TestCase
|
|
140
140
|
end
|
141
141
|
|
142
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
|
143
161
|
assert_match two_hours + ' cd /my/path && RAILS_ENV=production rake blahblah --silent', @output
|
144
162
|
end
|
145
163
|
end
|
@@ -157,7 +175,7 @@ class OutputDefaultDefinedJobsTest < Test::Unit::TestCase
|
|
157
175
|
end
|
158
176
|
|
159
177
|
should "output the rake command using that path" do
|
160
|
-
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
|
161
179
|
end
|
162
180
|
end
|
163
181
|
|
data/test/test_helper.rb
CHANGED
data/whenever.gemspec
CHANGED
@@ -15,8 +15,17 @@ Gem::Specification.new do |s|
|
|
15
15
|
s.test_files = `git ls-files -- test/{functional,unit}/*`.split("\n")
|
16
16
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
17
17
|
s.require_paths = ["lib"]
|
18
|
-
|
19
|
-
s.
|
20
|
-
s.
|
21
|
-
|
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"
|
22
31
|
end
|
metadata
CHANGED
@@ -1,101 +1,96 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: whenever
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.7.0
|
5
5
|
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 6
|
9
|
-
- 8
|
10
|
-
version: 0.6.8
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
7
|
+
authors:
|
13
8
|
- Javan Makhmali
|
14
9
|
autorequire:
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
name: aaronh-chronic
|
23
|
-
prerelease: false
|
24
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
12
|
+
date: 2011-09-02 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: chronic
|
16
|
+
requirement: &70222728174660 !ruby/object:Gem::Requirement
|
25
17
|
none: false
|
26
|
-
requirements:
|
27
|
-
- -
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
|
30
|
-
segments:
|
31
|
-
- 0
|
32
|
-
- 3
|
33
|
-
- 9
|
34
|
-
version: 0.3.9
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 0.6.3
|
35
22
|
type: :runtime
|
36
|
-
version_requirements: *id001
|
37
|
-
- !ruby/object:Gem::Dependency
|
38
|
-
name: activesupport
|
39
23
|
prerelease: false
|
40
|
-
|
24
|
+
version_requirements: *70222728174660
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: activesupport
|
27
|
+
requirement: &70222728174020 !ruby/object:Gem::Requirement
|
41
28
|
none: false
|
42
|
-
requirements:
|
43
|
-
- -
|
44
|
-
- !ruby/object:Gem::Version
|
45
|
-
hash: 11
|
46
|
-
segments:
|
47
|
-
- 2
|
48
|
-
- 3
|
49
|
-
- 4
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
50
32
|
version: 2.3.4
|
51
33
|
type: :runtime
|
52
|
-
version_requirements: *id002
|
53
|
-
- !ruby/object:Gem::Dependency
|
54
|
-
name: shoulda
|
55
34
|
prerelease: false
|
56
|
-
|
35
|
+
version_requirements: *70222728174020
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: shoulda
|
38
|
+
requirement: &70222728173280 !ruby/object:Gem::Requirement
|
57
39
|
none: false
|
58
|
-
requirements:
|
59
|
-
- -
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
hash: 9
|
62
|
-
segments:
|
63
|
-
- 2
|
64
|
-
- 1
|
65
|
-
- 1
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
66
43
|
version: 2.1.1
|
67
44
|
type: :development
|
68
|
-
version_requirements: *id003
|
69
|
-
- !ruby/object:Gem::Dependency
|
70
|
-
name: mocha
|
71
45
|
prerelease: false
|
72
|
-
|
46
|
+
version_requirements: *70222728173280
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: mocha
|
49
|
+
requirement: &70222728172720 !ruby/object:Gem::Requirement
|
73
50
|
none: false
|
74
|
-
requirements:
|
75
|
-
- -
|
76
|
-
- !ruby/object:Gem::Version
|
77
|
-
hash: 49
|
78
|
-
segments:
|
79
|
-
- 0
|
80
|
-
- 9
|
81
|
-
- 5
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
82
54
|
version: 0.9.5
|
83
55
|
type: :development
|
84
|
-
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: *70222728172720
|
58
|
+
- !ruby/object:Gem::Dependency
|
59
|
+
name: rake
|
60
|
+
requirement: &70222728172280 !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ! '>='
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '0'
|
66
|
+
type: :development
|
67
|
+
prerelease: false
|
68
|
+
version_requirements: *70222728172280
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: i18n
|
71
|
+
requirement: &70222728171580 !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
73
|
+
requirements:
|
74
|
+
- - ! '>='
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
type: :development
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: *70222728171580
|
85
80
|
description: Clean ruby syntax for writing and deploying cron jobs.
|
86
|
-
email:
|
81
|
+
email:
|
87
82
|
- javan@javan.us
|
88
|
-
executables:
|
83
|
+
executables:
|
89
84
|
- whenever
|
90
85
|
- wheneverize
|
91
86
|
extensions: []
|
92
|
-
|
93
87
|
extra_rdoc_files: []
|
94
|
-
|
95
|
-
files:
|
88
|
+
files:
|
96
89
|
- .gitignore
|
90
|
+
- .travis.yml
|
97
91
|
- CHANGELOG.md
|
98
92
|
- Gemfile
|
93
|
+
- LICENSE
|
99
94
|
- README.md
|
100
95
|
- Rakefile
|
101
96
|
- bin/whenever
|
@@ -119,41 +114,31 @@ files:
|
|
119
114
|
- test/unit/cron_test.rb
|
120
115
|
- test/unit/job_test.rb
|
121
116
|
- whenever.gemspec
|
122
|
-
|
123
|
-
homepage: ""
|
117
|
+
homepage: ''
|
124
118
|
licenses: []
|
125
|
-
|
126
119
|
post_install_message:
|
127
120
|
rdoc_options: []
|
128
|
-
|
129
|
-
require_paths:
|
121
|
+
require_paths:
|
130
122
|
- lib
|
131
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
123
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
132
124
|
none: false
|
133
|
-
requirements:
|
134
|
-
- -
|
135
|
-
- !ruby/object:Gem::Version
|
136
|
-
|
137
|
-
|
138
|
-
- 0
|
139
|
-
version: "0"
|
140
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
125
|
+
requirements:
|
126
|
+
- - ! '>='
|
127
|
+
- !ruby/object:Gem::Version
|
128
|
+
version: '0'
|
129
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
141
130
|
none: false
|
142
|
-
requirements:
|
143
|
-
- -
|
144
|
-
- !ruby/object:Gem::Version
|
145
|
-
|
146
|
-
segments:
|
147
|
-
- 0
|
148
|
-
version: "0"
|
131
|
+
requirements:
|
132
|
+
- - ! '>='
|
133
|
+
- !ruby/object:Gem::Version
|
134
|
+
version: '0'
|
149
135
|
requirements: []
|
150
|
-
|
151
136
|
rubyforge_project:
|
152
|
-
rubygems_version: 1.
|
137
|
+
rubygems_version: 1.8.6
|
153
138
|
signing_key:
|
154
139
|
specification_version: 3
|
155
140
|
summary: Cron jobs in ruby.
|
156
|
-
test_files:
|
141
|
+
test_files:
|
157
142
|
- test/functional/command_line_test.rb
|
158
143
|
- test/functional/output_at_test.rb
|
159
144
|
- test/functional/output_default_defined_jobs_test.rb
|