whenever 0.3.7 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +3 -0
- data/CHANGELOG.rdoc +7 -0
- data/README.rdoc +5 -23
- data/Rakefile +28 -9
- data/bin/whenever +1 -3
- data/bin/wheneverize +1 -1
- data/lib/{base.rb → whenever/base.rb} +1 -1
- data/lib/{command_line.rb → whenever/command_line.rb} +0 -0
- data/lib/{job_list.rb → whenever/job_list.rb} +5 -3
- data/lib/whenever/job_types/default.rb +27 -0
- data/lib/{job_types → whenever/job_types}/rake_task.rb +0 -0
- data/lib/{job_types → whenever/job_types}/runner.rb +0 -0
- data/lib/whenever/outputs/cron/output_redirection.rb +54 -0
- data/lib/{outputs → whenever/outputs}/cron.rb +11 -3
- data/lib/whenever/version.rb +3 -0
- data/lib/whenever.rb +17 -22
- data/test/output_command_test.rb +1 -68
- data/test/output_redirection_test.rb +289 -0
- data/whenever.gemspec +52 -10
- metadata +22 -36
- data/Manifest +0 -24
- data/lib/job_types/default.rb +0 -27
- data/lib/version.rb +0 -9
data/.gitignore
ADDED
data/CHANGELOG.rdoc
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
== 0.4.0 / October 20th, 2009
|
2
|
+
|
3
|
+
* New output option replaces the old cron_log option for output redirection and is much more flexible. #31 [Peer Allan]
|
4
|
+
|
5
|
+
* Reorganized the lib files (http://weblog.rubyonrails.org/2009/9/1/gem-packaging-best-practices) and switched to Jeweler from Echoe.
|
6
|
+
|
7
|
+
|
1
8
|
== 0.3.7 / September 4th, 2009
|
2
9
|
|
3
10
|
* No longer tries (and fails) to combine @shortcut jobs. #20 [Javan Makhmali]
|
data/README.rdoc
CHANGED
@@ -8,35 +8,17 @@ Discussion: http://groups.google.com/group/whenever-gem
|
|
8
8
|
|
9
9
|
== Installation
|
10
10
|
|
11
|
-
|
11
|
+
If you haven't already, get set up with http://gemcutter.org
|
12
12
|
|
13
|
-
$ gem
|
14
|
-
$ sudo gem install javan-whenever
|
13
|
+
$ sudo gem install whenever
|
15
14
|
|
16
15
|
In a Rails (2.1 or greater) application:
|
17
16
|
|
18
17
|
in your "config/environment.rb" file:
|
19
18
|
|
20
19
|
Rails::Initializer.run do |config|
|
21
|
-
config.gem '
|
20
|
+
config.gem 'whenever', :lib => false, :source => 'http://gemcutter.org/'
|
22
21
|
end
|
23
|
-
|
24
|
-
To install this gem (and all other missing gem dependencies), run rake gems:install (use sudo if necessary).
|
25
|
-
|
26
|
-
In older versions of Rails:
|
27
|
-
|
28
|
-
$ gem sources -a http://gems.github.com #you only need to run this once
|
29
|
-
$ gem install javan-whenever
|
30
|
-
|
31
|
-
in your "config/environment.rb" file:
|
32
|
-
|
33
|
-
Rails::Initializer.run do |config|
|
34
|
-
...
|
35
|
-
end
|
36
|
-
|
37
|
-
require 'whenever'
|
38
|
-
|
39
|
-
NOTE: Requiring the whenever gem inside your Rails application is technically optional. However, if you plan to use something like Capistrano to automatically deploy and write your crontab file, you'll need to have the gem installed on your servers, and requiring it in your app is one way to ensure this.
|
40
22
|
|
41
23
|
== Getting started
|
42
24
|
|
@@ -66,13 +48,13 @@ This will create an initial "config/schedule.rb" file you.
|
|
66
48
|
end
|
67
49
|
|
68
50
|
More examples on the wiki: http://wiki.github.com/javan/whenever/instructions-and-examples
|
69
|
-
|
51
|
+
|
70
52
|
== Cron output
|
71
53
|
|
72
54
|
$ cd /my/rails/app
|
73
55
|
$ whenever
|
74
56
|
|
75
|
-
And you'll see your schedule.rb converted to cron sytax
|
57
|
+
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.
|
76
58
|
|
77
59
|
== Capistrano integration
|
78
60
|
|
data/Rakefile
CHANGED
@@ -1,13 +1,32 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
require 'rake'
|
3
|
-
require 'echoe'
|
4
3
|
|
5
|
-
require
|
4
|
+
require 'lib/whenever/version.rb'
|
6
5
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
6
|
+
begin
|
7
|
+
require 'jeweler'
|
8
|
+
Jeweler::Tasks.new do |gemspec|
|
9
|
+
gemspec.name = "whenever"
|
10
|
+
gemspec.version = Whenever::VERSION
|
11
|
+
gemspec.summary = "Clean ruby syntax for defining and deploying messy cron jobs."
|
12
|
+
gemspec.description = "Clean ruby syntax for defining and deploying messy cron jobs."
|
13
|
+
gemspec.email = "javan@javan.us"
|
14
|
+
gemspec.homepage = "http://github.com/javan/whenever"
|
15
|
+
gemspec.authors = ["Javan Makhmali"]
|
16
|
+
gemspec.add_dependency("chronic", '>= 0.2.3')
|
17
|
+
end
|
18
|
+
Jeweler::GemcutterTasks.new
|
19
|
+
rescue LoadError
|
20
|
+
puts "Jeweler not available. Install it with: sudo gem install jeweler -s http://gemcutter.org"
|
21
|
+
end
|
22
|
+
|
23
|
+
require 'rake/testtask'
|
24
|
+
Rake::TestTask.new(:test) do |test|
|
25
|
+
test.libs << 'lib' << 'test'
|
26
|
+
test.pattern = 'test/*.rb'
|
27
|
+
test.verbose = true
|
28
|
+
end
|
29
|
+
|
30
|
+
task :test => :check_dependencies
|
31
|
+
|
32
|
+
task :default => :test
|
data/bin/whenever
CHANGED
@@ -6,13 +6,11 @@ require 'fileutils'
|
|
6
6
|
require 'tempfile'
|
7
7
|
require 'whenever'
|
8
8
|
|
9
|
-
require File.expand_path(File.dirname(__FILE__) + "/../lib/version")
|
10
|
-
|
11
9
|
options = Hash.new
|
12
10
|
|
13
11
|
OptionParser.new do |opts|
|
14
12
|
opts.banner = "Usage: whenever [options]"
|
15
|
-
opts.on('-v', '--version') { puts "Whenever v#{Whenever::VERSION
|
13
|
+
opts.on('-v', '--version') { puts "Whenever v#{Whenever::VERSION}"; exit }
|
16
14
|
opts.on('-w', '--write-crontab') { options[:write] = true }
|
17
15
|
opts.on('-i', '--update-crontab [identifier]', 'Default: full path to schedule.rb file') do |identifier|
|
18
16
|
options[:update] = true
|
data/bin/wheneverize
CHANGED
File without changes
|
@@ -38,8 +38,11 @@ module Whenever
|
|
38
38
|
end
|
39
39
|
|
40
40
|
def command(task, options = {})
|
41
|
-
|
42
|
-
options[:
|
41
|
+
# :cron_log was an old option for output redirection, it remains for backwards compatibility
|
42
|
+
options[:output] = (options[:cron_log] || @cron_log) if defined?(@cron_log) || options.has_key?(:cron_log)
|
43
|
+
# :output is the newer, more flexible option.
|
44
|
+
options[:output] = @output if defined?(@output) && !options.has_key?(:output)
|
45
|
+
options[:class] ||= Whenever::Job::Default
|
43
46
|
@jobs[@current_time_scope] ||= []
|
44
47
|
@jobs[@current_time_scope] << options[:class].new(@options.merge(:task => task).merge(options))
|
45
48
|
end
|
@@ -140,7 +143,6 @@ module Whenever
|
|
140
143
|
@jobs.each do |time, jobs|
|
141
144
|
jobs.each do |job|
|
142
145
|
Whenever::Output::Cron.output(time, job) do |cron|
|
143
|
-
cron << " >> #{job.cron_log} 2>&1" if job.cron_log
|
144
146
|
cron << "\n\n"
|
145
147
|
|
146
148
|
if cron.starts_with?("@")
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Whenever
|
2
|
+
module Job
|
3
|
+
class Default
|
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
|
File without changes
|
File without changes
|
@@ -0,0 +1,54 @@
|
|
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
|
37
|
+
">> #{stdout} 2> #{stderr}"
|
38
|
+
when stderr
|
39
|
+
"2> #{stderr}"
|
40
|
+
when stdout
|
41
|
+
">> #{stdout}"
|
42
|
+
else
|
43
|
+
''
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def redirect_from_string
|
48
|
+
">> #{@output} 2>&1"
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -5,10 +5,11 @@ module Whenever
|
|
5
5
|
|
6
6
|
attr_accessor :time, :task
|
7
7
|
|
8
|
-
def initialize(time = nil, task = nil, at = nil)
|
8
|
+
def initialize(time = nil, task = nil, at = nil, output_redirection = nil)
|
9
9
|
@time = time
|
10
10
|
@task = task
|
11
11
|
@at = at.is_a?(String) ? (Chronic.parse(at) || 0) : (at || 0)
|
12
|
+
@output_redirection = output_redirection
|
12
13
|
end
|
13
14
|
|
14
15
|
def self.enumerate(item)
|
@@ -24,11 +25,14 @@ module Whenever
|
|
24
25
|
def self.output(times, job)
|
25
26
|
enumerate(times).each do |time|
|
26
27
|
enumerate(job.at).each do |at|
|
27
|
-
|
28
|
-
yield "#{out.time_in_cron_syntax} #{out.task}"
|
28
|
+
yield new(time, job.output, at, job.output_redirection).output
|
29
29
|
end
|
30
30
|
end
|
31
31
|
end
|
32
|
+
|
33
|
+
def output
|
34
|
+
[time_in_cron_syntax, task, output_redirection].compact.join(' ').strip
|
35
|
+
end
|
32
36
|
|
33
37
|
def time_in_cron_syntax
|
34
38
|
case @time
|
@@ -37,6 +41,10 @@ module Whenever
|
|
37
41
|
else parse_time
|
38
42
|
end
|
39
43
|
end
|
44
|
+
|
45
|
+
def output_redirection
|
46
|
+
OutputRedirection.new(@output_redirection).to_s unless @output_redirection == :not_set
|
47
|
+
end
|
40
48
|
|
41
49
|
protected
|
42
50
|
|
data/lib/whenever.rb
CHANGED
@@ -1,36 +1,31 @@
|
|
1
|
-
unless defined?(Whenever)
|
2
|
-
$:.unshift(File.dirname(__FILE__))
|
3
|
-
|
4
|
-
# Hoping to load Rails' Rakefile
|
5
|
-
begin
|
6
|
-
load 'Rakefile'
|
7
|
-
rescue LoadError => e
|
8
|
-
nil
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
1
|
require 'chronic'
|
13
2
|
|
3
|
+
# Hoping to load Rails' Rakefile
|
4
|
+
begin
|
5
|
+
load 'Rakefile'
|
6
|
+
rescue LoadError
|
7
|
+
nil
|
8
|
+
end
|
9
|
+
|
14
10
|
# If Rails' rakefile was loaded than so was activesupport, but
|
15
11
|
# if this is being used in a non-rails enviroment we need to require it.
|
16
12
|
# It was previously defined as a dependency of this gem, but that became
|
17
13
|
# problematic. See: http://github.com/javan/whenever/issues#issue/1
|
18
14
|
begin
|
19
15
|
require 'activesupport'
|
20
|
-
rescue LoadError
|
16
|
+
rescue LoadError
|
21
17
|
warn 'To user Whenever you need the activesupport gem:'
|
22
18
|
warn '$ sudo gem install activesupport'
|
23
19
|
exit(1)
|
24
20
|
end
|
25
21
|
|
26
22
|
# Whenever files
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
job_types/
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
}.each { |file| require File.expand_path(File.dirname(__FILE__) + "/#{file}") }
|
23
|
+
require 'whenever/base'
|
24
|
+
require 'whenever/job_list'
|
25
|
+
require 'whenever/job_types/default'
|
26
|
+
require 'whenever/job_types/rake_task'
|
27
|
+
require 'whenever/job_types/runner'
|
28
|
+
require 'whenever/outputs/cron'
|
29
|
+
require 'whenever/outputs/cron/output_redirection'
|
30
|
+
require 'whenever/command_line'
|
31
|
+
require 'whenever/version'
|
data/test/output_command_test.rb
CHANGED
@@ -17,73 +17,6 @@ class OutputCommandTest < Test::Unit::TestCase
|
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
|
-
context "A command when the cron_log is set" do
|
21
|
-
setup do
|
22
|
-
@output = Whenever.cron \
|
23
|
-
<<-file
|
24
|
-
set :cron_log, 'logfile.log'
|
25
|
-
every 2.hours do
|
26
|
-
command "blahblah"
|
27
|
-
end
|
28
|
-
file
|
29
|
-
end
|
30
|
-
|
31
|
-
should "output the command with the log syntax appended" do
|
32
|
-
assert_match /^.+ .+ .+ .+ blahblah >> logfile.log 2>&1$/, @output
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
context "A command when the cron_log is set and the comand overrides it" do
|
37
|
-
setup do
|
38
|
-
@output = Whenever.cron \
|
39
|
-
<<-file
|
40
|
-
set :cron_log, 'logfile.log'
|
41
|
-
every 2.hours do
|
42
|
-
command "blahblah", :cron_log => 'otherlog.log'
|
43
|
-
end
|
44
|
-
file
|
45
|
-
end
|
46
|
-
|
47
|
-
should "output the command with the log syntax appended" do
|
48
|
-
assert_no_match /.+ .+ .+ .+ blahblah >> logfile.log 2>&1/, @output
|
49
|
-
assert_match /^.+ .+ .+ .+ blahblah >> otherlog.log 2>&1$/, @output
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
context "A command when the cron_log is set and the comand rejects it" do
|
54
|
-
setup do
|
55
|
-
@output = Whenever.cron \
|
56
|
-
<<-file
|
57
|
-
set :cron_log, 'logfile.log'
|
58
|
-
every 2.hours do
|
59
|
-
command "blahblah", :cron_log => false
|
60
|
-
end
|
61
|
-
file
|
62
|
-
end
|
63
|
-
|
64
|
-
should "output the command without the log syntax appended" do
|
65
|
-
assert_no_match /.+ .+ .+ .+ blahblah >> logfile.log 2>&1/, @output
|
66
|
-
assert_match /^.+ .+ .+ .+ blahblah$/, @output
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
context "A command when the cron_log is set and is overridden by the :set option" do
|
71
|
-
setup do
|
72
|
-
@output = Whenever.cron :set => 'cron_log=otherlog.log', :string => \
|
73
|
-
<<-file
|
74
|
-
set :cron_log, 'logfile.log'
|
75
|
-
every 2.hours do
|
76
|
-
command "blahblah"
|
77
|
-
end
|
78
|
-
file
|
79
|
-
end
|
80
|
-
|
81
|
-
should "output the otherlog.log as the log file" do
|
82
|
-
assert_no_match /.+ .+ .+ .+ blahblah >> logfile.log 2>&1/, @output
|
83
|
-
assert_match /^.+ .+ .+ .+ blahblah >> otherlog.log 2>&1/, @output
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
20
|
context "An every statement with two commands in it" do
|
88
21
|
setup do
|
89
22
|
@output = Whenever.cron \
|
@@ -100,5 +33,5 @@ class OutputCommandTest < Test::Unit::TestCase
|
|
100
33
|
assert_match "0 * * * * second", @output
|
101
34
|
end
|
102
35
|
end
|
103
|
-
|
36
|
+
|
104
37
|
end
|
@@ -0,0 +1,289 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + "/test_helper")
|
2
|
+
|
3
|
+
class OutputRedirectionTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
context "A command when the output is set to nil" do
|
6
|
+
setup do
|
7
|
+
@output = Whenever.cron \
|
8
|
+
<<-file
|
9
|
+
set :output, nil
|
10
|
+
every 2.hours do
|
11
|
+
command "blahblah"
|
12
|
+
end
|
13
|
+
file
|
14
|
+
end
|
15
|
+
|
16
|
+
should "output the command with the log syntax appended" do
|
17
|
+
assert_match /^.+ .+ .+ .+ blahblah >> \/dev\/null 2>&1$/, @output
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
|
22
|
+
context "A command when the output is set" do
|
23
|
+
setup do
|
24
|
+
@output = Whenever.cron \
|
25
|
+
<<-file
|
26
|
+
set :output, 'logfile.log'
|
27
|
+
every 2.hours do
|
28
|
+
command "blahblah"
|
29
|
+
end
|
30
|
+
file
|
31
|
+
end
|
32
|
+
|
33
|
+
should "output the command with the log syntax appended" do
|
34
|
+
assert_match /^.+ .+ .+ .+ blahblah >> logfile.log 2>&1$/, @output
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
context "A command when the error and standard output is set by the command" do
|
39
|
+
setup do
|
40
|
+
@output = Whenever.cron \
|
41
|
+
<<-file
|
42
|
+
every 2.hours do
|
43
|
+
command "blahblah", :output => {:standard => 'dev_null', :error => 'dev_err'}
|
44
|
+
end
|
45
|
+
file
|
46
|
+
end
|
47
|
+
|
48
|
+
should "output the command without the log syntax appended" do
|
49
|
+
assert_match /^.+ .+ .+ .+ blahblah >> dev_null 2> dev_err$/, @output
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
context "A command when the output is set and the comand overrides it" do
|
54
|
+
setup do
|
55
|
+
@output = Whenever.cron \
|
56
|
+
<<-file
|
57
|
+
set :output, 'logfile.log'
|
58
|
+
every 2.hours do
|
59
|
+
command "blahblah", :output => 'otherlog.log'
|
60
|
+
end
|
61
|
+
file
|
62
|
+
end
|
63
|
+
|
64
|
+
should "output the command with the command syntax appended" do
|
65
|
+
assert_no_match /.+ .+ .+ .+ blahblah >> logfile.log 2>&1/, @output
|
66
|
+
assert_match /^.+ .+ .+ .+ blahblah >> otherlog.log 2>&1$/, @output
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
context "A command when the output is set and the comand overrides with standard and error" do
|
71
|
+
setup do
|
72
|
+
@output = Whenever.cron \
|
73
|
+
<<-file
|
74
|
+
set :output, 'logfile.log'
|
75
|
+
every 2.hours do
|
76
|
+
command "blahblah", :output => {:error => 'dev_err', :standard => 'dev_null' }
|
77
|
+
end
|
78
|
+
file
|
79
|
+
end
|
80
|
+
|
81
|
+
should "output the command with the overridden redirection syntax appended" do
|
82
|
+
assert_no_match /.+ .+ .+ .+ blahblah >> logfile.log 2>&1/, @output
|
83
|
+
assert_match /^.+ .+ .+ .+ blahblah >> dev_null 2> dev_err$/, @output
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
context "A command when the output is set and the comand rejects it" do
|
88
|
+
setup do
|
89
|
+
@output = Whenever.cron \
|
90
|
+
<<-file
|
91
|
+
set :output, 'logfile.log'
|
92
|
+
every 2.hours do
|
93
|
+
command "blahblah", :output => false
|
94
|
+
end
|
95
|
+
file
|
96
|
+
end
|
97
|
+
|
98
|
+
should "output the command without the log syntax appended" do
|
99
|
+
assert_no_match /.+ .+ .+ .+ blahblah >> logfile.log 2>&1/, @output
|
100
|
+
assert_match /^.+ .+ .+ .+ blahblah$/, @output
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
context "A command when the output is set and is overridden by the :set option" do
|
105
|
+
setup do
|
106
|
+
@output = Whenever.cron :set => 'output=otherlog.log', :string => \
|
107
|
+
<<-file
|
108
|
+
set :output, 'logfile.log'
|
109
|
+
every 2.hours do
|
110
|
+
command "blahblah"
|
111
|
+
end
|
112
|
+
file
|
113
|
+
end
|
114
|
+
|
115
|
+
should "output the otherlog.log as the log file" do
|
116
|
+
assert_no_match /.+ .+ .+ .+ blahblah >> logfile.log 2>&1/, @output
|
117
|
+
assert_match /^.+ .+ .+ .+ blahblah >> otherlog.log 2>&1/, @output
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
context "A command when the error and standard output is set" do
|
122
|
+
setup do
|
123
|
+
@output = Whenever.cron \
|
124
|
+
<<-file
|
125
|
+
set :output, {:error => 'dev_err', :standard => 'dev_null' }
|
126
|
+
every 2.hours do
|
127
|
+
command "blahblah"
|
128
|
+
end
|
129
|
+
file
|
130
|
+
end
|
131
|
+
|
132
|
+
should "output the command without the redirection syntax appended" do
|
133
|
+
assert_match /^.+ .+ .+ .+ blahblah >> dev_null 2> dev_err$/, @output
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
context "A command when error output is set" do
|
138
|
+
setup do
|
139
|
+
@output = Whenever.cron \
|
140
|
+
<<-file
|
141
|
+
set :output, {:error => 'dev_null'}
|
142
|
+
every 2.hours do
|
143
|
+
command "blahblah"
|
144
|
+
end
|
145
|
+
file
|
146
|
+
end
|
147
|
+
|
148
|
+
should "output the command without the standard errror syntax appended" do
|
149
|
+
assert_match /^.+ .+ .+ .+ blahblah 2> dev_null$/, @output
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
context "A command when the standard output is set" do
|
154
|
+
setup do
|
155
|
+
@output = Whenever.cron \
|
156
|
+
<<-file
|
157
|
+
set :output, {:standard => 'dev_out'}
|
158
|
+
every 2.hours do
|
159
|
+
command "blahblah"
|
160
|
+
end
|
161
|
+
file
|
162
|
+
end
|
163
|
+
|
164
|
+
should "output the command with standard output syntax appended" do
|
165
|
+
assert_match /^.+ .+ .+ .+ blahblah >> dev_out$/, @output
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
context "A command when error output is set by the command" do
|
170
|
+
setup do
|
171
|
+
@output = Whenever.cron \
|
172
|
+
<<-file
|
173
|
+
every 2.hours do
|
174
|
+
command "blahblah", :output => {:error => 'dev_err'}
|
175
|
+
end
|
176
|
+
file
|
177
|
+
end
|
178
|
+
|
179
|
+
should "output the command without the log syntax appended" do
|
180
|
+
assert_match /^.+ .+ .+ .+ blahblah 2> dev_err$/, @output
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
184
|
+
context "A command when standard output is set by the command" do
|
185
|
+
setup do
|
186
|
+
@output = Whenever.cron \
|
187
|
+
<<-file
|
188
|
+
every 2.hours do
|
189
|
+
command "blahblah", :output => {:standard => 'dev_out'}
|
190
|
+
end
|
191
|
+
file
|
192
|
+
end
|
193
|
+
|
194
|
+
should "output the command without the log syntax appended" do
|
195
|
+
assert_match /^.+ .+ .+ .+ blahblah >> dev_out$/, @output
|
196
|
+
end
|
197
|
+
end
|
198
|
+
|
199
|
+
context "A command when standard output is set to nil" do
|
200
|
+
setup do
|
201
|
+
@output = Whenever.cron \
|
202
|
+
<<-file
|
203
|
+
every 2.hours do
|
204
|
+
command "blahblah", :output => {:standard => nil}
|
205
|
+
end
|
206
|
+
file
|
207
|
+
end
|
208
|
+
|
209
|
+
should "output the command with stdout directed to /dev/null" do
|
210
|
+
assert_match /^.+ .+ .+ .+ blahblah >> \/dev\/null$/, @output
|
211
|
+
end
|
212
|
+
end
|
213
|
+
|
214
|
+
context "A command when standard error is set to nil" do
|
215
|
+
setup do
|
216
|
+
@output = Whenever.cron \
|
217
|
+
<<-file
|
218
|
+
every 2.hours do
|
219
|
+
command "blahblah", :output => {:error => nil}
|
220
|
+
end
|
221
|
+
file
|
222
|
+
end
|
223
|
+
|
224
|
+
should "output the command with stderr directed to /dev/null" do
|
225
|
+
assert_match /^.+ .+ .+ .+ blahblah 2> \/dev\/null$/, @output
|
226
|
+
end
|
227
|
+
end
|
228
|
+
|
229
|
+
context "A command when standard output and standard error is set to nil" do
|
230
|
+
setup do
|
231
|
+
@output = Whenever.cron \
|
232
|
+
<<-file
|
233
|
+
every 2.hours do
|
234
|
+
command "blahblah", :output => {:error => nil, :standard => nil}
|
235
|
+
end
|
236
|
+
file
|
237
|
+
end
|
238
|
+
|
239
|
+
should "output the command with stderr directed to /dev/null" do
|
240
|
+
assert_match /^.+ .+ .+ .+ blahblah >> \/dev\/null 2>&1$/, @output
|
241
|
+
end
|
242
|
+
end
|
243
|
+
|
244
|
+
context "A command when standard output is set and standard error is set to nil" do
|
245
|
+
setup do
|
246
|
+
@output = Whenever.cron \
|
247
|
+
<<-file
|
248
|
+
every 2.hours do
|
249
|
+
command "blahblah", :output => {:error => nil, :standard => 'my.log'}
|
250
|
+
end
|
251
|
+
file
|
252
|
+
end
|
253
|
+
|
254
|
+
should "output the command with stderr directed to /dev/null" do
|
255
|
+
assert_match /^.+ .+ .+ .+ blahblah >> my.log 2> \/dev\/null$/, @output
|
256
|
+
end
|
257
|
+
end
|
258
|
+
|
259
|
+
context "A command when standard output is nil and standard error is set" do
|
260
|
+
setup do
|
261
|
+
@output = Whenever.cron \
|
262
|
+
<<-file
|
263
|
+
every 2.hours do
|
264
|
+
command "blahblah", :output => {:error => 'my_error.log', :standard => nil}
|
265
|
+
end
|
266
|
+
file
|
267
|
+
end
|
268
|
+
|
269
|
+
should "output the command with stderr directed to /dev/null" do
|
270
|
+
assert_match /^.+ .+ .+ .+ blahblah >> \/dev\/null 2> my_error.log$/, @output
|
271
|
+
end
|
272
|
+
end
|
273
|
+
|
274
|
+
context "A command when the deprecated :cron_log is set" do
|
275
|
+
setup do
|
276
|
+
@output = Whenever.cron \
|
277
|
+
<<-file
|
278
|
+
set :cron_log, "cron.log"
|
279
|
+
every 2.hours do
|
280
|
+
command "blahblah"
|
281
|
+
end
|
282
|
+
file
|
283
|
+
end
|
284
|
+
|
285
|
+
should "output the command with with the stdout and stderr going to the log" do
|
286
|
+
assert_match /^.+ .+ .+ .+ blahblah >> cron.log 2>&1$/, @output
|
287
|
+
end
|
288
|
+
end
|
289
|
+
end
|
data/whenever.gemspec
CHANGED
@@ -1,24 +1,65 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
1
4
|
# -*- encoding: utf-8 -*-
|
2
5
|
|
3
6
|
Gem::Specification.new do |s|
|
4
7
|
s.name = %q{whenever}
|
5
|
-
s.version = "0.
|
8
|
+
s.version = "0.4.0"
|
6
9
|
|
7
|
-
s.required_rubygems_version = Gem::Requirement.new(">=
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
11
|
s.authors = ["Javan Makhmali"]
|
9
|
-
s.date = %q{2009-10-
|
10
|
-
s.description = %q{
|
12
|
+
s.date = %q{2009-10-20}
|
13
|
+
s.description = %q{Clean ruby syntax for defining and deploying messy cron jobs.}
|
11
14
|
s.email = %q{javan@javan.us}
|
12
15
|
s.executables = ["whenever", "wheneverize"]
|
13
|
-
s.extra_rdoc_files = [
|
14
|
-
|
16
|
+
s.extra_rdoc_files = [
|
17
|
+
"README.rdoc"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".gitignore",
|
21
|
+
"CHANGELOG.rdoc",
|
22
|
+
"README.rdoc",
|
23
|
+
"Rakefile",
|
24
|
+
"bin/whenever",
|
25
|
+
"bin/wheneverize",
|
26
|
+
"lib/whenever.rb",
|
27
|
+
"lib/whenever/base.rb",
|
28
|
+
"lib/whenever/command_line.rb",
|
29
|
+
"lib/whenever/job_list.rb",
|
30
|
+
"lib/whenever/job_types/default.rb",
|
31
|
+
"lib/whenever/job_types/rake_task.rb",
|
32
|
+
"lib/whenever/job_types/runner.rb",
|
33
|
+
"lib/whenever/outputs/cron.rb",
|
34
|
+
"lib/whenever/outputs/cron/output_redirection.rb",
|
35
|
+
"lib/whenever/version.rb",
|
36
|
+
"test/command_line_test.rb",
|
37
|
+
"test/cron_test.rb",
|
38
|
+
"test/output_at_test.rb",
|
39
|
+
"test/output_command_test.rb",
|
40
|
+
"test/output_env_test.rb",
|
41
|
+
"test/output_rake_test.rb",
|
42
|
+
"test/output_redirection_test.rb",
|
43
|
+
"test/output_runner_test.rb",
|
44
|
+
"test/test_helper.rb",
|
45
|
+
"whenever.gemspec"
|
46
|
+
]
|
15
47
|
s.homepage = %q{http://github.com/javan/whenever}
|
16
|
-
s.rdoc_options = ["--
|
48
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
17
49
|
s.require_paths = ["lib"]
|
18
|
-
s.rubyforge_project = %q{whenever}
|
19
50
|
s.rubygems_version = %q{1.3.5}
|
20
|
-
s.summary = %q{
|
21
|
-
s.test_files = [
|
51
|
+
s.summary = %q{Clean ruby syntax for defining and deploying messy cron jobs.}
|
52
|
+
s.test_files = [
|
53
|
+
"test/command_line_test.rb",
|
54
|
+
"test/cron_test.rb",
|
55
|
+
"test/output_at_test.rb",
|
56
|
+
"test/output_command_test.rb",
|
57
|
+
"test/output_env_test.rb",
|
58
|
+
"test/output_rake_test.rb",
|
59
|
+
"test/output_redirection_test.rb",
|
60
|
+
"test/output_runner_test.rb",
|
61
|
+
"test/test_helper.rb"
|
62
|
+
]
|
22
63
|
|
23
64
|
if s.respond_to? :specification_version then
|
24
65
|
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
@@ -33,3 +74,4 @@ Gem::Specification.new do |s|
|
|
33
74
|
s.add_dependency(%q<chronic>, [">= 0.2.3"])
|
34
75
|
end
|
35
76
|
end
|
77
|
+
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: whenever
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Javan Makhmali
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-10-
|
12
|
+
date: 2009-10-20 00:00:00 -04:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -22,7 +22,7 @@ dependencies:
|
|
22
22
|
- !ruby/object:Gem::Version
|
23
23
|
version: 0.2.3
|
24
24
|
version:
|
25
|
-
description:
|
25
|
+
description: Clean ruby syntax for defining and deploying messy cron jobs.
|
26
26
|
email: javan@javan.us
|
27
27
|
executables:
|
28
28
|
- whenever
|
@@ -30,41 +30,31 @@ executables:
|
|
30
30
|
extensions: []
|
31
31
|
|
32
32
|
extra_rdoc_files:
|
33
|
-
- bin/whenever
|
34
|
-
- bin/wheneverize
|
35
|
-
- CHANGELOG.rdoc
|
36
|
-
- lib/base.rb
|
37
|
-
- lib/command_line.rb
|
38
|
-
- lib/job_list.rb
|
39
|
-
- lib/job_types/default.rb
|
40
|
-
- lib/job_types/rake_task.rb
|
41
|
-
- lib/job_types/runner.rb
|
42
|
-
- lib/outputs/cron.rb
|
43
|
-
- lib/version.rb
|
44
|
-
- lib/whenever.rb
|
45
33
|
- README.rdoc
|
46
34
|
files:
|
35
|
+
- .gitignore
|
36
|
+
- CHANGELOG.rdoc
|
37
|
+
- README.rdoc
|
38
|
+
- Rakefile
|
47
39
|
- bin/whenever
|
48
40
|
- bin/wheneverize
|
49
|
-
- CHANGELOG.rdoc
|
50
|
-
- lib/base.rb
|
51
|
-
- lib/command_line.rb
|
52
|
-
- lib/job_list.rb
|
53
|
-
- lib/job_types/default.rb
|
54
|
-
- lib/job_types/rake_task.rb
|
55
|
-
- lib/job_types/runner.rb
|
56
|
-
- lib/outputs/cron.rb
|
57
|
-
- lib/version.rb
|
58
41
|
- lib/whenever.rb
|
59
|
-
-
|
60
|
-
-
|
61
|
-
-
|
42
|
+
- lib/whenever/base.rb
|
43
|
+
- lib/whenever/command_line.rb
|
44
|
+
- lib/whenever/job_list.rb
|
45
|
+
- lib/whenever/job_types/default.rb
|
46
|
+
- lib/whenever/job_types/rake_task.rb
|
47
|
+
- lib/whenever/job_types/runner.rb
|
48
|
+
- lib/whenever/outputs/cron.rb
|
49
|
+
- lib/whenever/outputs/cron/output_redirection.rb
|
50
|
+
- lib/whenever/version.rb
|
62
51
|
- test/command_line_test.rb
|
63
52
|
- test/cron_test.rb
|
64
53
|
- test/output_at_test.rb
|
65
54
|
- test/output_command_test.rb
|
66
55
|
- test/output_env_test.rb
|
67
56
|
- test/output_rake_test.rb
|
57
|
+
- test/output_redirection_test.rb
|
68
58
|
- test/output_runner_test.rb
|
69
59
|
- test/test_helper.rb
|
70
60
|
- whenever.gemspec
|
@@ -74,12 +64,7 @@ licenses: []
|
|
74
64
|
|
75
65
|
post_install_message:
|
76
66
|
rdoc_options:
|
77
|
-
- --
|
78
|
-
- --inline-source
|
79
|
-
- --title
|
80
|
-
- Whenever
|
81
|
-
- --main
|
82
|
-
- README.rdoc
|
67
|
+
- --charset=UTF-8
|
83
68
|
require_paths:
|
84
69
|
- lib
|
85
70
|
required_ruby_version: !ruby/object:Gem::Requirement
|
@@ -92,15 +77,15 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
92
77
|
requirements:
|
93
78
|
- - ">="
|
94
79
|
- !ruby/object:Gem::Version
|
95
|
-
version: "
|
80
|
+
version: "0"
|
96
81
|
version:
|
97
82
|
requirements: []
|
98
83
|
|
99
|
-
rubyforge_project:
|
84
|
+
rubyforge_project:
|
100
85
|
rubygems_version: 1.3.5
|
101
86
|
signing_key:
|
102
87
|
specification_version: 3
|
103
|
-
summary:
|
88
|
+
summary: Clean ruby syntax for defining and deploying messy cron jobs.
|
104
89
|
test_files:
|
105
90
|
- test/command_line_test.rb
|
106
91
|
- test/cron_test.rb
|
@@ -108,5 +93,6 @@ test_files:
|
|
108
93
|
- test/output_command_test.rb
|
109
94
|
- test/output_env_test.rb
|
110
95
|
- test/output_rake_test.rb
|
96
|
+
- test/output_redirection_test.rb
|
111
97
|
- test/output_runner_test.rb
|
112
98
|
- test/test_helper.rb
|
data/Manifest
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
bin/whenever
|
2
|
-
bin/wheneverize
|
3
|
-
CHANGELOG.rdoc
|
4
|
-
lib/base.rb
|
5
|
-
lib/command_line.rb
|
6
|
-
lib/job_list.rb
|
7
|
-
lib/job_types/default.rb
|
8
|
-
lib/job_types/rake_task.rb
|
9
|
-
lib/job_types/runner.rb
|
10
|
-
lib/outputs/cron.rb
|
11
|
-
lib/version.rb
|
12
|
-
lib/whenever.rb
|
13
|
-
Manifest
|
14
|
-
Rakefile
|
15
|
-
README.rdoc
|
16
|
-
test/command_line_test.rb
|
17
|
-
test/cron_test.rb
|
18
|
-
test/output_at_test.rb
|
19
|
-
test/output_command_test.rb
|
20
|
-
test/output_env_test.rb
|
21
|
-
test/output_rake_test.rb
|
22
|
-
test/output_runner_test.rb
|
23
|
-
test/test_helper.rb
|
24
|
-
whenever.gemspec
|
data/lib/job_types/default.rb
DELETED
@@ -1,27 +0,0 @@
|
|
1
|
-
module Whenever
|
2
|
-
module Job
|
3
|
-
class Default
|
4
|
-
|
5
|
-
attr_accessor :task, :at, :cron_log
|
6
|
-
|
7
|
-
def initialize(options = {})
|
8
|
-
@task = options[:task]
|
9
|
-
@at = options[:at]
|
10
|
-
@cron_log = options[:cron_log]
|
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
|