whenever 0.5.0 → 0.6.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: whenever
3
3
  version: !ruby/object:Gem::Version
4
+ hash: 3
4
5
  prerelease: false
5
6
  segments:
6
7
  - 0
7
- - 5
8
- - 0
9
- version: 0.5.0
8
+ - 6
9
+ - 2
10
+ version: 0.6.2
10
11
  platform: ruby
11
12
  authors:
12
13
  - Javan Makhmali
@@ -14,24 +15,74 @@ autorequire:
14
15
  bindir: bin
15
16
  cert_chain: []
16
17
 
17
- date: 2010-06-28 00:00:00 -04:00
18
+ date: 2010-10-26 00:00:00 -04:00
18
19
  default_executable:
19
20
  dependencies:
20
21
  - !ruby/object:Gem::Dependency
21
- name: chronic
22
+ name: aaronh-chronic
22
23
  prerelease: false
23
24
  requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
24
26
  requirements:
25
27
  - - ">="
26
28
  - !ruby/object:Gem::Version
29
+ hash: 1
27
30
  segments:
28
31
  - 0
29
- - 2
30
32
  - 3
31
- version: 0.2.3
33
+ - 9
34
+ version: 0.3.9
32
35
  type: :runtime
33
36
  version_requirements: *id001
34
- description: Clean ruby syntax for defining and deploying messy cron jobs.
37
+ - !ruby/object:Gem::Dependency
38
+ name: activesupport
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ hash: 11
46
+ segments:
47
+ - 2
48
+ - 3
49
+ - 4
50
+ version: 2.3.4
51
+ type: :runtime
52
+ version_requirements: *id002
53
+ - !ruby/object:Gem::Dependency
54
+ name: shoulda
55
+ prerelease: false
56
+ requirement: &id003 !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ hash: 9
62
+ segments:
63
+ - 2
64
+ - 1
65
+ - 1
66
+ version: 2.1.1
67
+ type: :development
68
+ version_requirements: *id003
69
+ - !ruby/object:Gem::Dependency
70
+ name: mocha
71
+ prerelease: false
72
+ requirement: &id004 !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ hash: 49
78
+ segments:
79
+ - 0
80
+ - 9
81
+ - 5
82
+ version: 0.9.5
83
+ type: :development
84
+ version_requirements: *id004
85
+ description: Clean ruby syntax for writing and deploying cron jobs.
35
86
  email: javan@javan.us
36
87
  executables:
37
88
  - whenever
@@ -39,33 +90,32 @@ executables:
39
90
  extensions: []
40
91
 
41
92
  extra_rdoc_files:
42
- - README.rdoc
93
+ - README.md
43
94
  files:
44
95
  - .gitignore
45
- - CHANGELOG.rdoc
46
- - README.rdoc
96
+ - CHANGELOG.md
97
+ - README.md
47
98
  - Rakefile
48
99
  - bin/whenever
49
100
  - bin/wheneverize
50
101
  - lib/whenever.rb
51
- - lib/whenever/base.rb
102
+ - lib/whenever/capistrano.rb
52
103
  - lib/whenever/command_line.rb
104
+ - lib/whenever/cron.rb
53
105
  - lib/whenever/job.rb
54
106
  - lib/whenever/job_list.rb
55
- - lib/whenever/job_types/default.rb
56
- - lib/whenever/outputs/cron.rb
57
- - lib/whenever/outputs/cron/output_redirection.rb
107
+ - lib/whenever/output_redirection.rb
108
+ - lib/whenever/setup.rb
58
109
  - lib/whenever/version.rb
59
- - test/command_line_test.rb
60
- - test/cron_test.rb
61
- - test/output_at_test.rb
62
- - test/output_command_test.rb
63
- - test/output_defined_job_test.rb
64
- - test/output_env_test.rb
65
- - test/output_rake_test.rb
66
- - test/output_redirection_test.rb
67
- - test/output_runner_test.rb
110
+ - test/functional/command_line_test.rb
111
+ - test/functional/output_at_test.rb
112
+ - test/functional/output_default_defined_jobs_test.rb
113
+ - test/functional/output_defined_job_test.rb
114
+ - test/functional/output_env_test.rb
115
+ - test/functional/output_redirection_test.rb
68
116
  - test/test_helper.rb
117
+ - test/unit/cron_test.rb
118
+ - test/unit/job_test.rb
69
119
  - whenever.gemspec
70
120
  has_rdoc: true
71
121
  homepage: http://github.com/javan/whenever
@@ -77,34 +127,37 @@ rdoc_options:
77
127
  require_paths:
78
128
  - lib
79
129
  required_ruby_version: !ruby/object:Gem::Requirement
130
+ none: false
80
131
  requirements:
81
132
  - - ">="
82
133
  - !ruby/object:Gem::Version
134
+ hash: 3
83
135
  segments:
84
136
  - 0
85
137
  version: "0"
86
138
  required_rubygems_version: !ruby/object:Gem::Requirement
139
+ none: false
87
140
  requirements:
88
141
  - - ">="
89
142
  - !ruby/object:Gem::Version
143
+ hash: 3
90
144
  segments:
91
145
  - 0
92
146
  version: "0"
93
147
  requirements: []
94
148
 
95
149
  rubyforge_project:
96
- rubygems_version: 1.3.6
150
+ rubygems_version: 1.3.7
97
151
  signing_key:
98
152
  specification_version: 3
99
- summary: Clean ruby syntax for defining and deploying messy cron jobs.
153
+ summary: Write your cron jobs in ruby.
100
154
  test_files:
101
- - test/command_line_test.rb
102
- - test/cron_test.rb
103
- - test/output_at_test.rb
104
- - test/output_command_test.rb
105
- - test/output_defined_job_test.rb
106
- - test/output_env_test.rb
107
- - test/output_rake_test.rb
108
- - test/output_redirection_test.rb
109
- - test/output_runner_test.rb
155
+ - test/functional/command_line_test.rb
156
+ - test/functional/output_at_test.rb
157
+ - test/functional/output_default_defined_jobs_test.rb
158
+ - test/functional/output_defined_job_test.rb
159
+ - test/functional/output_env_test.rb
160
+ - test/functional/output_redirection_test.rb
110
161
  - test/test_helper.rb
162
+ - test/unit/cron_test.rb
163
+ - test/unit/job_test.rb
data/README.rdoc DELETED
@@ -1,127 +0,0 @@
1
- == Introduction
2
-
3
- Whenever is a Ruby gem that provides a clear syntax for defining cron jobs. It outputs valid cron syntax and can even write your crontab file for you. It is designed to work well with Rails applications and can be deployed with Capistrano. Whenever works fine independently as well.
4
-
5
- Ryan Bates created a great Railscast about Whenever: http://railscasts.com/episodes/164-cron-in-ruby
6
-
7
- Discussion: http://groups.google.com/group/whenever-gem
8
-
9
- == Installation
10
-
11
- $ sudo gem install whenever
12
-
13
- == Getting started
14
-
15
- $ cd /my/rails/app
16
- $ wheneverize .
17
-
18
- This will create an initial "config/schedule.rb" file you.
19
-
20
- == 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
-
28
- every 1.day, :at => '4:30 am' do
29
- runner "MyModel.task_to_run_at_four_thirty_in_the_morning"
30
- end
31
-
32
- every :hour do # Many shortcuts available: :hour, :day, :month, :year, :reboot
33
- runner "SomeModel.ladeeda"
34
- end
35
-
36
- every :sunday, :at => '12pm' do # Use any day of the week or :weekend, :weekday
37
- runner "Task.do_something_great"
38
- end
39
-
40
- More examples on the wiki: http://wiki.github.com/javan/whenever/instructions-and-examples
41
-
42
- == Define your own job types
43
-
44
- Whenever ships with three pre-defined job types: command, runner, and rake. You can define your own with <code>job_type</code>.
45
-
46
- For example:
47
-
48
- job_type :awesome, '/usr/local/bin/awesome :task :fun_level'
49
-
50
- every 2.hours do
51
- awesome "party", :fun_level => "extreme"
52
- end
53
-
54
- Would run <code>/usr/local/bin/awesome party extreme</code> every two hours. <code>:task</code> is always replaced with the first argument, and any additional <code>:whatevers</code> are replaced with the options passed in or by variables that have been defined with <code>set</code>.
55
-
56
- The default job types that ship with Whenever are defined like so:
57
-
58
- job_type :command, ':task'
59
- job_type :runner, 'cd :path && script/runner -e :environment ":task"'
60
- job_type :rake, 'cd :path && RAILS_ENV=:environment /usr/bin/env rake :task'
61
-
62
- If a <code>:path</code> is not set it will default to the directory in which <code>whenever</code> was executed. <code>:environment</code> will default to 'production'.
63
-
64
- == Cron output
65
-
66
- $ cd /my/rails/app
67
- $ whenever
68
-
69
- And you'll see your schedule.rb converted to cron sytax. Note: running `whenever' with no options does not display your current crontab file, it simply shows you the output of converting your schedule.rb file.
70
-
71
- == Capistrano integration
72
-
73
- In your "config/deploy.rb" file do something like:
74
-
75
- after "deploy:symlink", "deploy:update_crontab"
76
-
77
- namespace :deploy do
78
- desc "Update the crontab file"
79
- task :update_crontab, :roles => :db do
80
- run "cd #{release_path} && whenever --update-crontab #{application}"
81
- end
82
- end
83
-
84
- This will update your crontab file, leaving any existing entries unharmed. When using the <code>--update-crontab</code> option, Whenever will only update the entries in your crontab file related to the current schedule.rb file. You can replace the <code>#{application}</code> with any identifying string you'd like. You can have any number of apps deploy to the same crontab file peacefully given they each use a different identifier.
85
-
86
- If you wish to simply overwrite your crontab file each time you deploy, use the <code>--write-crontab</code> option. This is ideal if you are only working with one app and every crontab entry is contained in a single schedule.rb file.
87
-
88
- By mixing and matching the <code>--load-file</code> and <code>--user</code> options with your various :roles in Capistrano it is entirely possible to deploy different crontab schedules under different users to all your various servers. Get creative!
89
-
90
- If you want to override a variable (like your environment) at the time of deployment you can do so with the <code>--set</code> option: http://wiki.github.com/javan/whenever/setting-variables-on-the-fly
91
-
92
- == Credit
93
-
94
- Whenever was created for use at Inkling (http://inklingmarkets.com) where I work. Their take on it: http://blog.inklingmarkets.com/2009/02/whenever-easy-way-to-do-cron-jobs-from.html
95
-
96
- While building Whenever, I learned a lot by digging through the source code of Capistrano - http://github.com/jamis/capistrano
97
-
98
- == Discussion / Feedback / Issues / Bugs
99
-
100
- For general discussion and questions, please use the google group: http://groups.google.com/group/whenever-gem
101
-
102
- If you've found a genuine bug or issue, please use the Issues section on github: http://github.com/javan/whenever/issues
103
-
104
- == License
105
-
106
- Copyright (c) 2009+ Javan Makhmali
107
-
108
- Permission is hereby granted, free of charge, to any person
109
- obtaining a copy of this software and associated documentation
110
- files (the "Software"), to deal in the Software without
111
- restriction, including without limitation the rights to use,
112
- copy, modify, merge, publish, distribute, sublicense, and/or sell
113
- copies of the Software, and to permit persons to whom the
114
- Software is furnished to do so, subject to the following
115
- conditions:
116
-
117
- The above copyright notice and this permission notice shall be
118
- included in all copies or substantial portions of the Software.
119
-
120
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
121
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
122
- OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
123
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
124
- HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
125
- WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
126
- FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
127
- OTHER DEALINGS IN THE SOFTWARE.
data/lib/whenever/base.rb DELETED
@@ -1,11 +0,0 @@
1
- module Whenever
2
-
3
- def self.cron(options)
4
- Whenever::JobList.new(options).generate_cron_output
5
- end
6
-
7
- def self.path
8
- Dir.pwd
9
- end
10
-
11
- end
@@ -1,3 +0,0 @@
1
- job_type :command, ':task'
2
- job_type :runner, 'cd :path && script/runner -e :environment ":task"'
3
- job_type :rake, 'cd :path && RAILS_ENV=:environment /usr/bin/env rake :task'
@@ -1,60 +0,0 @@
1
- module Whenever
2
- module Output
3
- class Cron
4
- class OutputRedirection
5
-
6
- def initialize(output)
7
- @output = output
8
- end
9
-
10
- def to_s
11
- return '' unless defined?(@output)
12
- case @output
13
- when String then redirect_from_string
14
- when Hash then redirect_from_hash
15
- when NilClass then ">> /dev/null 2>&1"
16
- else ''
17
- end
18
- end
19
-
20
- protected
21
-
22
- def stdout
23
- return unless @output.has_key?(:standard)
24
- @output[:standard].nil? ? '/dev/null' : @output[:standard]
25
- end
26
-
27
- def stderr
28
- return unless @output.has_key?(:error)
29
- @output[:error].nil? ? '/dev/null' : @output[:error]
30
- end
31
-
32
- def redirect_from_hash
33
- case
34
- when stdout == '/dev/null' && stderr == '/dev/null'
35
- "> /dev/null 2>&1"
36
- when stdout && stderr == '/dev/null'
37
- ">> #{stdout} 2> /dev/null"
38
- when stdout && stderr
39
- ">> #{stdout} 2>> #{stderr}"
40
- when stderr == '/dev/null'
41
- "2> /dev/null"
42
- when stderr
43
- "2>> #{stderr}"
44
- when stdout == '/dev/null'
45
- "> /dev/null"
46
- when stdout
47
- ">> #{stdout}"
48
- else
49
- ''
50
- end
51
- end
52
-
53
- def redirect_from_string
54
- ">> #{@output} 2>&1"
55
- end
56
-
57
- end
58
- end
59
- end
60
- end
@@ -1,177 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + "/test_helper")
2
-
3
- class CommandLineTest < Test::Unit::TestCase
4
-
5
- context "A command line write" do
6
- setup do
7
- File.expects(:exists?).with('config/schedule.rb').returns(true)
8
- @command = Whenever::CommandLine.new(:write => true, :identifier => 'My identifier')
9
- @task = "#{two_hours} /my/command"
10
- Whenever.expects(:cron).returns(@task)
11
- end
12
-
13
- should "output the cron job with identifier blocks" do
14
- output = <<-EXPECTED
15
- # Begin Whenever generated tasks for: My identifier
16
- #{@task}
17
- # End Whenever generated tasks for: My identifier
18
- EXPECTED
19
-
20
- assert_equal output, @command.send(:whenever_cron)
21
- end
22
-
23
- should "write the crontab when run" do
24
- @command.expects(:write_crontab).returns(true)
25
- assert @command.run
26
- end
27
- end
28
-
29
- context "A command line update" do
30
- setup do
31
- File.expects(:exists?).with('config/schedule.rb').returns(true)
32
- @command = Whenever::CommandLine.new(:update => true, :identifier => 'My identifier')
33
- @task = "#{two_hours} /my/command"
34
- Whenever.expects(:cron).returns(@task)
35
- end
36
-
37
- should "add the cron to the end of the file if there is no existing identifier block" do
38
- existing = '# Existing crontab'
39
- @command.expects(:read_crontab).at_least_once.returns(existing)
40
-
41
- new_cron = <<-EXPECTED
42
- #{existing}
43
-
44
- # Begin Whenever generated tasks for: My identifier
45
- #{@task}
46
- # End Whenever generated tasks for: My identifier
47
- EXPECTED
48
-
49
- assert_equal new_cron, @command.send(:updated_crontab)
50
-
51
- @command.expects(:write_crontab).with(new_cron).returns(true)
52
- assert @command.run
53
- end
54
-
55
- should "replace an existing block if the identifier matches" do
56
- existing = <<-EXISTING_CRON
57
- # Something
58
-
59
- # Begin Whenever generated tasks for: My identifier
60
- My whenever job that was already here
61
- # End Whenever generated tasks for: My identifier
62
-
63
- # Begin Whenever generated tasks for: Other identifier
64
- This shouldn't get replaced
65
- # End Whenever generated tasks for: Other identifier
66
- EXISTING_CRON
67
-
68
- @command.expects(:read_crontab).at_least_once.returns(existing)
69
-
70
- new_cron = <<-NEW_CRON
71
- # Something
72
-
73
- # Begin Whenever generated tasks for: My identifier
74
- #{@task}
75
- # End Whenever generated tasks for: My identifier
76
-
77
- # Begin Whenever generated tasks for: Other identifier
78
- This shouldn't get replaced
79
- # End Whenever generated tasks for: Other identifier
80
- NEW_CRON
81
-
82
- assert_equal new_cron, @command.send(:updated_crontab)
83
-
84
- @command.expects(:write_crontab).with(new_cron).returns(true)
85
- assert @command.run
86
- end
87
- end
88
-
89
- context "A command line delete" do
90
- setup do
91
- File.expects(:exists?).with('config/schedule.rb').returns(true)
92
- @command = Whenever::CommandLine.new(:clear => true, :identifier => 'My identifier')
93
- @task = "#{two_hours} /my/command"
94
- end
95
-
96
- should "add an empty identifier block if there is no existing one" do
97
- existing = '# Existing crontab'
98
- @command.expects(:read_crontab).at_least_once.returns(existing)
99
-
100
- new_cron = <<-EXPECTED
101
- #{existing}
102
-
103
- # Begin Whenever generated tasks for: My identifier
104
- # End Whenever generated tasks for: My identifier
105
- EXPECTED
106
-
107
- assert_equal new_cron, @command.send(:updated_crontab)
108
-
109
- @command.expects(:write_crontab).with(new_cron).returns(true)
110
- assert @command.run
111
- end
112
-
113
- should "delete an existing block if the identifier matches" do
114
- existing = <<-EXISTING_CRON
115
- # Something
116
-
117
- # Begin Whenever generated tasks for: My identifier
118
- My whenever job that was already here
119
- # End Whenever generated tasks for: My identifier
120
-
121
- # Begin Whenever generated tasks for: Other identifier
122
- This shouldn't get replaced
123
- # End Whenever generated tasks for: Other identifier
124
- EXISTING_CRON
125
-
126
- @command.expects(:read_crontab).at_least_once.returns(existing)
127
-
128
- new_cron = <<-NEW_CRON
129
- # Something
130
-
131
- # Begin Whenever generated tasks for: My identifier
132
- # End Whenever generated tasks for: My identifier
133
-
134
- # Begin Whenever generated tasks for: Other identifier
135
- This shouldn't get replaced
136
- # End Whenever generated tasks for: Other identifier
137
- NEW_CRON
138
-
139
- assert_equal new_cron, @command.send(:updated_crontab)
140
-
141
- @command.expects(:write_crontab).with(new_cron).returns(true)
142
- assert @command.run
143
- end
144
- end
145
-
146
- context "A command line update with no identifier" do
147
- setup do
148
- File.expects(:exists?).with('config/schedule.rb').returns(true)
149
- Whenever::CommandLine.any_instance.expects(:default_identifier).returns('DEFAULT')
150
- @command = Whenever::CommandLine.new(:update => true, :file => @file)
151
- end
152
-
153
- should "use the default identifier" do
154
- assert_equal "Whenever generated tasks for: DEFAULT", @command.send(:comment_base)
155
- end
156
- end
157
-
158
- context "combined params" do
159
- setup do
160
- Whenever::CommandLine.any_instance.expects(:exit)
161
- Whenever::CommandLine.any_instance.expects(:warn)
162
- File.expects(:exists?).with('config/schedule.rb').returns(true)
163
- end
164
-
165
- should "exit with write and clear" do
166
- @command = Whenever::CommandLine.new(:write => true, :clear => true)
167
- end
168
-
169
- should "exit with write and update" do
170
- @command = Whenever::CommandLine.new(:write => true, :update => true)
171
- end
172
-
173
- should "exit with update and clear" do
174
- @command = Whenever::CommandLine.new(:update => true, :clear => true)
175
- end
176
- end
177
- end
@@ -1,37 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + "/test_helper")
2
-
3
- class OutputCommandTest < Test::Unit::TestCase
4
-
5
- context "A plain command" do
6
- setup do
7
- @output = Whenever.cron \
8
- <<-file
9
- every 2.hours do
10
- command "blahblah"
11
- end
12
- file
13
- end
14
-
15
- should "output the command" do
16
- assert_match /^.+ .+ .+ .+ blahblah$/, @output
17
- end
18
- end
19
-
20
- context "An every statement with two commands in it" do
21
- setup do
22
- @output = Whenever.cron \
23
- <<-file
24
- every 1.hour do
25
- command "first"
26
- command "second"
27
- end
28
- file
29
- end
30
-
31
- should "output both commands" do
32
- assert_match "0 * * * * first", @output
33
- assert_match "0 * * * * second", @output
34
- end
35
- end
36
-
37
- end
@@ -1,56 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + "/test_helper")
2
-
3
- class OutputEnvTest < Test::Unit::TestCase
4
-
5
- context "The output from Whenever with environment variables set" do
6
- setup do
7
- @output = Whenever.cron \
8
- <<-file
9
- env :MYVAR, 'blah'
10
- env 'MAILTO', "someone@example.com"
11
- file
12
- end
13
-
14
- should "output MYVAR environment variable" do
15
- assert_match "MYVAR=blah", @output
16
- end
17
-
18
- should "output MAILTO environment variable" do
19
- assert_match "MAILTO=someone@example.com", @output
20
- end
21
- end
22
-
23
- context "No PATH environment variable set" do
24
- setup do
25
- Whenever::JobList.any_instance.expects(:read_path).at_least_once.returns('/usr/local/bin')
26
- @output = Whenever.cron ""
27
- end
28
-
29
- should "add a PATH variable based on the user's PATH" do
30
- assert_match "PATH=/usr/local/bin", @output
31
- end
32
- end
33
-
34
- context "A PATH environment variable set" do
35
- setup do
36
- Whenever::JobList.stubs(:read_path).returns('/usr/local/bin')
37
- @output = Whenever.cron "env :PATH, '/my/path'"
38
- end
39
-
40
- should "use that path and the user's PATH" do
41
- assert_match "PATH=/my/path", @output
42
- assert_no_match /local/, @output
43
- end
44
- end
45
-
46
- context "No PATH set and instructed not to automatically load the user's path" do
47
- setup do
48
- @output = Whenever.cron "set :set_path_automatically, false"
49
- end
50
-
51
- should "not have a PATH set" do
52
- assert_no_match /PATH/, @output
53
- end
54
- end
55
-
56
- end