insrc-whenever 0.4.0 → 0.5.0
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.
- data/CHANGELOG.rdoc +27 -0
- data/README.rdoc +24 -12
- data/bin/whenever +5 -3
- data/lib/whenever.rb +4 -15
- data/lib/whenever/base.rb +1 -5
- data/lib/whenever/command_line.rb +8 -5
- data/lib/whenever/job.rb +22 -0
- data/lib/whenever/job_list.rb +24 -24
- data/lib/whenever/job_types/default.rb +3 -27
- data/lib/whenever/outputs/cron.rb +2 -2
- data/lib/whenever/outputs/cron/output_redirection.rb +9 -3
- data/lib/whenever/version.rb +1 -1
- data/test/command_line_test.rb +78 -2
- data/test/output_at_test.rb +63 -4
- data/test/output_defined_job_test.rb +87 -0
- data/test/output_redirection_test.rb +10 -10
- data/test/output_runner_test.rb +10 -44
- data/whenever.gemspec +10 -9
- metadata +34 -15
- data/lib/whenever/job_types/rake_task.rb +0 -12
- data/lib/whenever/job_types/runner.rb +0 -12
data/CHANGELOG.rdoc
CHANGED
@@ -1,3 +1,30 @@
|
|
1
|
+
== 0.5.0 / June 28th, 2010
|
2
|
+
|
3
|
+
* New job_type API for writing custom jobs. Internals use this to define command, runner, and rake. [Javan Makhmali - inspired by idlefingers (Damien)]
|
4
|
+
|
5
|
+
* Jobs < 1.hour can specify an :at. [gorenje]
|
6
|
+
|
7
|
+
* --clear option to remove crontab entries for a specific [identifier]. [mraidel (Michael Raidel)]
|
8
|
+
|
9
|
+
|
10
|
+
== 0.4.2 / April 26th, 2010
|
11
|
+
|
12
|
+
* runners now cd into the app's directory and then execute. [Michael Guterl]
|
13
|
+
|
14
|
+
* Fix STDERR output redirection to file to append instead of overwrite. [weplay]
|
15
|
+
|
16
|
+
* Move require of tempfile lib to file that actually uses it. [Finn Smith]
|
17
|
+
|
18
|
+
* bugfix: comparison Time with 0 failed. #32 [Dan Hixon]
|
19
|
+
|
20
|
+
|
21
|
+
== 0.4.1 / November 30th, 2009
|
22
|
+
|
23
|
+
* exit(0) instead of just exit to make JRuby happy. [Elan Meng]
|
24
|
+
|
25
|
+
* Fixed activesupport deprecation warning by requiring active_support. #37 [Andrew Nesbitt]
|
26
|
+
|
27
|
+
|
1
28
|
== 0.4.0 / October 20th, 2009
|
2
29
|
|
3
30
|
* New output option replaces the old cron_log option for output redirection and is much more flexible. #31 [Peer Allan]
|
data/README.rdoc
CHANGED
@@ -7,18 +7,8 @@ Ryan Bates created a great Railscast about Whenever: http://railscasts.com/episo
|
|
7
7
|
Discussion: http://groups.google.com/group/whenever-gem
|
8
8
|
|
9
9
|
== Installation
|
10
|
-
|
11
|
-
If you haven't already, get set up with http://gemcutter.org
|
12
|
-
|
13
|
-
$ sudo gem install whenever
|
14
|
-
|
15
|
-
In a Rails (2.1 or greater) application:
|
16
10
|
|
17
|
-
|
18
|
-
|
19
|
-
Rails::Initializer.run do |config|
|
20
|
-
config.gem 'whenever', :lib => false, :source => 'http://gemcutter.org/'
|
21
|
-
end
|
11
|
+
$ sudo gem install whenever
|
22
12
|
|
23
13
|
== Getting started
|
24
14
|
|
@@ -49,6 +39,28 @@ This will create an initial "config/schedule.rb" file you.
|
|
49
39
|
|
50
40
|
More examples on the wiki: http://wiki.github.com/javan/whenever/instructions-and-examples
|
51
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
|
+
|
52
64
|
== Cron output
|
53
65
|
|
54
66
|
$ cd /my/rails/app
|
@@ -91,7 +103,7 @@ If you've found a genuine bug or issue, please use the Issues section on github:
|
|
91
103
|
|
92
104
|
== License
|
93
105
|
|
94
|
-
Copyright (c) 2009 Javan Makhmali
|
106
|
+
Copyright (c) 2009+ Javan Makhmali
|
95
107
|
|
96
108
|
Permission is hereby granted, free of charge, to any person
|
97
109
|
obtaining a copy of this software and associated documentation
|
data/bin/whenever
CHANGED
@@ -2,8 +2,6 @@
|
|
2
2
|
|
3
3
|
require 'rubygems'
|
4
4
|
require 'optparse'
|
5
|
-
require 'fileutils'
|
6
|
-
require 'tempfile'
|
7
5
|
require 'whenever'
|
8
6
|
|
9
7
|
options = Hash.new
|
@@ -16,6 +14,10 @@ OptionParser.new do |opts|
|
|
16
14
|
options[:update] = true
|
17
15
|
options[:identifier] = identifier if identifier
|
18
16
|
end
|
17
|
+
opts.on('-c', '--clear-crontab [identifier]') do |identifier|
|
18
|
+
options[:clear] = true
|
19
|
+
options[:identifier] = identifier if identifier
|
20
|
+
end
|
19
21
|
opts.on('-f', '--load-file [schedule file]', 'Default: config/schedule.rb') do |file|
|
20
22
|
options[:file] = file if file
|
21
23
|
end
|
@@ -27,4 +29,4 @@ OptionParser.new do |opts|
|
|
27
29
|
end
|
28
30
|
end.parse!
|
29
31
|
|
30
|
-
Whenever::CommandLine.execute(options)
|
32
|
+
Whenever::CommandLine.execute(options)
|
data/lib/whenever.rb
CHANGED
@@ -1,30 +1,19 @@
|
|
1
1
|
require 'chronic'
|
2
2
|
|
3
|
-
# Hoping to load Rails' Rakefile
|
4
|
-
begin
|
5
|
-
load 'Rakefile'
|
6
|
-
rescue LoadError
|
7
|
-
nil
|
8
|
-
end
|
9
|
-
|
10
|
-
# If Rails' rakefile was loaded than so was activesupport, but
|
11
|
-
# if this is being used in a non-rails enviroment we need to require it.
|
12
3
|
# It was previously defined as a dependency of this gem, but that became
|
13
4
|
# problematic. See: http://github.com/javan/whenever/issues#issue/1
|
14
5
|
begin
|
15
|
-
require '
|
6
|
+
require 'active_support/all'
|
16
7
|
rescue LoadError
|
17
|
-
warn 'To
|
18
|
-
warn '$
|
8
|
+
warn 'To use Whenever you need the active_support gem:'
|
9
|
+
warn '$ gem install activesupport'
|
19
10
|
exit(1)
|
20
11
|
end
|
21
12
|
|
22
13
|
# Whenever files
|
23
14
|
require 'whenever/base'
|
24
15
|
require 'whenever/job_list'
|
25
|
-
require 'whenever/
|
26
|
-
require 'whenever/job_types/rake_task'
|
27
|
-
require 'whenever/job_types/runner'
|
16
|
+
require 'whenever/job'
|
28
17
|
require 'whenever/outputs/cron'
|
29
18
|
require 'whenever/outputs/cron/output_redirection'
|
30
19
|
require 'whenever/command_line'
|
data/lib/whenever/base.rb
CHANGED
@@ -1,3 +1,6 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
require 'tempfile'
|
3
|
+
|
1
4
|
module Whenever
|
2
5
|
class CommandLine
|
3
6
|
|
@@ -16,14 +19,14 @@ module Whenever
|
|
16
19
|
exit(1)
|
17
20
|
end
|
18
21
|
|
19
|
-
if @options[:update]
|
20
|
-
warn("[fail] Can
|
22
|
+
if [@options[:update], @options[:write], @options[:clear]].compact.length > 1
|
23
|
+
warn("[fail] Can only update, write or clear. Choose one.")
|
21
24
|
exit(1)
|
22
25
|
end
|
23
26
|
end
|
24
27
|
|
25
28
|
def run
|
26
|
-
if @options[:update]
|
29
|
+
if @options[:update] || @options[:clear]
|
27
30
|
write_crontab(updated_crontab)
|
28
31
|
elsif @options[:write]
|
29
32
|
write_crontab(whenever_cron)
|
@@ -40,7 +43,7 @@ module Whenever
|
|
40
43
|
end
|
41
44
|
|
42
45
|
def whenever_cron
|
43
|
-
@whenever_cron ||= [comment_open, Whenever.cron(@options), comment_close].join("\n") + "\n"
|
46
|
+
@whenever_cron ||= [comment_open, (Whenever.cron(@options) unless @options[:clear]), comment_close].compact.join("\n") + "\n"
|
44
47
|
end
|
45
48
|
|
46
49
|
def read_crontab
|
@@ -105,4 +108,4 @@ module Whenever
|
|
105
108
|
end
|
106
109
|
|
107
110
|
end
|
108
|
-
end
|
111
|
+
end
|
data/lib/whenever/job.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
module Whenever
|
2
|
+
class Job
|
3
|
+
|
4
|
+
attr_accessor :at, :output_redirection
|
5
|
+
|
6
|
+
def initialize(options = {})
|
7
|
+
@options = options
|
8
|
+
|
9
|
+
@at = options[:at]
|
10
|
+
@output_redirection = options.has_key?(:output) ? options[:output] : :not_set
|
11
|
+
@options[:environment] ||= :production
|
12
|
+
@options[:path] ||= Whenever.path
|
13
|
+
end
|
14
|
+
|
15
|
+
def output
|
16
|
+
@options[:template].gsub(/:\w+/) do |key|
|
17
|
+
@options[key.sub(':', '').to_sym]
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
end
|
data/lib/whenever/job_list.rb
CHANGED
@@ -2,8 +2,7 @@ module Whenever
|
|
2
2
|
class JobList
|
3
3
|
|
4
4
|
def initialize(options)
|
5
|
-
@jobs =
|
6
|
-
@env = Hash.new
|
5
|
+
@jobs, @env, @set_variables = {}, {}, {}
|
7
6
|
|
8
7
|
case options
|
9
8
|
when String
|
@@ -16,7 +15,12 @@ module Whenever
|
|
16
15
|
end
|
17
16
|
pre_set(options[:set])
|
18
17
|
end
|
19
|
-
|
18
|
+
|
19
|
+
# Load all job type files.
|
20
|
+
Dir["#{File.expand_path(File.dirname(__FILE__))}/job_types/*.rb"].each do |file|
|
21
|
+
eval(File.read(file))
|
22
|
+
end
|
23
|
+
|
20
24
|
eval(config)
|
21
25
|
end
|
22
26
|
|
@@ -25,6 +29,7 @@ module Whenever
|
|
25
29
|
|
26
30
|
instance_variable_set("@#{variable}".to_sym, value)
|
27
31
|
self.class.send(:attr_reader, variable.to_sym)
|
32
|
+
@set_variables[variable] = value
|
28
33
|
end
|
29
34
|
|
30
35
|
def env(variable, value)
|
@@ -37,26 +42,21 @@ module Whenever
|
|
37
42
|
yield
|
38
43
|
end
|
39
44
|
|
40
|
-
def
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
def rake(task, options = {})
|
57
|
-
options.reverse_merge!(:environment => @environment, :path => @path)
|
58
|
-
options[:class] = Whenever::Job::RakeTask
|
59
|
-
command(task, options)
|
45
|
+
def job_type(name, template)
|
46
|
+
class_eval do
|
47
|
+
define_method(name) do |task, *args|
|
48
|
+
options = { :task => task, :template => template }
|
49
|
+
options.merge!(args[0]) if args[0].is_a? Hash
|
50
|
+
|
51
|
+
# :cron_log was an old option for output redirection, it remains for backwards compatibility
|
52
|
+
options[:output] = (options[:cron_log] || @cron_log) if defined?(@cron_log) || options.has_key?(:cron_log)
|
53
|
+
# :output is the newer, more flexible option.
|
54
|
+
options[:output] = @output if defined?(@output) && !options.has_key?(:output)
|
55
|
+
|
56
|
+
@jobs[@current_time_scope] ||= []
|
57
|
+
@jobs[@current_time_scope] << Whenever::Job.new(@options.merge(@set_variables).merge(options))
|
58
|
+
end
|
59
|
+
end
|
60
60
|
end
|
61
61
|
|
62
62
|
def generate_cron_output
|
@@ -79,7 +79,7 @@ module Whenever
|
|
79
79
|
pairs.each do |pair|
|
80
80
|
next unless pair.index('=')
|
81
81
|
variable, value = *pair.split('=')
|
82
|
-
set(variable.strip, value.strip) unless variable.blank? || value.blank?
|
82
|
+
set(variable.strip.to_sym, value.strip) unless variable.blank? || value.blank?
|
83
83
|
end
|
84
84
|
end
|
85
85
|
|
@@ -1,27 +1,3 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
attr_accessor :task, :at, :output, :output_redirection
|
6
|
-
|
7
|
-
def initialize(options = {})
|
8
|
-
@task = options[:task]
|
9
|
-
@at = options[:at]
|
10
|
-
@output_redirection = options.has_key?(:output) ? options[:output] : :not_set
|
11
|
-
@environment = options[:environment] || :production
|
12
|
-
@path = options[:path] || Whenever.path
|
13
|
-
end
|
14
|
-
|
15
|
-
def output
|
16
|
-
task
|
17
|
-
end
|
18
|
-
|
19
|
-
protected
|
20
|
-
|
21
|
-
def path_required
|
22
|
-
raise ArgumentError, "No path available; set :path, '/your/path' in your schedule file" if @path.blank?
|
23
|
-
end
|
24
|
-
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
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'
|
@@ -60,7 +60,7 @@ module Whenever
|
|
60
60
|
end
|
61
61
|
|
62
62
|
if shortcut
|
63
|
-
if @at >
|
63
|
+
if @at.is_a?(Time) || (@at.is_a?(Numeric) && @at>0)
|
64
64
|
raise ArgumentError, "You cannot specify an ':at' when using the shortcuts for times."
|
65
65
|
else
|
66
66
|
return shortcut
|
@@ -77,7 +77,7 @@ module Whenever
|
|
77
77
|
raise ArgumentError, "Time must be in minutes or higher"
|
78
78
|
when 1.minute...1.hour
|
79
79
|
minute_frequency = @time / 60
|
80
|
-
timing[0] = comma_separated_timing(minute_frequency, 59)
|
80
|
+
timing[0] = comma_separated_timing(minute_frequency, 59, @at || 0)
|
81
81
|
when 1.hour...1.day
|
82
82
|
hour_frequency = (@time / 60 / 60).round
|
83
83
|
timing[0] = @at.is_a?(Time) ? @at.min : @at
|
@@ -32,11 +32,17 @@ module Whenever
|
|
32
32
|
def redirect_from_hash
|
33
33
|
case
|
34
34
|
when stdout == '/dev/null' && stderr == '/dev/null'
|
35
|
-
"
|
35
|
+
"> /dev/null 2>&1"
|
36
|
+
when stdout && stderr == '/dev/null'
|
37
|
+
">> #{stdout} 2> /dev/null"
|
36
38
|
when stdout && stderr
|
37
|
-
">> #{stdout} 2
|
39
|
+
">> #{stdout} 2>> #{stderr}"
|
40
|
+
when stderr == '/dev/null'
|
41
|
+
"2> /dev/null"
|
38
42
|
when stderr
|
39
|
-
"2
|
43
|
+
"2>> #{stderr}"
|
44
|
+
when stdout == '/dev/null'
|
45
|
+
"> /dev/null"
|
40
46
|
when stdout
|
41
47
|
">> #{stdout}"
|
42
48
|
else
|
data/lib/whenever/version.rb
CHANGED
data/test/command_line_test.rb
CHANGED
@@ -74,6 +74,63 @@ EXISTING_CRON
|
|
74
74
|
#{@task}
|
75
75
|
# End Whenever generated tasks for: My identifier
|
76
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
|
+
|
77
134
|
# Begin Whenever generated tasks for: Other identifier
|
78
135
|
This shouldn't get replaced
|
79
136
|
# End Whenever generated tasks for: Other identifier
|
@@ -97,5 +154,24 @@ NEW_CRON
|
|
97
154
|
assert_equal "Whenever generated tasks for: DEFAULT", @command.send(:comment_base)
|
98
155
|
end
|
99
156
|
end
|
100
|
-
|
101
|
-
|
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
|
data/test/output_at_test.rb
CHANGED
@@ -91,7 +91,7 @@ class OutputAtTest < Test::Unit::TestCase
|
|
91
91
|
end
|
92
92
|
|
93
93
|
should "output the runner using one entry because the times are aligned" do
|
94
|
-
assert_match '2 5,15 * * 1,3,5 /your/path
|
94
|
+
assert_match '2 5,15 * * 1,3,5 cd /your/path && script/runner -e production "blahblah"', @output
|
95
95
|
end
|
96
96
|
end
|
97
97
|
|
@@ -115,7 +115,7 @@ class OutputAtTest < Test::Unit::TestCase
|
|
115
115
|
setup do
|
116
116
|
@output = Whenever.cron \
|
117
117
|
<<-file
|
118
|
-
every [1.month, 1.day], :at => '
|
118
|
+
every [1.month, 1.day], :at => 'january 5:02am, june 17th at 2:22pm, june 3rd at 3:33am' do
|
119
119
|
command "blahblah"
|
120
120
|
end
|
121
121
|
file
|
@@ -168,11 +168,70 @@ class OutputAtTest < Test::Unit::TestCase
|
|
168
168
|
|
169
169
|
should "output all of the commands @daily" do
|
170
170
|
assert_match '@daily cd /your/path && RAILS_ENV=production /usr/bin/env rake blah:blah', @output
|
171
|
-
assert_match '@daily /your/path
|
171
|
+
assert_match '@daily cd /your/path && script/runner -e production "runner_1"', @output
|
172
172
|
assert_match '@daily command_1', @output
|
173
|
-
assert_match '@daily /your/path
|
173
|
+
assert_match '@daily cd /your/path && script/runner -e production "runner_2"', @output
|
174
174
|
assert_match '@daily command_2', @output
|
175
175
|
end
|
176
176
|
end
|
177
177
|
|
178
|
+
context "every 5 minutes but but starting at 1" do
|
179
|
+
setup do
|
180
|
+
@output = Whenever.cron \
|
181
|
+
<<-file
|
182
|
+
every 5.minutes, :at => 1 do
|
183
|
+
command "blahblah"
|
184
|
+
end
|
185
|
+
file
|
186
|
+
end
|
187
|
+
|
188
|
+
should "output the command using that time" do
|
189
|
+
assert_match '1,6,11,16,21,26,31,36,41,46,51,56 * * * * blahblah', @output
|
190
|
+
end
|
191
|
+
end
|
192
|
+
|
193
|
+
context "every 4 minutes but starting at 2" do
|
194
|
+
setup do
|
195
|
+
@output = Whenever.cron \
|
196
|
+
<<-file
|
197
|
+
every 4.minutes, :at => 2 do
|
198
|
+
command "blahblah"
|
199
|
+
end
|
200
|
+
file
|
201
|
+
end
|
202
|
+
|
203
|
+
should "output the command using that time" do
|
204
|
+
assert_match '2,6,10,14,18,22,26,30,34,38,42,46,50,54,58 * * * * blahblah', @output
|
205
|
+
end
|
206
|
+
end
|
207
|
+
|
208
|
+
context "every 3 minutes but starting at 7" do
|
209
|
+
setup do
|
210
|
+
@output = Whenever.cron \
|
211
|
+
<<-file
|
212
|
+
every 3.minutes, :at => 7 do
|
213
|
+
command "blahblah"
|
214
|
+
end
|
215
|
+
file
|
216
|
+
end
|
217
|
+
|
218
|
+
should "output the command using that time" do
|
219
|
+
assert_match '7,10,13,16,19,22,25,28,31,34,37,40,43,46,49,52,55,58 * * * * blahblah', @output
|
220
|
+
end
|
221
|
+
end
|
222
|
+
|
223
|
+
context "every 2 minutes but starting at 27" do
|
224
|
+
setup do
|
225
|
+
@output = Whenever.cron \
|
226
|
+
<<-file
|
227
|
+
every 2.minutes, :at => 27 do
|
228
|
+
command "blahblah"
|
229
|
+
end
|
230
|
+
file
|
231
|
+
end
|
232
|
+
|
233
|
+
should "output the command using that time" do
|
234
|
+
assert_match '27,29,31,33,35,37,39,41,43,45,47,49,51,53,55,57,59 * * * * blahblah', @output
|
235
|
+
end
|
236
|
+
end
|
178
237
|
end
|
@@ -0,0 +1,87 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + "/test_helper")
|
2
|
+
|
3
|
+
class OutputDefinedJobTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
context "A defined job with a :task" do
|
6
|
+
setup do
|
7
|
+
@output = Whenever.cron \
|
8
|
+
<<-file
|
9
|
+
job_type :some_job, "before :task after"
|
10
|
+
every 2.hours do
|
11
|
+
some_job "during"
|
12
|
+
end
|
13
|
+
file
|
14
|
+
end
|
15
|
+
|
16
|
+
should "output the defined job with the task" do
|
17
|
+
assert_match /^.+ .+ .+ .+ before during after$/, @output
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
context "A defined job with a :task and some options" do
|
22
|
+
setup do
|
23
|
+
@output = Whenever.cron \
|
24
|
+
<<-file
|
25
|
+
job_type :some_job, "before :task after :option1 :option2"
|
26
|
+
every 2.hours do
|
27
|
+
some_job "during", :option1 => 'happy', :option2 => 'birthday'
|
28
|
+
end
|
29
|
+
file
|
30
|
+
end
|
31
|
+
|
32
|
+
should "output the defined job with the task and options" do
|
33
|
+
assert_match /^.+ .+ .+ .+ before during after happy birthday$/, @output
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
context "A defined job with a :task and an option where the option is set globally" do
|
38
|
+
setup do
|
39
|
+
@output = Whenever.cron \
|
40
|
+
<<-file
|
41
|
+
job_type :some_job, "before :task after :option1"
|
42
|
+
set :option1, 'happy'
|
43
|
+
every 2.hours do
|
44
|
+
some_job "during"
|
45
|
+
end
|
46
|
+
file
|
47
|
+
end
|
48
|
+
|
49
|
+
should "output the defined job with the task and options" do
|
50
|
+
assert_match /^.+ .+ .+ .+ before during after happy$/, @output
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
context "A defined job with a :task and an option where the option is set globally and locally" do
|
55
|
+
setup do
|
56
|
+
@output = Whenever.cron \
|
57
|
+
<<-file
|
58
|
+
job_type :some_job, "before :task after :option1"
|
59
|
+
set :option1, 'global'
|
60
|
+
every 2.hours do
|
61
|
+
some_job "during", :option1 => 'local'
|
62
|
+
end
|
63
|
+
file
|
64
|
+
end
|
65
|
+
|
66
|
+
should "output the defined job using the local option" do
|
67
|
+
assert_match /^.+ .+ .+ .+ before during after local$/, @output
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
context "A defined job with a :task and an option that is not set" do
|
72
|
+
setup do
|
73
|
+
@output = Whenever.cron \
|
74
|
+
<<-file
|
75
|
+
job_type :some_job, "before :task after :option1"
|
76
|
+
every 2.hours do
|
77
|
+
some_job "during", :option2 => 'happy'
|
78
|
+
end
|
79
|
+
file
|
80
|
+
end
|
81
|
+
|
82
|
+
should "output the defined job with that option removed" do
|
83
|
+
assert_match /^.+ .+ .+ .+ before during after$/, @output
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
end
|
@@ -46,7 +46,7 @@ class OutputRedirectionTest < Test::Unit::TestCase
|
|
46
46
|
end
|
47
47
|
|
48
48
|
should "output the command without the log syntax appended" do
|
49
|
-
assert_match /^.+ .+ .+ .+ blahblah >> dev_null 2
|
49
|
+
assert_match /^.+ .+ .+ .+ blahblah >> dev_null 2>> dev_err$/, @output
|
50
50
|
end
|
51
51
|
end
|
52
52
|
|
@@ -80,7 +80,7 @@ class OutputRedirectionTest < Test::Unit::TestCase
|
|
80
80
|
|
81
81
|
should "output the command with the overridden redirection syntax appended" do
|
82
82
|
assert_no_match /.+ .+ .+ .+ blahblah >> logfile.log 2>&1/, @output
|
83
|
-
assert_match /^.+ .+ .+ .+ blahblah >> dev_null 2
|
83
|
+
assert_match /^.+ .+ .+ .+ blahblah >> dev_null 2>> dev_err$/, @output
|
84
84
|
end
|
85
85
|
end
|
86
86
|
|
@@ -130,7 +130,7 @@ class OutputRedirectionTest < Test::Unit::TestCase
|
|
130
130
|
end
|
131
131
|
|
132
132
|
should "output the command without the redirection syntax appended" do
|
133
|
-
assert_match /^.+ .+ .+ .+ blahblah >> dev_null 2
|
133
|
+
assert_match /^.+ .+ .+ .+ blahblah >> dev_null 2>> dev_err$/, @output
|
134
134
|
end
|
135
135
|
end
|
136
136
|
|
@@ -145,8 +145,8 @@ class OutputRedirectionTest < Test::Unit::TestCase
|
|
145
145
|
file
|
146
146
|
end
|
147
147
|
|
148
|
-
should "output the command without the standard
|
149
|
-
assert_match /^.+ .+ .+ .+ blahblah 2
|
148
|
+
should "output the command without the standard error syntax appended" do
|
149
|
+
assert_match /^.+ .+ .+ .+ blahblah 2>> dev_null$/, @output
|
150
150
|
end
|
151
151
|
end
|
152
152
|
|
@@ -177,7 +177,7 @@ class OutputRedirectionTest < Test::Unit::TestCase
|
|
177
177
|
end
|
178
178
|
|
179
179
|
should "output the command without the log syntax appended" do
|
180
|
-
assert_match /^.+ .+ .+ .+ blahblah 2
|
180
|
+
assert_match /^.+ .+ .+ .+ blahblah 2>> dev_err$/, @output
|
181
181
|
end
|
182
182
|
end
|
183
183
|
|
@@ -207,7 +207,7 @@ class OutputRedirectionTest < Test::Unit::TestCase
|
|
207
207
|
end
|
208
208
|
|
209
209
|
should "output the command with stdout directed to /dev/null" do
|
210
|
-
assert_match /^.+ .+ .+ .+ blahblah
|
210
|
+
assert_match /^.+ .+ .+ .+ blahblah > \/dev\/null$/, @output
|
211
211
|
end
|
212
212
|
end
|
213
213
|
|
@@ -237,7 +237,7 @@ class OutputRedirectionTest < Test::Unit::TestCase
|
|
237
237
|
end
|
238
238
|
|
239
239
|
should "output the command with stderr directed to /dev/null" do
|
240
|
-
assert_match /^.+ .+ .+ .+ blahblah
|
240
|
+
assert_match /^.+ .+ .+ .+ blahblah > \/dev\/null 2>&1$/, @output
|
241
241
|
end
|
242
242
|
end
|
243
243
|
|
@@ -267,7 +267,7 @@ class OutputRedirectionTest < Test::Unit::TestCase
|
|
267
267
|
end
|
268
268
|
|
269
269
|
should "output the command with stderr directed to /dev/null" do
|
270
|
-
assert_match /^.+ .+ .+ .+ blahblah >> \/dev\/null 2
|
270
|
+
assert_match /^.+ .+ .+ .+ blahblah >> \/dev\/null 2>> my_error.log$/, @output
|
271
271
|
end
|
272
272
|
end
|
273
273
|
|
@@ -286,4 +286,4 @@ class OutputRedirectionTest < Test::Unit::TestCase
|
|
286
286
|
assert_match /^.+ .+ .+ .+ blahblah >> cron.log 2>&1$/, @output
|
287
287
|
end
|
288
288
|
end
|
289
|
-
end
|
289
|
+
end
|
data/test/output_runner_test.rb
CHANGED
@@ -14,7 +14,7 @@ class OutputRunnerTest < Test::Unit::TestCase
|
|
14
14
|
end
|
15
15
|
|
16
16
|
should "output the runner using that path" do
|
17
|
-
assert_match two_hours + ' /my/path
|
17
|
+
assert_match two_hours + ' cd /my/path && script/runner -e production "blahblah"', @output
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
@@ -30,7 +30,7 @@ class OutputRunnerTest < Test::Unit::TestCase
|
|
30
30
|
end
|
31
31
|
|
32
32
|
should "output the runner using that path" do
|
33
|
-
assert_match two_hours + ' /some/other/path
|
33
|
+
assert_match two_hours + ' cd /some/other/path && script/runner -e production "blahblah"', @output
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
@@ -47,7 +47,7 @@ class OutputRunnerTest < Test::Unit::TestCase
|
|
47
47
|
end
|
48
48
|
|
49
49
|
should "output the runner using that path" do
|
50
|
-
assert_match two_hours + ' /my/path
|
50
|
+
assert_match two_hours + ' cd /my/path && script/runner -e production "blahblah"', @output
|
51
51
|
end
|
52
52
|
end
|
53
53
|
|
@@ -65,29 +65,11 @@ class OutputRunnerTest < Test::Unit::TestCase
|
|
65
65
|
end
|
66
66
|
|
67
67
|
should "use the path" do
|
68
|
-
assert_match two_hours + ' /my/path
|
68
|
+
assert_match two_hours + ' cd /my/path && script/runner -e production "blahblah"', @output
|
69
69
|
assert_no_match /\/rails\/path/, @output
|
70
70
|
end
|
71
71
|
end
|
72
72
|
|
73
|
-
context "A runner with no path set and no RAILS_ROOT defined" do
|
74
|
-
setup do
|
75
|
-
Whenever.stubs(:path).returns(nil)
|
76
|
-
|
77
|
-
@input = <<-file
|
78
|
-
every 2.hours do
|
79
|
-
runner "blahblah"
|
80
|
-
end
|
81
|
-
file
|
82
|
-
end
|
83
|
-
|
84
|
-
should "raise an exception" do
|
85
|
-
assert_raises ArgumentError do
|
86
|
-
Whenever.cron(@input)
|
87
|
-
end
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
73
|
context "A runner with an environment set" do
|
92
74
|
setup do
|
93
75
|
@output = Whenever.cron \
|
@@ -101,7 +83,7 @@ class OutputRunnerTest < Test::Unit::TestCase
|
|
101
83
|
end
|
102
84
|
|
103
85
|
should "output the runner using that environment" do
|
104
|
-
assert_match two_hours + ' /my/path
|
86
|
+
assert_match two_hours + ' cd /my/path && script/runner -e silly "blahblah"', @output
|
105
87
|
end
|
106
88
|
end
|
107
89
|
|
@@ -118,7 +100,7 @@ class OutputRunnerTest < Test::Unit::TestCase
|
|
118
100
|
end
|
119
101
|
|
120
102
|
should "output the runner using that environment" do
|
121
|
-
assert_match two_hours + ' /my/path
|
103
|
+
assert_match two_hours + ' cd /my/path && script/runner -e serious "blahblah"', @output
|
122
104
|
end
|
123
105
|
end
|
124
106
|
|
@@ -135,7 +117,7 @@ class OutputRunnerTest < Test::Unit::TestCase
|
|
135
117
|
end
|
136
118
|
|
137
119
|
should "output the runner using the override environment" do
|
138
|
-
assert_match two_hours + ' /my/path
|
120
|
+
assert_match two_hours + ' cd /my/path && script/runner -e serious "blahblah"', @output
|
139
121
|
end
|
140
122
|
end
|
141
123
|
|
@@ -152,7 +134,7 @@ class OutputRunnerTest < Test::Unit::TestCase
|
|
152
134
|
end
|
153
135
|
|
154
136
|
should "output the runner using the overridden path and environment" do
|
155
|
-
assert_match two_hours + ' /serious/path
|
137
|
+
assert_match two_hours + ' cd /serious/path && script/runner -e serious "blahblah"', @output
|
156
138
|
end
|
157
139
|
end
|
158
140
|
|
@@ -169,7 +151,7 @@ class OutputRunnerTest < Test::Unit::TestCase
|
|
169
151
|
end
|
170
152
|
|
171
153
|
should "output the runner using the overridden path and environment" do
|
172
|
-
assert_match two_hours + ' /serious/path
|
154
|
+
assert_match two_hours + ' cd /serious/path && script/runner -e serious "blahblah"', @output
|
173
155
|
end
|
174
156
|
end
|
175
157
|
|
@@ -186,23 +168,7 @@ class OutputRunnerTest < Test::Unit::TestCase
|
|
186
168
|
end
|
187
169
|
|
188
170
|
should "output the runner using the original environmnet" do
|
189
|
-
assert_match two_hours + ' /silly/path
|
190
|
-
end
|
191
|
-
end
|
192
|
-
|
193
|
-
context "A runner which makes use of double quotes" do
|
194
|
-
setup do
|
195
|
-
@output = Whenever.cron \
|
196
|
-
<<-file
|
197
|
-
set :path, '/my/path'
|
198
|
-
every 2.hours do
|
199
|
-
runner 'Product.import("http://example.com/product.xml")'
|
200
|
-
end
|
201
|
-
file
|
202
|
-
end
|
203
|
-
|
204
|
-
should "output the runner using the original environmnet" do
|
205
|
-
assert_match two_hours + ' /my/path/script/runner -e production "Product.import(\"http://example.com/product.xml\")"', @output
|
171
|
+
assert_match two_hours + ' cd /silly/path && script/runner -e silly "blahblah"', @output
|
206
172
|
end
|
207
173
|
end
|
208
174
|
|
data/whenever.gemspec
CHANGED
@@ -5,13 +5,13 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{insrc-whenever}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.5.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
-
s.authors = ["
|
12
|
-
s.date = %q{
|
13
|
-
s.description = %q{Clean ruby syntax for defining and deploying messy cron jobs.
|
14
|
-
s.email = %q{
|
11
|
+
s.authors = ["IN SRC Studio"]
|
12
|
+
s.date = %q{2010-06-28}
|
13
|
+
s.description = %q{Clean ruby syntax for defining and deploying messy cron jobs.}
|
14
|
+
s.email = %q{elanmeng@in-src.com}
|
15
15
|
s.executables = ["whenever", "wheneverize"]
|
16
16
|
s.extra_rdoc_files = [
|
17
17
|
"README.rdoc"
|
@@ -26,10 +26,9 @@ Gem::Specification.new do |s|
|
|
26
26
|
"lib/whenever.rb",
|
27
27
|
"lib/whenever/base.rb",
|
28
28
|
"lib/whenever/command_line.rb",
|
29
|
+
"lib/whenever/job.rb",
|
29
30
|
"lib/whenever/job_list.rb",
|
30
31
|
"lib/whenever/job_types/default.rb",
|
31
|
-
"lib/whenever/job_types/rake_task.rb",
|
32
|
-
"lib/whenever/job_types/runner.rb",
|
33
32
|
"lib/whenever/outputs/cron.rb",
|
34
33
|
"lib/whenever/outputs/cron/output_redirection.rb",
|
35
34
|
"lib/whenever/version.rb",
|
@@ -37,6 +36,7 @@ Gem::Specification.new do |s|
|
|
37
36
|
"test/cron_test.rb",
|
38
37
|
"test/output_at_test.rb",
|
39
38
|
"test/output_command_test.rb",
|
39
|
+
"test/output_defined_job_test.rb",
|
40
40
|
"test/output_env_test.rb",
|
41
41
|
"test/output_rake_test.rb",
|
42
42
|
"test/output_redirection_test.rb",
|
@@ -44,16 +44,17 @@ Gem::Specification.new do |s|
|
|
44
44
|
"test/test_helper.rb",
|
45
45
|
"whenever.gemspec"
|
46
46
|
]
|
47
|
-
s.homepage = %q{http://github.com/
|
47
|
+
s.homepage = %q{http://github.com/javan/whenever}
|
48
48
|
s.rdoc_options = ["--charset=UTF-8"]
|
49
49
|
s.require_paths = ["lib"]
|
50
|
-
s.rubygems_version = %q{1.3.
|
50
|
+
s.rubygems_version = %q{1.3.6}
|
51
51
|
s.summary = %q{Clean ruby syntax for defining and deploying messy cron jobs.}
|
52
52
|
s.test_files = [
|
53
53
|
"test/command_line_test.rb",
|
54
54
|
"test/cron_test.rb",
|
55
55
|
"test/output_at_test.rb",
|
56
56
|
"test/output_command_test.rb",
|
57
|
+
"test/output_defined_job_test.rb",
|
57
58
|
"test/output_env_test.rb",
|
58
59
|
"test/output_rake_test.rb",
|
59
60
|
"test/output_redirection_test.rb",
|
metadata
CHANGED
@@ -1,29 +1,41 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: insrc-whenever
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
hash: 11
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 5
|
9
|
+
- 0
|
10
|
+
version: 0.5.0
|
5
11
|
platform: ruby
|
6
12
|
authors:
|
7
|
-
-
|
13
|
+
- IN SRC Studio
|
8
14
|
autorequire:
|
9
15
|
bindir: bin
|
10
16
|
cert_chain: []
|
11
17
|
|
12
|
-
date:
|
18
|
+
date: 2010-06-28 00:00:00 +08:00
|
13
19
|
default_executable:
|
14
20
|
dependencies:
|
15
21
|
- !ruby/object:Gem::Dependency
|
16
22
|
name: chronic
|
17
|
-
|
18
|
-
|
19
|
-
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
20
26
|
requirements:
|
21
27
|
- - ">="
|
22
28
|
- !ruby/object:Gem::Version
|
29
|
+
hash: 17
|
30
|
+
segments:
|
31
|
+
- 0
|
32
|
+
- 2
|
33
|
+
- 3
|
23
34
|
version: 0.2.3
|
24
|
-
|
25
|
-
|
26
|
-
|
35
|
+
type: :runtime
|
36
|
+
version_requirements: *id001
|
37
|
+
description: Clean ruby syntax for defining and deploying messy cron jobs.
|
38
|
+
email: elanmeng@in-src.com
|
27
39
|
executables:
|
28
40
|
- whenever
|
29
41
|
- wheneverize
|
@@ -41,10 +53,9 @@ files:
|
|
41
53
|
- lib/whenever.rb
|
42
54
|
- lib/whenever/base.rb
|
43
55
|
- lib/whenever/command_line.rb
|
56
|
+
- lib/whenever/job.rb
|
44
57
|
- lib/whenever/job_list.rb
|
45
58
|
- lib/whenever/job_types/default.rb
|
46
|
-
- lib/whenever/job_types/rake_task.rb
|
47
|
-
- lib/whenever/job_types/runner.rb
|
48
59
|
- lib/whenever/outputs/cron.rb
|
49
60
|
- lib/whenever/outputs/cron/output_redirection.rb
|
50
61
|
- lib/whenever/version.rb
|
@@ -52,6 +63,7 @@ files:
|
|
52
63
|
- test/cron_test.rb
|
53
64
|
- test/output_at_test.rb
|
54
65
|
- test/output_command_test.rb
|
66
|
+
- test/output_defined_job_test.rb
|
55
67
|
- test/output_env_test.rb
|
56
68
|
- test/output_rake_test.rb
|
57
69
|
- test/output_redirection_test.rb
|
@@ -59,7 +71,7 @@ files:
|
|
59
71
|
- test/test_helper.rb
|
60
72
|
- whenever.gemspec
|
61
73
|
has_rdoc: true
|
62
|
-
homepage: http://github.com/
|
74
|
+
homepage: http://github.com/javan/whenever
|
63
75
|
licenses: []
|
64
76
|
|
65
77
|
post_install_message:
|
@@ -68,21 +80,27 @@ rdoc_options:
|
|
68
80
|
require_paths:
|
69
81
|
- lib
|
70
82
|
required_ruby_version: !ruby/object:Gem::Requirement
|
83
|
+
none: false
|
71
84
|
requirements:
|
72
85
|
- - ">="
|
73
86
|
- !ruby/object:Gem::Version
|
87
|
+
hash: 3
|
88
|
+
segments:
|
89
|
+
- 0
|
74
90
|
version: "0"
|
75
|
-
version:
|
76
91
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
92
|
+
none: false
|
77
93
|
requirements:
|
78
94
|
- - ">="
|
79
95
|
- !ruby/object:Gem::Version
|
96
|
+
hash: 3
|
97
|
+
segments:
|
98
|
+
- 0
|
80
99
|
version: "0"
|
81
|
-
version:
|
82
100
|
requirements: []
|
83
101
|
|
84
102
|
rubyforge_project:
|
85
|
-
rubygems_version: 1.3.
|
103
|
+
rubygems_version: 1.3.7
|
86
104
|
signing_key:
|
87
105
|
specification_version: 3
|
88
106
|
summary: Clean ruby syntax for defining and deploying messy cron jobs.
|
@@ -91,6 +109,7 @@ test_files:
|
|
91
109
|
- test/cron_test.rb
|
92
110
|
- test/output_at_test.rb
|
93
111
|
- test/output_command_test.rb
|
112
|
+
- test/output_defined_job_test.rb
|
94
113
|
- test/output_env_test.rb
|
95
114
|
- test/output_rake_test.rb
|
96
115
|
- test/output_redirection_test.rb
|