simple_job 0.2.1 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.rdoc +4 -0
- data/lib/simple_job/job_definition.rb +5 -0
- data/lib/simple_job/sqs_job_queue.rb +18 -1
- data/lib/simple_job/version.rb +1 -1
- metadata +4 -4
data/CHANGELOG.rdoc
CHANGED
@@ -1,5 +1,9 @@
|
|
1
1
|
= Simple Job
|
2
2
|
|
3
|
+
== Version 0.3.0
|
4
|
+
* Allowing JobDefinition#execute method to take a message parameter
|
5
|
+
* Adding max_attempt_count declaration to JobDefinition
|
6
|
+
|
3
7
|
== Version 0.2.1
|
4
8
|
* Disabling type/version checking to support multiple type declarations in one job
|
5
9
|
|
@@ -150,6 +150,11 @@ module JobDefinition
|
|
150
150
|
::SimpleJob::JobDefinition.job_definitions << new_definition
|
151
151
|
end
|
152
152
|
|
153
|
+
def max_attempt_count(attempts = nil)
|
154
|
+
@max_attempt_count = attempts if attempts
|
155
|
+
@max_attempt_count
|
156
|
+
end
|
157
|
+
|
153
158
|
def job_queue(queue_type = nil)
|
154
159
|
@job_queue = JobQueue[queue_type] if queue_type
|
155
160
|
@job_queue
|
@@ -66,6 +66,9 @@ class SQSJobQueue < JobQueue
|
|
66
66
|
# two arguments, the matching job definition (already populated with the
|
67
67
|
# contents of the message) and the raw AWS message.
|
68
68
|
#
|
69
|
+
# The #execute method MAY have a parameter, which will be populated with
|
70
|
+
# the raw AWS::SQS::ReceivedMessage object if it exists.
|
71
|
+
#
|
69
72
|
# The queue's configured visibility timeout will be used unless the
|
70
73
|
# :visibility_timeout option is passed (as a number of seconds).
|
71
74
|
#
|
@@ -84,6 +87,9 @@ class SQSJobQueue < JobQueue
|
|
84
87
|
# will safely complete processing the current message and return if a HUP,
|
85
88
|
# INT, or TERM signal is sent to the process.
|
86
89
|
#
|
90
|
+
# You may also pass a :max_executions option (as an integer), in which case
|
91
|
+
# the poll method will poll that many times and then exit.
|
92
|
+
#
|
87
93
|
# Note that this method will override any signal handlers for the HUP, INT,
|
88
94
|
# or TERM signals during its execution, but the previous handlers will be
|
89
95
|
# restored once the method returns.
|
@@ -98,7 +104,12 @@ class SQSJobQueue < JobQueue
|
|
98
104
|
}.merge(options)
|
99
105
|
|
100
106
|
message_handler = block || lambda do |definition, message|
|
101
|
-
definition.execute
|
107
|
+
execute_method = definition.method(:execute)
|
108
|
+
arguments = []
|
109
|
+
if execute_method.arity >= 1
|
110
|
+
arguments << message
|
111
|
+
end
|
112
|
+
execute_method.call(*arguments)
|
102
113
|
end
|
103
114
|
|
104
115
|
exit_next = false
|
@@ -127,7 +138,13 @@ class SQSJobQueue < JobQueue
|
|
127
138
|
raw_message = JSON.parse(message.body)
|
128
139
|
current_job_type = raw_message['type']
|
129
140
|
definition_class = JobDefinition.job_definition_class_for(raw_message['type'], raw_message['version'])
|
141
|
+
|
130
142
|
raise('no definition found') if !definition_class
|
143
|
+
|
144
|
+
if definition_class.max_attempt_count && (message.receive_count > definition_class.max_attempt_count)
|
145
|
+
raise('max attempt count reached')
|
146
|
+
end
|
147
|
+
|
131
148
|
definition = definition_class.new.from_json(message.body)
|
132
149
|
message_handler.call(definition, message)
|
133
150
|
end
|
data/lib/simple_job/version.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simple_job
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 19
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 0.
|
8
|
+
- 3
|
9
|
+
- 0
|
10
|
+
version: 0.3.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- David Dawson
|