coney_island 0.10.2 → 0.10.3
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/job.rb +2 -33
- data/lib/coney_island/submitter.rb +33 -5
- data/lib/coney_island/version.rb +1 -1
- data/lib/coney_island/worker.rb +2 -11
- data/test/coney_island_test.rb +1 -0
- data/test/dummy/log/test.log +12 -0
- data/test/performer_test.rb +2 -6
- 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: 22e0c2669707a9d1cc3ee045e95ca32039f5fcf6
|
4
|
+
data.tar.gz: 2ef3018f894f47115f0d0b2336e25156619765fc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d8c14389f6cd4e1deffcb9c25474b1eb0833d4a79d61786276b2b0d37c1acf03fd21f73b012f2d321117f2664fb031a65a73d6fee0f55a7d57d938d56a88e48b
|
7
|
+
data.tar.gz: 52d86d4d9fed7ebcecc46f465f1dfb4c1563ae7b719bbbc7a2149404c71967f37e20f95e9bf1033b61ff7cf7a0b0a153ee524987f7823d8e634b3f07a1619a78
|
data/lib/coney_island/job.rb
CHANGED
@@ -81,12 +81,7 @@ module ConeyIsland
|
|
81
81
|
end
|
82
82
|
|
83
83
|
def next_attempt_delay
|
84
|
-
|
85
|
-
time_delayed = (Time.now - self.delay_start).round
|
86
|
-
new_delay = self.delay - time_delayed
|
87
|
-
else
|
88
|
-
ConeyIsland.delay_seed**(self.attempts - 1)
|
89
|
-
end
|
84
|
+
ConeyIsland.delay_seed**(self.attempts - 1)
|
90
85
|
end
|
91
86
|
|
92
87
|
def resubmit_args
|
@@ -95,36 +90,10 @@ module ConeyIsland
|
|
95
90
|
end
|
96
91
|
|
97
92
|
def finalize_job
|
98
|
-
metadata.ack if !
|
93
|
+
metadata.ack if !ConeyIsland.running_inline?
|
99
94
|
log.info("finished job #{id}")
|
100
95
|
ConeyIsland::Worker.running_jobs.delete self
|
101
96
|
end
|
102
97
|
|
103
|
-
def delaying?
|
104
|
-
@delaying
|
105
|
-
end
|
106
|
-
|
107
|
-
def acked?
|
108
|
-
@acked
|
109
|
-
end
|
110
|
-
|
111
|
-
def activate_after_delay
|
112
|
-
@delaying = false
|
113
|
-
ConeyIsland::Worker.delayed_jobs.delete self
|
114
|
-
end
|
115
|
-
|
116
|
-
def delay_job
|
117
|
-
@delaying = true
|
118
|
-
ConeyIsland::Worker.delayed_jobs << self
|
119
|
-
unless ConeyIsland.running_inline?
|
120
|
-
@acked = true
|
121
|
-
metadata.ack
|
122
|
-
end
|
123
|
-
log.info("delaying job #{id} for #{self.delay} seconds")
|
124
|
-
end
|
125
|
-
|
126
|
-
def requeue_delay
|
127
|
-
ConeyIsland.submit(self.klass, self.method_name, self.resubmit_args)
|
128
|
-
end
|
129
98
|
end
|
130
99
|
end
|
@@ -51,10 +51,18 @@ module ConeyIsland
|
|
51
51
|
end
|
52
52
|
end
|
53
53
|
|
54
|
+
def self.channel
|
55
|
+
@channel
|
56
|
+
end
|
57
|
+
|
54
58
|
def self.exchange
|
55
59
|
@exchange
|
56
60
|
end
|
57
61
|
|
62
|
+
def self.delay_exchange
|
63
|
+
@delay_exchange
|
64
|
+
end
|
65
|
+
|
58
66
|
def self.amqp_parameters=(params)
|
59
67
|
@amqp_parameters = params
|
60
68
|
end
|
@@ -86,8 +94,10 @@ module ConeyIsland
|
|
86
94
|
retry
|
87
95
|
end
|
88
96
|
else
|
89
|
-
@channel
|
97
|
+
@channel ||= AMQP::Channel.new(@connection)
|
90
98
|
@exchange = @channel.topic('coney_island')
|
99
|
+
@delay_exchange = @channel.topic('coney_island_delay')
|
100
|
+
@delay_queue = {}
|
91
101
|
end
|
92
102
|
|
93
103
|
def self.amqp_connection
|
@@ -104,18 +114,36 @@ module ConeyIsland
|
|
104
114
|
job_args ||= {}
|
105
115
|
job_args['klass'] = klass_name
|
106
116
|
job_args['method_name'] = method_name
|
117
|
+
job_args.stringify_keys!
|
107
118
|
if @run_inline
|
108
|
-
job_args.stringify_keys!
|
109
119
|
job = ConeyIsland::Job.new(nil, job_args)
|
110
120
|
job.handle_job
|
111
121
|
else
|
112
|
-
work_queue = job_args.delete
|
122
|
+
work_queue = job_args.delete 'work_queue'
|
113
123
|
if klass.respond_to? :coney_island_settings
|
114
124
|
work_queue ||= klass.coney_island_settings[:work_queue]
|
115
125
|
end
|
116
126
|
work_queue ||= 'default'
|
117
|
-
|
118
|
-
|
127
|
+
delay = job_args['delay']
|
128
|
+
if klass.respond_to? :coney_island_settings
|
129
|
+
delay ||= klass.coney_island_settings[:delay]
|
130
|
+
end
|
131
|
+
if delay && delay.to_i > 0
|
132
|
+
puts 'delaying...'
|
133
|
+
@delay_queue[work_queue] ||= {}
|
134
|
+
unless @delay_queue[work_queue][delay].present?
|
135
|
+
@delay_queue[work_queue][delay] ||= self.channel.queue(
|
136
|
+
work_queue + '_delayed_' + delay.to_s, auto_delete: false, durable: true,
|
137
|
+
arguments: {'x-dead-letter-exchange' => 'coney_island', 'x-message-ttl' => delay * 1000})
|
138
|
+
@delay_queue[work_queue][delay].bind(self.delay_exchange, routing_key: 'carousels.' + work_queue + ".#{delay}")
|
139
|
+
end
|
140
|
+
self.delay_exchange.publish(job_args.to_json, {routing_key: "carousels.#{work_queue}.#{delay}"}) do
|
141
|
+
RequestStore.store[:jobs].delete job_id if RequestStore.store[:jobs] && job_id.present?
|
142
|
+
end
|
143
|
+
else
|
144
|
+
self.exchange.publish(job_args.to_json, {routing_key: "carousels.#{work_queue}"}) do
|
145
|
+
RequestStore.store[:jobs].delete job_id if RequestStore.store[:jobs] && job_id.present?
|
146
|
+
end
|
119
147
|
end
|
120
148
|
end
|
121
149
|
true
|
data/lib/coney_island/version.rb
CHANGED
data/lib/coney_island/worker.rb
CHANGED
@@ -135,7 +135,7 @@ module ConeyIsland
|
|
135
135
|
|
136
136
|
self.channel.prefetch @prefetch_count
|
137
137
|
@queue = self.channel.queue(@full_instance_name, auto_delete: false, durable: true)
|
138
|
-
@queue.bind(self.exchange, routing_key: 'carousels.' + @ticket)
|
138
|
+
@queue.bind(self.exchange, routing_key: 'carousels.' + @ticket + '.#')
|
139
139
|
@queue.subscribe(:ack => true) do |metadata,payload|
|
140
140
|
self.handle_incoming_message(metadata,payload)
|
141
141
|
end
|
@@ -164,16 +164,7 @@ module ConeyIsland
|
|
164
164
|
begin
|
165
165
|
args = JSON.parse(payload)
|
166
166
|
job = Job.new(metadata, args)
|
167
|
-
|
168
|
-
self.delayed_jobs << job
|
169
|
-
job.delay_job
|
170
|
-
EventMachine.add_timer(job.delay) do
|
171
|
-
job.activate_after_delay
|
172
|
-
job.handle_job
|
173
|
-
end
|
174
|
-
else
|
175
|
-
job.handle_job
|
176
|
-
end
|
167
|
+
job.handle_job
|
177
168
|
rescue Timeout::Error => e
|
178
169
|
ConeyIsland.poke_the_badger(e, {code_source: 'ConeyIsland', job_payload: args, reason: 'timeout in subscribe code before calling job method'})
|
179
170
|
rescue Exception => e
|
data/test/coney_island_test.rb
CHANGED
@@ -39,6 +39,7 @@ class ConeyIslandTest < MiniTest::Test
|
|
39
39
|
ConeyIsland.tcp_connection_retry_interval = 0
|
40
40
|
@fake_channel = MiniTest::Mock.new
|
41
41
|
@fake_channel.expect :topic, nil, [String]
|
42
|
+
@fake_channel.expect :topic, nil, [String]
|
42
43
|
AMQP::Channel.stub(:new,@fake_channel) do
|
43
44
|
AMQP.stub(:connect, force_tcp_error) do
|
44
45
|
ConeyIsland::Submitter.handle_connection
|
data/test/dummy/log/test.log
CHANGED
@@ -10,3 +10,15 @@ Failed to connecto to RabbitMQ Attempt #1 time(s), trying again in 0 seconds...
|
|
10
10
|
ConeyIsland::Submitter.submit! about to iterate over this many jobs: 1
|
11
11
|
Failed to connecto to RabbitMQ Attempt #1 time(s), trying again in 0 seconds...
|
12
12
|
ConeyIsland::Submitter.submit! about to iterate over this many jobs: 1
|
13
|
+
undefined method `[]' for nil:NilClass
|
14
|
+
undefined method `[]' for nil:NilClass
|
15
|
+
ConeyIsland::Submitter.submit! about to iterate over this many jobs: 1
|
16
|
+
Failed to connecto to RabbitMQ Attempt #1 time(s), trying again in 0 seconds...
|
17
|
+
undefined method `[]' for nil:NilClass
|
18
|
+
undefined method `[]' for nil:NilClass
|
19
|
+
undefined method `[]' for nil:NilClass
|
20
|
+
Failed to connecto to RabbitMQ Attempt #1 time(s), trying again in 0 seconds...
|
21
|
+
ConeyIsland::Submitter.submit! about to iterate over this many jobs: 1
|
22
|
+
undefined method `[]' for nil:NilClass
|
23
|
+
ConeyIsland::Submitter.submit! about to iterate over this many jobs: 1
|
24
|
+
Failed to connecto to RabbitMQ Attempt #1 time(s), trying again in 0 seconds...
|
data/test/performer_test.rb
CHANGED
@@ -23,8 +23,6 @@ class PerformerTest < MiniTest::Test
|
|
23
23
|
job.timeout.must_equal 10
|
24
24
|
end
|
25
25
|
it 'sets work queue for the class' do
|
26
|
-
capture_publish = proc do |payload,options|
|
27
|
-
end
|
28
26
|
@exchange = Minitest::Mock.new
|
29
27
|
def @exchange.publish(payload,options,&blk)
|
30
28
|
::PerformerTest.messages[:publish_hash] = options
|
@@ -32,15 +30,13 @@ class PerformerTest < MiniTest::Test
|
|
32
30
|
ConeyIsland::Submitter.stub(:handle_connection, nil) do
|
33
31
|
ConeyIsland::Submitter.stub(:exchange, @exchange) do
|
34
32
|
ConeyIsland::Submitter.stop_running_inline
|
35
|
-
ConeyIsland::Submitter.submit(MyPerformer, :
|
33
|
+
ConeyIsland::Submitter.submit(MyPerformer, :perform, args: [], delay: 0)
|
36
34
|
end
|
37
35
|
end
|
38
36
|
@exchange.verify
|
39
37
|
::PerformerTest.messages[:publish_hash][:routing_key].must_equal "carousels.cyclone"
|
40
38
|
end
|
41
39
|
it 'overrides the class work queue with the job-level work queue' do
|
42
|
-
capture_publish = proc do |payload,options|
|
43
|
-
end
|
44
40
|
@exchange = Minitest::Mock.new
|
45
41
|
def @exchange.publish(payload,options,&blk)
|
46
42
|
::PerformerTest.messages[:publish_hash] = options
|
@@ -48,7 +44,7 @@ class PerformerTest < MiniTest::Test
|
|
48
44
|
ConeyIsland::Submitter.stub(:handle_connection, nil) do
|
49
45
|
ConeyIsland::Submitter.stub(:exchange, @exchange) do
|
50
46
|
ConeyIsland::Submitter.stop_running_inline
|
51
|
-
ConeyIsland::Submitter.submit(MyPerformer, :add_to_list, work_queue: 'boardwalk', args: [[]])
|
47
|
+
ConeyIsland::Submitter.submit(MyPerformer, :add_to_list, work_queue: 'boardwalk', args: [[]], delay: 0)
|
52
48
|
end
|
53
49
|
end
|
54
50
|
@exchange.verify
|