moneypools-whenever 0.4.0 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.rdoc CHANGED
@@ -1,3 +1,10 @@
1
+ == 0.4.1 / November 30th, 2009
2
+
3
+ * exit(0) instead of just exit to make JRuby happy. [Elan Meng]
4
+
5
+ * Fixed activesupport deprecation warning by requiring active_support. #37 [Andrew Nesbitt]
6
+
7
+
1
8
  == 0.4.0 / October 20th, 2009
2
9
 
3
10
  * New output option replaces the old cron_log option for output redirection and is much more flexible. #31 [Peer Allan]
data/Rakefile CHANGED
@@ -29,4 +29,4 @@ end
29
29
 
30
30
  task :test => :check_dependencies
31
31
 
32
- task :default => :test
32
+ task :default => :test
data/bin/whenever CHANGED
@@ -10,7 +10,7 @@ options = Hash.new
10
10
 
11
11
  OptionParser.new do |opts|
12
12
  opts.banner = "Usage: whenever [options]"
13
- opts.on('-v', '--version') { puts "Whenever v#{Whenever::VERSION}"; exit }
13
+ opts.on('-v', '--version') { puts "Whenever v#{Whenever::VERSION}"; exit(0) }
14
14
  opts.on('-w', '--write-crontab') { options[:write] = true }
15
15
  opts.on('-i', '--update-crontab [identifier]', 'Default: full path to schedule.rb file') do |identifier|
16
16
  options[:update] = true
@@ -29,7 +29,7 @@ module Whenever
29
29
  write_crontab(whenever_cron)
30
30
  else
31
31
  puts Whenever.cron(@options)
32
- exit
32
+ exit(0)
33
33
  end
34
34
  end
35
35
 
@@ -67,7 +67,7 @@ module Whenever
67
67
  action = 'written' if @options[:write]
68
68
  action = 'updated' if @options[:update]
69
69
  puts "[write] crontab file #{action}"
70
- exit
70
+ exit(0)
71
71
  else
72
72
  warn "[fail] Couldn't write crontab; try running `whenever' with no options to ensure your schedule file is valid."
73
73
  exit(1)
@@ -1,24 +1,30 @@
1
1
  module Whenever
2
2
  class JobSequence < Array
3
- attr_writer :dependent, :on_failure
3
+ attr_writer :dependent
4
4
 
5
5
  def initialize(options={}, size=0, obj=nil)
6
6
  super(size, obj)
7
7
 
8
8
  @options = options
9
9
  @dependent = options.fetch(:dependent, true)
10
- @on_failure = options[:on_failure]
11
10
  end
12
11
 
13
12
  def to_single_job
13
+ options = @options.dup
14
+ default_redirection = options.delete(:output)
15
+
14
16
  concatenation = @dependent ? " && " : "; "
15
- task = map(&:output).join(concatenation)
16
-
17
- if @dependent && @on_failure && @on_failure != ''
18
- task = "(#{task}) || #{@on_failure}"
17
+ tasks_with_redirection = map do |t|
18
+ if redirection = t.output_redirection.nil? || t.output_redirection == :not_set ? default_redirection : t.output_redirection
19
+ t.output + " " + Output::Cron::OutputRedirection.new(redirection).to_s
20
+ else
21
+ t.output
22
+ end
19
23
  end
24
+
25
+ single_task = tasks_with_redirection.join(concatenation)
20
26
 
21
- Job::Default.new(@options.merge(:task => task))
27
+ Job::Default.new(options.merge(:task => single_task))
22
28
  end
23
29
  end
24
- end
30
+ end
@@ -1,3 +1,3 @@
1
1
  module Whenever
2
- VERSION = '0.4.0'
2
+ VERSION = '0.4.1'
3
3
  end unless defined?(Whenever::VERSION)
data/lib/whenever.rb CHANGED
@@ -7,15 +7,15 @@ rescue LoadError
7
7
  nil
8
8
  end
9
9
 
10
- # If Rails' rakefile was loaded than so was activesupport, but
10
+ # If Rails' rakefile was loaded than so was active_support, but
11
11
  # if this is being used in a non-rails enviroment we need to require it.
12
12
  # It was previously defined as a dependency of this gem, but that became
13
13
  # problematic. See: http://github.com/javan/whenever/issues#issue/1
14
14
  begin
15
- require 'activesupport'
15
+ require 'active_support'
16
16
  rescue LoadError
17
- warn 'To user Whenever you need the activesupport gem:'
18
- warn '$ sudo gem install activesupport'
17
+ warn 'To user Whenever you need the active_support gem:'
18
+ warn '$ sudo gem install active_support'
19
19
  exit(1)
20
20
  end
21
21
 
@@ -19,40 +19,63 @@ class InSequenceTest < Test::Unit::TestCase
19
19
  end
20
20
  end
21
21
 
22
- context "A pair of tasks in the same time block that should be executed in a dependent sequence" do
22
+ context "A pair of tasks in a sequence with output redirection" do
23
23
  setup do
24
24
  @output = Whenever.cron \
25
25
  <<-file
26
26
  set :path, '/my/path'
27
- every 2.hours do
27
+ every 1.day, :at => "20:15" do
28
28
  in_sequence do
29
- cap "first_task"
30
- rake "second_task"
29
+ rake "first_task", :output => 'logfile1'
30
+ rake "second_task", :output => 'logfile2'
31
31
  end
32
32
  end
33
33
  file
34
34
  end
35
35
 
36
- should "output the pair of tasks using &&" do
37
- assert_match 'cd /my/path && RAILS_ENV=production /usr/bin/env cap first_task && cd /my/path && RAILS_ENV=production /usr/bin/env rake second_task', @output
36
+ should "produce a set of tasks using individual output options" do
37
+ assert_match 'rake first_task >> logfile1', @output
38
+ assert_match 'rake second_task >> logfile2', @output
39
+ end
40
+ end
41
+
42
+ context "A pair of tasks in a sequence with two levels of output redirection" do
43
+ setup do
44
+ @output = Whenever.cron \
45
+ <<-file
46
+ set :path, '/my/path'
47
+ every 1.day, :at => "20:15" do
48
+ in_sequence :output => 'fallthrough' do
49
+ rake "first_task"
50
+ rake "second_task", :output => 'logfile2'
51
+ end
52
+ end
53
+ file
54
+ end
55
+
56
+ should "use the sequence level redirection as a default" do
57
+ assert_match 'rake first_task >> fallthrough', @output
58
+ assert_match 'rake second_task >> logfile2', @output
38
59
  end
39
60
  end
61
+
40
62
 
41
- context "A pair of dependent sequential tasks with a failure command" do
63
+ context "A pair of tasks in the same time block that should be executed in a dependent sequence" do
42
64
  setup do
43
65
  @output = Whenever.cron \
44
66
  <<-file
45
67
  set :path, '/my/path'
46
- every 1.day, :on_failure => "my_failure_command" do
68
+ every 2.hours do
47
69
  in_sequence do
48
- rake "only_task"
70
+ cap "first_task"
71
+ rake "second_task"
49
72
  end
50
73
  end
51
74
  file
52
75
  end
53
76
 
54
- should "produce pair of tasks using && with a command that runs if they fail" do
55
- assert_match '(cd /my/path && RAILS_ENV=production /usr/bin/env rake only_task) || my_failure_command', @output
77
+ should "output the pair of tasks using &&" do
78
+ assert_match 'cd /my/path && RAILS_ENV=production /usr/bin/env cap first_task && cd /my/path && RAILS_ENV=production /usr/bin/env rake second_task', @output
56
79
  end
57
80
  end
58
81
 
@@ -20,14 +20,6 @@ class JobSequenceTest < Test::Unit::TestCase
20
20
 
21
21
  assert_equal sequence.to_single_job.output, "first_task && second_task"
22
22
  end
23
-
24
- should "wrap sequence and fire failure command conditionally" do
25
- sequence = Whenever::JobSequence.new(:on_failure => "failure_command")
26
- sequence << Whenever::Job::Default.new(:task => "first_task", :path => @path)
27
- sequence << Whenever::Job::Default.new(:task => "second_task", :path => @path)
28
-
29
- assert_equal sequence.to_single_job.output, "(first_task && second_task) || failure_command"
30
- end
31
23
  end
32
24
 
33
25
  context "with independent sequences" do
@@ -38,14 +30,6 @@ class JobSequenceTest < Test::Unit::TestCase
38
30
 
39
31
  assert_equal sequence.to_single_job.output, "first_task; second_task"
40
32
  end
41
-
42
- should "not wrap sequence since it is not meaningful" do
43
- sequence = Whenever::JobSequence.new(:dependent => false, :on_failure => "failure_command")
44
- sequence << Whenever::Job::Default.new(:task => "first_task", :path => @path)
45
- sequence << Whenever::Job::Default.new(:task => "second_task", :path => @path)
46
-
47
- assert_equal sequence.to_single_job.output, "first_task; second_task"
48
- end
49
33
  end
50
34
  end
51
35
  end
@@ -113,14 +113,12 @@ class OutputAtTest < Test::Unit::TestCase
113
113
 
114
114
  context "A command every 1.month at very diverse times" do
115
115
  setup do
116
- Timecop.freeze(Date.new(2009, 1, 1)) do
117
- @output = Whenever.cron \
118
- <<-file
119
- every [1.month, 1.day], :at => 'beginning of the month at 5:02am, june 17th at 2:22pm, june 3rd at 3:33am' do
120
- command "blahblah"
121
- end
122
- file
123
- end
116
+ @output = Whenever.cron \
117
+ <<-file
118
+ every [1.month, 1.day], :at => 'january 5:02am, june 17th at 2:22pm, june 3rd at 3:33am' do
119
+ command "blahblah"
120
+ end
121
+ file
124
122
  end
125
123
 
126
124
  should "output 6 commands since none align" do
data/test/test_helper.rb CHANGED
@@ -3,26 +3,29 @@ require 'test/unit'
3
3
 
4
4
  require File.expand_path(File.dirname(__FILE__) + "/../lib/whenever")
5
5
 
6
- requirements = {
7
- 'shoulda' => 'thoughtbot-shoulda',
8
- 'mocha' => 'mocha',
9
- 'timecop' => 'timecop'
10
- }
6
+ begin
7
+ require 'shoulda'
8
+ rescue LoadError
9
+ warn 'To test Whenever you need the shoulda gem:'
10
+ warn '$ sudo gem install thoughtbot-shoulda'
11
+ exit(1)
12
+ end
11
13
 
12
- requirements.each_pair do |gem_name, gem_source|
13
- begin
14
- require gem_name
15
- rescue LoadError
16
- warn "To test Whenever you need the #{gem_name} gem:"
17
- warn "$ sudo gem install #{gem_source}"
18
- exit(1)
19
- end
14
+ begin
15
+ require 'mocha'
16
+ rescue LoadError
17
+ warn 'To test Whenever you need the mocha gem:'
18
+ warn '$ sudo gem install mocha'
19
+ exit(1)
20
20
  end
21
21
 
22
+
22
23
  module TestExtensions
24
+
23
25
  def two_hours
24
26
  "0 0,2,4,6,8,10,12,14,16,18,20,22 * * *"
25
27
  end
28
+
26
29
  end
27
30
 
28
31
  class Test::Unit::TestCase
data/whenever.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{whenever}
8
- s.version = "0.4.0"
8
+ s.version = "0.4.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Javan Makhmali"]
12
- s.date = %q{2009-10-20}
12
+ s.date = %q{2009-12-02}
13
13
  s.description = %q{Clean ruby syntax for defining and deploying messy cron jobs.}
14
14
  s.email = %q{javan@javan.us}
15
15
  s.executables = ["whenever", "wheneverize"]
@@ -27,6 +27,8 @@ Gem::Specification.new do |s|
27
27
  "lib/whenever/base.rb",
28
28
  "lib/whenever/command_line.rb",
29
29
  "lib/whenever/job_list.rb",
30
+ "lib/whenever/job_sequence.rb",
31
+ "lib/whenever/job_types/cap_task.rb",
30
32
  "lib/whenever/job_types/default.rb",
31
33
  "lib/whenever/job_types/rake_task.rb",
32
34
  "lib/whenever/job_types/runner.rb",
@@ -35,7 +37,10 @@ Gem::Specification.new do |s|
35
37
  "lib/whenever/version.rb",
36
38
  "test/command_line_test.rb",
37
39
  "test/cron_test.rb",
40
+ "test/in_sequence_test.rb",
41
+ "test/job_sequence_test.rb",
38
42
  "test/output_at_test.rb",
43
+ "test/output_cap_test.rb",
39
44
  "test/output_command_test.rb",
40
45
  "test/output_env_test.rb",
41
46
  "test/output_rake_test.rb",
@@ -52,7 +57,10 @@ Gem::Specification.new do |s|
52
57
  s.test_files = [
53
58
  "test/command_line_test.rb",
54
59
  "test/cron_test.rb",
60
+ "test/in_sequence_test.rb",
61
+ "test/job_sequence_test.rb",
55
62
  "test/output_at_test.rb",
63
+ "test/output_cap_test.rb",
56
64
  "test/output_command_test.rb",
57
65
  "test/output_env_test.rb",
58
66
  "test/output_rake_test.rb",
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: moneypools-whenever
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.1
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-11-30 00:00:00 -06:00
12
+ date: 2009-12-02 00:00:00 -06:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency