gregfitz23-chrono_trigger 0.1.3 → 0.1.4
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.yml +2 -2
- data/lib/chrono_trigger/trigger.rb +34 -10
- data/test/test_trigger.rb +23 -0
- metadata +2 -2
data/VERSION.yml
CHANGED
@@ -23,11 +23,11 @@ module ChronoTrigger
|
|
23
23
|
def at(options={})
|
24
24
|
validate_hours_or_minutes!(options)
|
25
25
|
|
26
|
-
if hour = options[:hour]
|
26
|
+
if hour = (options[:hour] || options[:hours])
|
27
27
|
cron_entry.set_hours(hour)
|
28
28
|
end
|
29
29
|
|
30
|
-
if minute = options[:minute]
|
30
|
+
if minute = (options[:minute] || options[:minutes])
|
31
31
|
cron_entry.set_minutes(minute)
|
32
32
|
end
|
33
33
|
end
|
@@ -36,11 +36,11 @@ module ChronoTrigger
|
|
36
36
|
#Specifying minutes not divisible by 60 result in an exception, use #at instead.
|
37
37
|
def every(options={})
|
38
38
|
validate_hours_or_minutes!(options)
|
39
|
-
if minutes = options[:minutes]
|
39
|
+
if minutes = (options[:minutes] || options[:minute])
|
40
40
|
cron_entry.set_minutes(extract_minutes_for_every(minutes))
|
41
41
|
end
|
42
42
|
|
43
|
-
if hours = options[:hours]
|
43
|
+
if hours = (options[:hours] || options[:hour])
|
44
44
|
cron_entry.set_hours(extract_hours_for_every(hours))
|
45
45
|
end
|
46
46
|
end
|
@@ -55,12 +55,7 @@ module ChronoTrigger
|
|
55
55
|
end
|
56
56
|
|
57
57
|
def execute
|
58
|
-
|
59
|
-
@exec_block.call
|
60
|
-
rescue Exception
|
61
|
-
STDERR.puts "Exception #{$!.inspect} caught in Trigger##{self.name}. Backtrace:"
|
62
|
-
STDERR.puts $!.backtrace
|
63
|
-
end
|
58
|
+
defined?(ActiveRecord) ? execute_with_active_record : execute_without_active_record
|
64
59
|
end
|
65
60
|
|
66
61
|
|
@@ -93,5 +88,34 @@ module ChronoTrigger
|
|
93
88
|
|
94
89
|
(0...base).select {|num| num % time_value == 0}
|
95
90
|
end
|
91
|
+
|
92
|
+
# When ActiveRecord is defined, attempt to rescue ConnectionNotEstablished errors once,
|
93
|
+
# and reestablish the connection to the database. If this fails, normal exception logging will take place.
|
94
|
+
#
|
95
|
+
def execute_with_active_record
|
96
|
+
begin
|
97
|
+
@exec_block.call
|
98
|
+
rescue ActiveRecord::ConnectionNotEstablished
|
99
|
+
ActiveRecord::Base.connection.reconnect!
|
100
|
+
execute_without_active_record
|
101
|
+
rescue Exception
|
102
|
+
log_exception
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
# Execute the execution block and log all exceptions.
|
107
|
+
#
|
108
|
+
def execute_without_active_record
|
109
|
+
begin
|
110
|
+
@exec_block.call
|
111
|
+
rescue Exception
|
112
|
+
log_exception
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
def log_exception
|
117
|
+
STDERR.puts "Exception #{$!.inspect} caught in Trigger##{self.name}. Backtrace:"
|
118
|
+
STDERR.puts $!.backtrace
|
119
|
+
end
|
96
120
|
end
|
97
121
|
end
|
data/test/test_trigger.rb
CHANGED
@@ -118,11 +118,34 @@ class TestTrigger < Test::Unit::TestCase
|
|
118
118
|
end #for 11 minutes
|
119
119
|
end #on a call to #every
|
120
120
|
|
121
|
+
context "and a block that will raise an ActiveRecord::ConnectionNotEstablished exception, then return a value" do
|
122
|
+
setup do
|
123
|
+
@value = "hello"
|
124
|
+
|
125
|
+
@run_once = false
|
126
|
+
@trigger.runs do
|
127
|
+
if @run_once
|
128
|
+
@value
|
129
|
+
else
|
130
|
+
@run_once = true
|
131
|
+
raise ActiveRecord::ConnectionNotEstablished
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
should "raise an exception, which is caught, then retry the call method" do
|
137
|
+
require "active_record"
|
138
|
+
ActiveRecord::Base.stubs(:connection).returns(mock({:reconnect! => true}))
|
139
|
+
assert_equal @value, @trigger.execute
|
140
|
+
end
|
141
|
+
end #and a block that will raise an ActiveRecord::ConnectionNotEstablished exception, then return a value
|
142
|
+
|
121
143
|
should "raise an exception on call to #every without minutes or hours" do
|
122
144
|
assert_raise ChronoTrigger::ConfigurationException do
|
123
145
|
@trigger.every()
|
124
146
|
end
|
125
147
|
end
|
148
|
+
|
126
149
|
end #A Trigger, @trigger,
|
127
150
|
|
128
151
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gregfitz23-chrono_trigger
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Greg Fitzgerald
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-07-09 00:00:00 -07:00
|
13
13
|
default_executable: chrono_trigger
|
14
14
|
dependencies: []
|
15
15
|
|