moneypools-whenever 0.2.1 → 0.3.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/VERSION +1 -1
- data/lib/whenever/job_sequence.rb +6 -1
- data/moneypools-whenever.gemspec +1 -1
- data/test/in_sequence_test.rb +18 -0
- data/test/job_sequence_test.rb +16 -0
- metadata +1 -1
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
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
|
data/moneypools-whenever.gemspec
CHANGED
data/test/in_sequence_test.rb
CHANGED
@@ -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 \
|
data/test/job_sequence_test.rb
CHANGED
@@ -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
|