coney_island 0.12.3 → 0.12.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/coney_island/submitter.rb +66 -46
- data/lib/coney_island/version.rb +1 -1
- data/test/dummy/log/test.log +30 -0
- data/test/submitter_test.rb +14 -0
- 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: 3ebf4aa13f64b3592f798c759e5a28a5e17c84ab
|
4
|
+
data.tar.gz: b22573d2f20af9c3e212351632615e38e2b39aae
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e31f447e805176a230c56540099b49dfc5f348287a9cfd957398cd8ebd7017debf9a5c605d650cbb6999d6acdd10d8b134642763d981f5febd30d9ef8da811ee
|
7
|
+
data.tar.gz: 767d5f3ef2575904e57cf6b53f2da1f48e6aba5e6e74efa5e476064ef4f601812ca017ac0dbbe533f4274306669699f67f3b28fde51abe98fcd66f09faf57e0f
|
@@ -10,7 +10,7 @@ module ConeyIsland
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def self.running_inline?
|
13
|
-
|
13
|
+
!!@run_inline
|
14
14
|
end
|
15
15
|
|
16
16
|
def self.tcp_connection_retries=(number)
|
@@ -149,53 +149,49 @@ module ConeyIsland
|
|
149
149
|
end
|
150
150
|
|
151
151
|
def self.publish_job(args, job_id = nil)
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
else
|
190
|
-
self.exchange.publish(job_args.to_json, {routing_key: "carousels.#{work_queue}"}) do
|
191
|
-
RequestStore.store[:jobs].delete job_id if RequestStore.store[:jobs] && job_id.present?
|
192
|
-
end
|
193
|
-
end
|
194
|
-
end
|
195
|
-
true
|
152
|
+
# Map arguments
|
153
|
+
klass, method_name, job_args = *args
|
154
|
+
# Job args is optional
|
155
|
+
job_args ||= {}
|
156
|
+
|
157
|
+
# Check arguments
|
158
|
+
# Break if klass isn't a Class or a Module
|
159
|
+
raise ConeyIsland::JobArgumentError.new "Expected #{klass} to be a Class or Module" unless [Class, Module].any? {|k| klass.is_a?(k)}
|
160
|
+
# Break if method_name isn't a String or a Symbol
|
161
|
+
raise ConeyIsland::JobArgumentError.new "Expected #{method_name} to be a String or a Symbol" unless [String,Symbol].any? {|k| method_name.is_a?(k)}
|
162
|
+
|
163
|
+
# Set defaults
|
164
|
+
job_args['klass'] = klass.name
|
165
|
+
job_args['method_name'] = method_name
|
166
|
+
job_args.stringify_keys!
|
167
|
+
|
168
|
+
# Extract non job args
|
169
|
+
delay = job_args.delete 'delay'
|
170
|
+
work_queue = job_args.delete 'work_queue'
|
171
|
+
|
172
|
+
# Set class defaults if they exist
|
173
|
+
if klass.included_modules.include?(Performer)
|
174
|
+
delay ||= klass.get_coney_settings[:delay]
|
175
|
+
work_queue ||= klass.get_coney_settings[:work_queue]
|
176
|
+
end
|
177
|
+
|
178
|
+
# Set our own defaults if we still don't have any
|
179
|
+
work_queue ||= ConeyIsland.default_settings[:work_queue]
|
180
|
+
delay ||= ConeyIsland.default_settings[:delay]
|
181
|
+
|
182
|
+
if self.running_inline?
|
183
|
+
# Just run this inline if we're not threaded
|
184
|
+
ConeyIsland::Job.new(nil, job_args).handle_job
|
185
|
+
elsif delay && delay.to_i > 0
|
186
|
+
# Is this delayed?
|
187
|
+
# Publish to the delay exchange
|
188
|
+
publish_to_delay_queue(job_id, job_args, work_queue, delay)
|
196
189
|
else
|
197
|
-
|
190
|
+
# Publish to the normal exchange
|
191
|
+
publish_to_queue(self.exchange, job_id, job_args, work_queue)
|
198
192
|
end
|
193
|
+
|
194
|
+
true
|
199
195
|
end
|
200
196
|
|
201
197
|
def self.cache_jobs
|
@@ -211,6 +207,30 @@ module ConeyIsland
|
|
211
207
|
RequestStore.store[:cache_jobs] = false
|
212
208
|
end
|
213
209
|
|
210
|
+
protected
|
211
|
+
|
212
|
+
# Publishes a job to a delayed queue exchange
|
213
|
+
def self.publish_to_delay_queue(job_id, job_args, work_queue, delay)
|
214
|
+
@delay_queue[work_queue] ||= {}
|
215
|
+
|
216
|
+
# TODO: Should this be in a different little method, say, bind_delay?
|
217
|
+
unless @delay_queue[work_queue][delay].present?
|
218
|
+
@delay_queue[work_queue][delay] ||= self.channel.queue(
|
219
|
+
work_queue + '_delayed_' + delay.to_s, auto_delete: false, durable: true,
|
220
|
+
arguments: {'x-dead-letter-exchange' => 'coney_island', 'x-message-ttl' => delay * 1000})
|
221
|
+
@delay_queue[work_queue][delay].bind(self.delay_exchange, routing_key: 'carousels.' + work_queue + ".#{delay}")
|
222
|
+
end
|
223
|
+
|
224
|
+
publish_to_queue(self.delay_exchange, job_id, job_args, "#{work_queue}.#{delay}")
|
225
|
+
end
|
226
|
+
|
227
|
+
# Publishes a job to a given exchange
|
228
|
+
def self.publish_to_queue(exchange, job_id, job_args, queue)
|
229
|
+
exchange.publish(job_args.to_json, {routing_key: "carousels.#{queue}"}) do
|
230
|
+
RequestStore.store[:jobs].delete job_id if RequestStore.store[:jobs] && job_id.present?
|
231
|
+
end
|
232
|
+
end
|
233
|
+
|
214
234
|
end
|
215
235
|
end
|
216
236
|
|
data/lib/coney_island/version.rb
CHANGED
data/test/dummy/log/test.log
CHANGED
@@ -138,3 +138,33 @@ ConeyIsland::Submitter.submit! about to iterate over this many jobs: 1
|
|
138
138
|
ConeyIsland::Submitter.handle_connection connecting...
|
139
139
|
Failed to connecto to RabbitMQ Attempt #1 time(s), trying again in 0 seconds...
|
140
140
|
ConeyIsland::Submitter.handle_connection connecting...
|
141
|
+
ConeyIsland::Submitter.submit! about to iterate over this many jobs: 1
|
142
|
+
ConeyIsland::Submitter.handle_connection connecting...
|
143
|
+
Failed to connecto to RabbitMQ Attempt #1 time(s), trying again in 0 seconds...
|
144
|
+
ConeyIsland::Submitter.handle_connection connecting...
|
145
|
+
ConeyIsland::Submitter.handle_connection connecting...
|
146
|
+
Failed to connecto to RabbitMQ Attempt #1 time(s), trying again in 0 seconds...
|
147
|
+
ConeyIsland::Submitter.handle_connection connecting...
|
148
|
+
ConeyIsland::Submitter.submit! about to iterate over this many jobs: 1
|
149
|
+
ConeyIsland::Submitter.handle_connection connecting...
|
150
|
+
Failed to connecto to RabbitMQ Attempt #1 time(s), trying again in 0 seconds...
|
151
|
+
ConeyIsland::Submitter.handle_connection connecting...
|
152
|
+
ConeyIsland::Submitter.handle_connection connecting...
|
153
|
+
Failed to connecto to RabbitMQ Attempt #1 time(s), trying again in 0 seconds...
|
154
|
+
ConeyIsland::Submitter.handle_connection connecting...
|
155
|
+
ConeyIsland::Submitter.handle_connection connecting...
|
156
|
+
Failed to connecto to RabbitMQ Attempt #1 time(s), trying again in 0 seconds...
|
157
|
+
ConeyIsland::Submitter.handle_connection connecting...
|
158
|
+
ConeyIsland::Submitter.handle_connection connecting...
|
159
|
+
Failed to connecto to RabbitMQ Attempt #1 time(s), trying again in 0 seconds...
|
160
|
+
ConeyIsland::Submitter.handle_connection connecting...
|
161
|
+
ConeyIsland::Submitter.handle_connection connecting...
|
162
|
+
Failed to connecto to RabbitMQ Attempt #1 time(s), trying again in 0 seconds...
|
163
|
+
ConeyIsland::Submitter.handle_connection connecting...
|
164
|
+
ConeyIsland::Submitter.handle_connection connecting...
|
165
|
+
Failed to connecto to RabbitMQ Attempt #1 time(s), trying again in 0 seconds...
|
166
|
+
ConeyIsland::Submitter.handle_connection connecting...
|
167
|
+
ConeyIsland::Submitter.handle_connection connecting...
|
168
|
+
Failed to connecto to RabbitMQ Attempt #1 time(s), trying again in 0 seconds...
|
169
|
+
ConeyIsland::Submitter.handle_connection connecting...
|
170
|
+
ConeyIsland::Submitter.submit! about to iterate over this many jobs: 1
|
data/test/submitter_test.rb
CHANGED
@@ -27,6 +27,20 @@ class SubmitterTest < MiniTest::Test
|
|
27
27
|
end
|
28
28
|
end
|
29
29
|
describe "error handling" do
|
30
|
+
it "breaks if klass is not a class or a Module" do
|
31
|
+
error = assert_raises(ConeyIsland::JobArgumentError) do
|
32
|
+
ConeyIsland::Submitter.publish_job([:not_a_class, :method])
|
33
|
+
end
|
34
|
+
assert_match /to be a Class or Module/, error.message
|
35
|
+
end
|
36
|
+
|
37
|
+
it "breaks if the method_name is not a String or a Symbol" do
|
38
|
+
error = assert_raises(ConeyIsland::JobArgumentError) do
|
39
|
+
ConeyIsland::Submitter.publish_job([Class, 1])
|
40
|
+
end
|
41
|
+
assert_match /to be a String or a Symbol/, error.message
|
42
|
+
end
|
43
|
+
|
30
44
|
it "handles argument errors for jobs" do
|
31
45
|
assert_raises(ConeyIsland::JobArgumentError) do
|
32
46
|
ConeyIsland::Submitter.publish_job([:not_a_class, :add_to_list, args: [[]]])
|