simple_job 0.11.0 → 0.12.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.rdoc +4 -0
- data/lib/simple_job/sqs_job_queue.rb +40 -9
- data/lib/simple_job/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7c017adc129ac7a434ceabc18789ffa3961e7a13
|
4
|
+
data.tar.gz: 4a7f812e0810ca90604bb300a10b43f31c019116
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0a6c69686ed7cebc1ba2531a2df856d6f9f154181b1eeb3ff82b82e5f528df3e44b7fd3a6b07d24398b8958a35f4dbb6091fe5a5a0046a23dada6d060ee19a3a
|
7
|
+
data.tar.gz: 9f75a0b951dfd8b9d72c490ae40aeff1a2871e723a9e98ce81702203afe563f6592c76dd7318d41a2123b2a7219c396827f652d47860e0c879255459b47d0c82
|
data/CHANGELOG.rdoc
CHANGED
@@ -1,5 +1,9 @@
|
|
1
1
|
= Simple Job
|
2
2
|
|
3
|
+
== Version 0.12.0
|
4
|
+
* Added accept_nested_definition option to SQSJobQueue
|
5
|
+
* Updating specs and eliminating their dependency on AWS
|
6
|
+
|
3
7
|
== Version 0.11.0
|
4
8
|
* Using explicit aws-sdk-v1 to allow apps dependent on this library to use both v1 and v2 of aws sdk
|
5
9
|
|
@@ -42,20 +42,38 @@ class SQSJobQueue < JobQueue
|
|
42
42
|
# then fork and execute the proper job in a separate process. This can be
|
43
43
|
# used when you have long-running jobs that will exceed the visibility timeout,
|
44
44
|
# and it is not critical that they be retried when they fail.
|
45
|
+
#
|
46
|
+
# You may pass an :accept_nested_definition option with a string value to allow this
|
47
|
+
# queue to accept messages where the body is nested within a hash entry. This
|
48
|
+
# facilitates easy processing of SNS and AutoScaling messages. For example, if you
|
49
|
+
# pass this option:
|
50
|
+
#
|
51
|
+
# accept_nested_definition: 'NotificationMetadata'
|
52
|
+
#
|
53
|
+
# Then you can put a job body into the NotificationMetadata of an AutoScaling
|
54
|
+
# notification:
|
55
|
+
#
|
56
|
+
# { "AutoScalingGroupName": "some_name", "Service": "AWS Auto Scaling" ...
|
57
|
+
# "NotificationMetadata": "{\"type\":\"my_job\",\"version\":\"1\"}" }
|
58
|
+
#
|
59
|
+
# Then the queue will attempt to process incoming messages normally, but if it
|
60
|
+
# encounters a message missing a type and version, it will check the value
|
61
|
+
# passed into accept_nested_definition before failing.
|
45
62
|
def self.define_queue(type, options = {})
|
46
63
|
type = type.to_s
|
47
64
|
|
48
65
|
options = {
|
49
|
-
:
|
50
|
-
:
|
51
|
-
:
|
66
|
+
visibility_timeout: config[:default_visibility_timeout],
|
67
|
+
asynchronous_execute: false,
|
68
|
+
default: false
|
52
69
|
}.merge(options)
|
70
|
+
make_default = options.delete(:default)
|
53
71
|
|
54
|
-
queue = self.new(type, options
|
72
|
+
queue = self.new(type, options)
|
55
73
|
self.queues ||= {}
|
56
74
|
self.queues[type] = queue
|
57
75
|
|
58
|
-
@default_queue = queue if
|
76
|
+
@default_queue = queue if make_default
|
59
77
|
|
60
78
|
queue
|
61
79
|
end
|
@@ -153,9 +171,10 @@ class SQSJobQueue < JobQueue
|
|
153
171
|
current_job_type = 'unknown'
|
154
172
|
begin
|
155
173
|
sqs_queue.receive_messages(options) do |message|
|
174
|
+
message_body = get_message_body(message)
|
156
175
|
last_message = message
|
157
176
|
last_message_at = Time.now
|
158
|
-
raw_message = JSON.parse(
|
177
|
+
raw_message = JSON.parse(message_body)
|
159
178
|
current_job_type = raw_message['type']
|
160
179
|
definition_class = JobDefinition.job_definition_class_for(raw_message['type'], raw_message['version'])
|
161
180
|
|
@@ -165,7 +184,7 @@ class SQSJobQueue < JobQueue
|
|
165
184
|
raise('max attempt count reached')
|
166
185
|
end
|
167
186
|
|
168
|
-
definition = definition_class.new.from_json(
|
187
|
+
definition = definition_class.new.from_json(message_body)
|
169
188
|
last_definition = definition
|
170
189
|
|
171
190
|
# NOTE: only executes if asynchronous_execute is false (message will be re-enqueued after
|
@@ -230,9 +249,9 @@ class SQSJobQueue < JobQueue
|
|
230
249
|
attr_accessor :queues
|
231
250
|
end
|
232
251
|
|
233
|
-
attr_accessor :queue_name, :sqs_queue, :visibility_timeout, :asynchronous_execute, :cloud_watch
|
252
|
+
attr_accessor :queue_name, :sqs_queue, :visibility_timeout, :asynchronous_execute, :cloud_watch, :accept_nested_definition
|
234
253
|
|
235
|
-
def initialize(type, visibility_timeout
|
254
|
+
def initialize(type, visibility_timeout:, asynchronous_execute:, accept_nested_definition: nil)
|
236
255
|
sqs = ::AWS::SQS.new
|
237
256
|
self.queue_name = "#{self.class.config[:queue_prefix]}-#{type}-#{self.class.config[:environment]}"
|
238
257
|
self.sqs_queue = sqs.queues.create(queue_name)
|
@@ -242,6 +261,7 @@ class SQSJobQueue < JobQueue
|
|
242
261
|
:aws_access_key_id => AWS.config.access_key_id,
|
243
262
|
:aws_secret_access_key => AWS.config.secret_access_key
|
244
263
|
)
|
264
|
+
self.accept_nested_definition = accept_nested_definition
|
245
265
|
end
|
246
266
|
|
247
267
|
def logger
|
@@ -350,6 +370,17 @@ class SQSJobQueue < JobQueue
|
|
350
370
|
end
|
351
371
|
end
|
352
372
|
|
373
|
+
def get_message_body(message)
|
374
|
+
result = message.body
|
375
|
+
message_hash = JSON.parse(result)
|
376
|
+
|
377
|
+
if (!message_hash.has_key?('type') || !message_hash.has_key?('version')) && accept_nested_definition
|
378
|
+
result = message_hash[accept_nested_definition]
|
379
|
+
end
|
380
|
+
|
381
|
+
result
|
382
|
+
end
|
383
|
+
|
353
384
|
end
|
354
385
|
end
|
355
386
|
|
data/lib/simple_job/version.rb
CHANGED