chrono_trigger 0.1.7
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +13 -0
- data/Manifest.txt +24 -0
- data/PostInstall.txt +1 -0
- data/README.rdoc +59 -0
- data/Rakefile +50 -0
- data/VERSION.yml +4 -0
- data/bin/chrono_trigger +7 -0
- data/chrono_trigger.gemspec +69 -0
- data/lib/chrono_trigger.rb +11 -0
- data/lib/chrono_trigger/cron_entry.rb +71 -0
- data/lib/chrono_trigger/process.rb +37 -0
- data/lib/chrono_trigger/runner.rb +292 -0
- data/lib/chrono_trigger/shell.rb +36 -0
- data/lib/chrono_trigger/tasks.rb +3 -0
- data/lib/chrono_trigger/trigger.rb +127 -0
- data/lib/tasks/chrono_trigger.rake +14 -0
- data/lib/triggers/test_triggers.rb +31 -0
- data/script/console +10 -0
- data/script/destroy +14 -0
- data/script/generate +14 -0
- data/test/test_chrono_trigger.rb +11 -0
- data/test/test_cron_entry.rb +198 -0
- data/test/test_helper.rb +13 -0
- data/test/test_shell.rb +52 -0
- data/test/test_trigger.rb +172 -0
- data/test/triggers.rb +17 -0
- metadata +79 -0
data/test/test_helper.rb
ADDED
data/test/test_shell.rb
ADDED
@@ -0,0 +1,52 @@
|
|
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
|
@@ -0,0 +1,172 @@
|
|
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
ADDED
@@ -0,0 +1,17 @@
|
|
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
|
metadata
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: chrono_trigger
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.7
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Jon Ciccone
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-08-22 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: Binding to tag
|
15
|
+
email: darful@gmail.com
|
16
|
+
executables:
|
17
|
+
- chrono_trigger
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files:
|
20
|
+
- README.rdoc
|
21
|
+
files:
|
22
|
+
- History.txt
|
23
|
+
- Manifest.txt
|
24
|
+
- PostInstall.txt
|
25
|
+
- README.rdoc
|
26
|
+
- Rakefile
|
27
|
+
- VERSION.yml
|
28
|
+
- bin/chrono_trigger
|
29
|
+
- chrono_trigger.gemspec
|
30
|
+
- lib/chrono_trigger.rb
|
31
|
+
- lib/chrono_trigger/cron_entry.rb
|
32
|
+
- lib/chrono_trigger/process.rb
|
33
|
+
- lib/chrono_trigger/runner.rb
|
34
|
+
- lib/chrono_trigger/shell.rb
|
35
|
+
- lib/chrono_trigger/tasks.rb
|
36
|
+
- lib/chrono_trigger/trigger.rb
|
37
|
+
- lib/tasks/chrono_trigger.rake
|
38
|
+
- lib/triggers/test_triggers.rb
|
39
|
+
- script/console
|
40
|
+
- script/destroy
|
41
|
+
- script/generate
|
42
|
+
- test/test_chrono_trigger.rb
|
43
|
+
- test/test_cron_entry.rb
|
44
|
+
- test/test_helper.rb
|
45
|
+
- test/test_shell.rb
|
46
|
+
- test/test_trigger.rb
|
47
|
+
- test/triggers.rb
|
48
|
+
homepage: ''
|
49
|
+
licenses: []
|
50
|
+
post_install_message:
|
51
|
+
rdoc_options:
|
52
|
+
- --charset=UTF-8
|
53
|
+
require_paths:
|
54
|
+
- lib
|
55
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
56
|
+
none: false
|
57
|
+
requirements:
|
58
|
+
- - ! '>='
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '0'
|
61
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
62
|
+
none: false
|
63
|
+
requirements:
|
64
|
+
- - ! '>='
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '0'
|
67
|
+
requirements: []
|
68
|
+
rubyforge_project:
|
69
|
+
rubygems_version: 1.8.24
|
70
|
+
signing_key:
|
71
|
+
specification_version: 3
|
72
|
+
summary: binding to tag
|
73
|
+
test_files:
|
74
|
+
- test/test_chrono_trigger.rb
|
75
|
+
- test/test_cron_entry.rb
|
76
|
+
- test/test_helper.rb
|
77
|
+
- test/test_shell.rb
|
78
|
+
- test/test_trigger.rb
|
79
|
+
- test/triggers.rb
|