chrono_trigger 0.1.7 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +167 -0
- data/LICENSE.txt +21 -0
- data/README.md +89 -0
- data/Rakefile +4 -50
- data/SUMMARY.md +5 -0
- data/bin/console +7 -0
- data/bin/loc +3 -0
- data/bin/setup +8 -0
- data/bin/standardize +4 -0
- data/lib/chrono_trigger.rb +27 -8
- data/lib/chrono_trigger/clock.rb +50 -0
- data/lib/chrono_trigger/config.rb +12 -0
- data/lib/chrono_trigger/event.rb +121 -0
- data/lib/chrono_trigger/schedule.rb +71 -0
- data/lib/chrono_trigger/timeline.rb +28 -0
- data/lib/chrono_trigger/version.rb +5 -0
- data/lib/chrono_trigger/worker.rb +10 -0
- metadata +168 -54
- data/History.txt +0 -13
- data/Manifest.txt +0 -24
- data/PostInstall.txt +0 -1
- data/README.rdoc +0 -59
- data/VERSION.yml +0 -4
- data/bin/chrono_trigger +0 -7
- data/chrono_trigger.gemspec +0 -69
- data/lib/chrono_trigger/cron_entry.rb +0 -71
- data/lib/chrono_trigger/process.rb +0 -37
- data/lib/chrono_trigger/runner.rb +0 -292
- data/lib/chrono_trigger/shell.rb +0 -36
- data/lib/chrono_trigger/tasks.rb +0 -3
- data/lib/chrono_trigger/trigger.rb +0 -127
- data/lib/tasks/chrono_trigger.rake +0 -14
- data/lib/triggers/test_triggers.rb +0 -31
- data/script/console +0 -10
- data/script/destroy +0 -14
- data/script/generate +0 -14
- data/test/test_chrono_trigger.rb +0 -11
- data/test/test_cron_entry.rb +0 -198
- data/test/test_helper.rb +0 -13
- data/test/test_shell.rb +0 -52
- data/test/test_trigger.rb +0 -172
- data/test/triggers.rb +0 -17
data/test/test_helper.rb
DELETED
data/test/test_shell.rb
DELETED
@@ -1,52 +0,0 @@
|
|
1
|
-
class TestShell < Test::Unit::TestCase
|
2
|
-
|
3
|
-
context "A shell instance, @shell" do
|
4
|
-
setup do
|
5
|
-
@shell = ChronoTrigger::Shell.new
|
6
|
-
end
|
7
|
-
|
8
|
-
should "return an empty array on call to triggers" do
|
9
|
-
assert_equal [], @shell.triggers
|
10
|
-
end
|
11
|
-
|
12
|
-
should "raise an exception unless a block is provided to #trigger" do
|
13
|
-
assert_raise(ChronoTrigger::ConfigurationException) { @shell.trigger("test trigger") }
|
14
|
-
end
|
15
|
-
|
16
|
-
context "when provided a valid block" do
|
17
|
-
setup do
|
18
|
-
@trigger = @shell.trigger("name") { runs { "x" } }
|
19
|
-
end
|
20
|
-
|
21
|
-
should "create a new trigger" do
|
22
|
-
assert_equal 1, @shell.triggers.size
|
23
|
-
end
|
24
|
-
|
25
|
-
should "create a trigger that will run x with execute" do
|
26
|
-
assert_equal "x", @shell.triggers.first.execute
|
27
|
-
end
|
28
|
-
|
29
|
-
context "and configured to run the next time shell.execute_triggers is called" do
|
30
|
-
setup do
|
31
|
-
ChronoTrigger::CronEntry.any_instance.stubs(:matches?).returns(true)
|
32
|
-
end
|
33
|
-
|
34
|
-
should "execute the code block" do
|
35
|
-
@trigger.expects(:execute)
|
36
|
-
@shell.execute_triggers
|
37
|
-
end
|
38
|
-
end #and configured to run the next time shell.execute_triggers is called
|
39
|
-
end #when provided a valid block
|
40
|
-
|
41
|
-
context "calling load_context with a valid trigger file" do
|
42
|
-
setup do
|
43
|
-
@shell.load_triggers(["test/triggers.rb"])
|
44
|
-
end
|
45
|
-
|
46
|
-
should "create 3 triggers" do
|
47
|
-
assert_equal 3, @shell.triggers.size
|
48
|
-
end
|
49
|
-
end #calling load_context with a valid trigger file
|
50
|
-
end #A shell instance, @shell
|
51
|
-
|
52
|
-
end
|
data/test/test_trigger.rb
DELETED
@@ -1,172 +0,0 @@
|
|
1
|
-
class TestTrigger < Test::Unit::TestCase
|
2
|
-
|
3
|
-
context "A Trigger, @trigger," do
|
4
|
-
setup do
|
5
|
-
@trigger = ChronoTrigger::Trigger.new("test trigger")
|
6
|
-
end
|
7
|
-
|
8
|
-
context "and a block of code to run" do
|
9
|
-
setup do
|
10
|
-
@block_to_run = "hello"
|
11
|
-
@trigger.runs { @block_to_run }
|
12
|
-
end
|
13
|
-
|
14
|
-
should "assign @exec_block on call to runs" do
|
15
|
-
assert_equal @block_to_run, @trigger.instance_variable_get(:@exec_block).call
|
16
|
-
end
|
17
|
-
|
18
|
-
should "execute @block_to_run on call to execute" do
|
19
|
-
assert_equal @block_to_run, @trigger.execute
|
20
|
-
end
|
21
|
-
|
22
|
-
context "that raises an exception" do
|
23
|
-
setup do
|
24
|
-
@trigger.runs { raise Exception.new("test error")}
|
25
|
-
end
|
26
|
-
|
27
|
-
should "be caught and logged by the trigger" do
|
28
|
-
assert_nothing_raised do
|
29
|
-
quietly { @trigger.execute }
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end #that raises an exception
|
33
|
-
end #and a block of code to run
|
34
|
-
|
35
|
-
context "and a call to #on with some days" do
|
36
|
-
setup do
|
37
|
-
@days = [:monday, :wednesday]
|
38
|
-
@expected_days = [1, 3]
|
39
|
-
@trigger.on(@days)
|
40
|
-
end
|
41
|
-
|
42
|
-
should "set the triggers cron entry days" do
|
43
|
-
assert_equal @expected_days, @trigger.instance_variable_get(:@cron_entry).instance_variable_get(:@days)
|
44
|
-
end
|
45
|
-
end #and a call to on with some days
|
46
|
-
|
47
|
-
context "and a call to #at with :hours and :minutes" do
|
48
|
-
setup do
|
49
|
-
@hours = 10
|
50
|
-
@minutes = 5
|
51
|
-
@trigger.at :hour=>@hours, :minute=>@minutes
|
52
|
-
end
|
53
|
-
|
54
|
-
should "set the trigger's cron entry's hours" do
|
55
|
-
assert_equal [@hours], @trigger.instance_variable_get(:@cron_entry).instance_variable_get(:@hours)
|
56
|
-
end
|
57
|
-
|
58
|
-
should "set the trigger's cron entry's minutes" do
|
59
|
-
assert_equal [@minutes], @trigger.instance_variable_get(:@cron_entry).instance_variable_get(:@minutes)
|
60
|
-
end
|
61
|
-
|
62
|
-
context "that are nil" do
|
63
|
-
setup do
|
64
|
-
@hours, @minutes = nil, nil
|
65
|
-
end
|
66
|
-
|
67
|
-
should "raise an exception" do
|
68
|
-
assert_raise ChronoTrigger::ConfigurationException do
|
69
|
-
@trigger.at :hours=>@hours, :minutes=>@minutes
|
70
|
-
end
|
71
|
-
end
|
72
|
-
end #that are nil
|
73
|
-
|
74
|
-
context "and a call to #monthly_on" do
|
75
|
-
setup do
|
76
|
-
@calendar_days = 15
|
77
|
-
@trigger.monthly_on @calendar_days
|
78
|
-
end
|
79
|
-
|
80
|
-
should "set the trigger's cron entry's calendar_days" do
|
81
|
-
assert_equal [@calendar_days], @trigger.instance_variable_get(:@cron_entry).instance_variable_get(:@calendar_days)
|
82
|
-
end
|
83
|
-
|
84
|
-
context "with mulitple #monthly_on values" do
|
85
|
-
setup do
|
86
|
-
@calendar_days_array = [@calendar_days, 16]
|
87
|
-
@trigger.monthly_on(@calendar_days_array)
|
88
|
-
end
|
89
|
-
|
90
|
-
should "set the trigger's cron entry's calendar_days" do
|
91
|
-
assert_equal @calendar_days_array, @trigger.instance_variable_get(:@cron_entry).instance_variable_get(:@calendar_days)
|
92
|
-
end
|
93
|
-
end
|
94
|
-
end
|
95
|
-
end #and a call to #at with :hours and :minutes
|
96
|
-
|
97
|
-
context "on a call to #every" do
|
98
|
-
context "for 10 minutes" do
|
99
|
-
setup do
|
100
|
-
@minutes = 10
|
101
|
-
end
|
102
|
-
|
103
|
-
context "when called" do
|
104
|
-
setup do
|
105
|
-
@trigger.every :minutes=>@minutes
|
106
|
-
end
|
107
|
-
|
108
|
-
should "set the trigger's cron entry's minutes to [0, 10,20,30,40,50]" do
|
109
|
-
assert_equal [0,10,20,30,40,50], @trigger.instance_variable_get(:@cron_entry).instance_variable_get(:@minutes)
|
110
|
-
end
|
111
|
-
|
112
|
-
context "in addition to setting #at to hour 2" do
|
113
|
-
setup do
|
114
|
-
@hour = 2
|
115
|
-
@trigger.at :hour=>@hour
|
116
|
-
end
|
117
|
-
|
118
|
-
should "set the trigger's cron entry's minutes to [0, 10,20,30,40,50]" do
|
119
|
-
assert_equal [0,10,20,30,40,50], @trigger.instance_variable_get(:@cron_entry).instance_variable_get(:@minutes)
|
120
|
-
end
|
121
|
-
|
122
|
-
should "set the trigger's cron entry's hours to 2" do
|
123
|
-
assert_equal [2], @trigger.instance_variable_get(:@cron_entry).instance_variable_get(:@hours)
|
124
|
-
end
|
125
|
-
end #in addition to setting #{}
|
126
|
-
end #when called
|
127
|
-
end #for 10 minutes
|
128
|
-
|
129
|
-
context "for 11 minutes" do
|
130
|
-
setup do
|
131
|
-
@minutes = 11
|
132
|
-
end
|
133
|
-
|
134
|
-
should "raise an exception" do
|
135
|
-
assert_raise ChronoTrigger::ConfigurationException do
|
136
|
-
@trigger.every :minutes=>@minutes
|
137
|
-
end
|
138
|
-
end
|
139
|
-
end #for 11 minutes
|
140
|
-
end #on a call to #every
|
141
|
-
|
142
|
-
context "and a block that will raise an ActiveRecord::ConnectionNotEstablished exception, then return a value" do
|
143
|
-
setup do
|
144
|
-
@value = "hello"
|
145
|
-
|
146
|
-
@run_once = false
|
147
|
-
@trigger.runs do
|
148
|
-
if @run_once
|
149
|
-
@value
|
150
|
-
else
|
151
|
-
@run_once = true
|
152
|
-
raise ActiveRecord::ConnectionNotEstablished
|
153
|
-
end
|
154
|
-
end
|
155
|
-
end
|
156
|
-
|
157
|
-
should "raise an exception, which is caught, then retry the call method" do
|
158
|
-
require "active_record"
|
159
|
-
ActiveRecord::Base.stubs(:connection).returns(mock({:reconnect! => true}))
|
160
|
-
assert_equal @value, @trigger.execute
|
161
|
-
end
|
162
|
-
end #and a block that will raise an ActiveRecord::ConnectionNotEstablished exception, then return a value
|
163
|
-
|
164
|
-
should "raise an exception on call to #every without minutes or hours" do
|
165
|
-
assert_raise ChronoTrigger::ConfigurationException do
|
166
|
-
@trigger.every()
|
167
|
-
end
|
168
|
-
end
|
169
|
-
|
170
|
-
end #A Trigger, @trigger,
|
171
|
-
|
172
|
-
end
|
data/test/triggers.rb
DELETED
@@ -1,17 +0,0 @@
|
|
1
|
-
trigger "test_trigger" do
|
2
|
-
runs { "hello world" }
|
3
|
-
on :monday
|
4
|
-
at :hour=>3, :minute=>10
|
5
|
-
end
|
6
|
-
|
7
|
-
trigger "test_trigger_2" do
|
8
|
-
runs { "hello world 2" }
|
9
|
-
on :tuesday
|
10
|
-
every :hours=>2, :minutes=>10
|
11
|
-
end
|
12
|
-
|
13
|
-
trigger "test_trigger_3" do
|
14
|
-
runs { "hello world 3" }
|
15
|
-
monthly_on 15
|
16
|
-
at :hours=>2, :minutes=>10
|
17
|
-
end
|