simple_job 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.rdoc CHANGED
@@ -1,5 +1,8 @@
1
1
  = Simple Job
2
2
 
3
+ == Version 0.5.0
4
+ * Added :asynchronous_execute option to SQSJobQueue#poll
5
+
3
6
  == Version 0.4.0
4
7
  * Made JobDefinition#job_definition_class_for more resilient to input types
5
8
  * Added #class_for alias to JobDefinition#job_definition_class_for
@@ -30,15 +30,26 @@ class SQSJobQueue < JobQueue
30
30
  @default_queue || super
31
31
  end
32
32
 
33
+ # Sets up an SQS queue, using the given type as a unique identifier for the name.
34
+ #
35
+ # A :visibility_timeout option may be passed to override the visibility timeout
36
+ # that is used when polling the queue.
37
+ #
38
+ # The :asynchronous_execute option, if set to true, will cause the poll method to
39
+ # parse and immediately accept each message (if it's validly formatted). It will
40
+ # then execute the proper job (outside the receive_message block). This can be
41
+ # used when you have long-running jobs that will exceed the visibility timeout,
42
+ # and it is not critical that they be retried when they fail.
33
43
  def self.define_queue(type, options = {})
34
44
  type = type.to_s
35
45
 
36
46
  options = {
37
47
  :visibility_timeout => config[:default_visibility_timeout],
48
+ :asynchronous_execute => false,
38
49
  :default => false,
39
50
  }.merge(options)
40
51
 
41
- queue = self.new(type, options[:visibility_timeout])
52
+ queue = self.new(type, options[:visibility_timeout], options[:asynchronous_execute])
42
53
  self.queues ||= {}
43
54
  self.queues[type] = queue
44
55
 
@@ -130,6 +141,7 @@ class SQSJobQueue < JobQueue
130
141
  loop do
131
142
  break if max_executions && (max_executions <= 0)
132
143
  last_message = nil
144
+ last_definition = nil
133
145
  current_start_milliseconds = get_milliseconds
134
146
  current_job_type = 'unknown'
135
147
  begin
@@ -146,9 +158,16 @@ class SQSJobQueue < JobQueue
146
158
  end
147
159
 
148
160
  definition = definition_class.new.from_json(message.body)
149
- message_handler.call(definition, message)
161
+ last_definition = definition
162
+
163
+ # NOTE: only executes if asynchronous_execute is false (message will be re-enqueued after
164
+ # vis. timeout if this fails or runs too long)
165
+ message_handler.call(definition, message) unless asynchronous_execute
150
166
  end
151
167
 
168
+ # NOTE: only executes if asynchronous_execute is set (after message has been confirmed)
169
+ message_handler.call(definition, message) if asynchronous_execute
170
+
152
171
  log_execution(true, last_message, current_job_type, current_start_milliseconds)
153
172
 
154
173
  break if options[:idle_timeout] && ((Time.now - last_message_at) > options[:idle_timeout])
@@ -185,13 +204,14 @@ class SQSJobQueue < JobQueue
185
204
  attr_accessor :queues
186
205
  end
187
206
 
188
- attr_accessor :queue_name, :sqs_queue, :visibility_timeout, :cloud_watch
207
+ attr_accessor :queue_name, :sqs_queue, :visibility_timeout, :asynchronous_execute, :cloud_watch
189
208
 
190
- def initialize(type, visibility_timeout)
209
+ def initialize(type, visibility_timeout, asynchronous_execute)
191
210
  sqs = ::AWS::SQS.new
192
211
  self.queue_name = "#{self.class.config[:queue_prefix]}-#{type}-#{self.class.config[:environment]}"
193
212
  self.sqs_queue = sqs.queues.create(queue_name)
194
213
  self.visibility_timeout = visibility_timeout
214
+ self.asynchronous_execute = asynchronous_execute
195
215
  self.cloud_watch = Fog::AWS::CloudWatch.new(
196
216
  :aws_access_key_id => AWS.config.access_key_id,
197
217
  :aws_secret_access_key => AWS.config.secret_access_key
@@ -1,3 +1,3 @@
1
1
  module SimpleJob
2
- VERSION = '0.4.0'
2
+ VERSION = '0.5.0'
3
3
  end
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: 15
4
+ hash: 11
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 4
8
+ - 5
9
9
  - 0
10
- version: 0.4.0
10
+ version: 0.5.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - David Dawson