moneypools-whenever 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.1
1
+ 0.3.0
@@ -1,18 +1,23 @@
1
1
  module Whenever
2
2
  class JobSequence < Array
3
- attr_writer :dependent
3
+ attr_writer :dependent, :on_failure
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]
10
11
  end
11
12
 
12
13
  def to_single_job
13
14
  concatenation = @dependent ? " && " : "; "
14
15
  task = map(&:output).join(concatenation)
15
16
 
17
+ if @dependent && @on_failure && @on_failure != ''
18
+ task = "(#{task}) || #{@on_failure}"
19
+ end
20
+
16
21
  Job::Default.new(@options.merge(:task => task))
17
22
  end
18
23
  end
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{moneypools-whenever}
8
- s.version = "0.2.1"
8
+ s.version = "0.3.0"
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"]
@@ -38,6 +38,24 @@ class InSequenceTest < Test::Unit::TestCase
38
38
  end
39
39
  end
40
40
 
41
+ context "A pair of dependent sequential tasks with a failure command" do
42
+ setup do
43
+ @output = Whenever.cron \
44
+ <<-file
45
+ set :path, '/my/path'
46
+ every 1.day, :on_failure => "my_failure_command" do
47
+ in_sequence do
48
+ rake "only_task"
49
+ end
50
+ end
51
+ file
52
+ end
53
+
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
56
+ end
57
+ end
58
+
41
59
  context "A pair of tasks in the same time block that should be executed in a independent sequence" do
42
60
  setup do
43
61
  @output = Whenever.cron \
@@ -20,6 +20,14 @@ 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
23
31
  end
24
32
 
25
33
  context "with independent sequences" do
@@ -30,6 +38,14 @@ class JobSequenceTest < Test::Unit::TestCase
30
38
 
31
39
  assert_equal sequence.to_single_job.output, "first_task; second_task"
32
40
  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
33
49
  end
34
50
  end
35
51
  end
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.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Javan Makhmali