eventq_rabbitmq 1.6.20 → 1.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/eventq_rabbitmq/rabbitmq_queue_worker.rb +67 -50
- data/lib/eventq_rabbitmq/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: e5d18c5f1558513c4230028b4551794ed95f1b82
|
4
|
+
data.tar.gz: 219e41df27fe185358b86db4928b10b306e7aab1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fb8df72733db2a36a7474ec4518c0be56c4b5220e77117b5ba576cdbea0456bc1cd9605ffe3b9798541abb8ca32ddfa4324515dccc8a770ba819d1f56b0704c3
|
7
|
+
data.tar.gz: 73f268f2d7c1c86179aa77eced1a165177fea070db9d0657219d3c8227eb324503863dcbd19691ca134f4fa819e88e10fa54e549102411ca66481f792e00da42
|
@@ -2,6 +2,8 @@ module EventQ
|
|
2
2
|
module RabbitMq
|
3
3
|
class QueueWorker
|
4
4
|
|
5
|
+
PROFILE_MEMORY = 'PROFILE_MEMORY'.freeze
|
6
|
+
|
5
7
|
attr_accessor :is_running
|
6
8
|
|
7
9
|
def initialize
|
@@ -78,85 +80,100 @@ module EventQ
|
|
78
80
|
break
|
79
81
|
end
|
80
82
|
|
81
|
-
|
83
|
+
if ENV[PROFILE_MEMORY] != nil
|
84
|
+
require 'memory_profiler'
|
82
85
|
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
+
report = MemoryProfiler.report do
|
87
|
+
thread_process_iteration(connection, manager, queue, block)
|
88
|
+
end
|
86
89
|
|
87
|
-
|
88
|
-
error = false
|
89
|
-
abort = false
|
90
|
+
EventQ.log(:debug, report.pretty_print.to_s)
|
90
91
|
|
91
|
-
|
92
|
-
|
92
|
+
else
|
93
|
+
thread_process_iteration(connection, manager, queue, block)
|
94
|
+
end
|
93
95
|
|
94
|
-
|
95
|
-
if payload != nil
|
96
|
+
end
|
96
97
|
|
97
|
-
|
98
|
+
connection.close
|
98
99
|
|
99
|
-
|
100
|
+
end
|
101
|
+
@threads.push(thr)
|
100
102
|
|
101
|
-
|
103
|
+
end
|
102
104
|
|
103
|
-
|
104
|
-
|
105
|
-
|
105
|
+
if options.key?(:wait) && options[:wait] == true
|
106
|
+
@threads.each { |thr| thr.join }
|
107
|
+
end
|
106
108
|
|
107
|
-
|
108
|
-
abort = true
|
109
|
-
EventQ.log(:info, "[#{self.class}] - Message aborted.")
|
110
|
-
else
|
111
|
-
#accept the message as processed
|
112
|
-
channel.acknowledge(delivery_info.delivery_tag, false)
|
113
|
-
EventQ.log(:info, "[#{self.class}] - Message acknowledged.")
|
114
|
-
received = true
|
115
|
-
end
|
109
|
+
return true
|
116
110
|
|
117
|
-
|
118
|
-
EventQ.log(:error, "[#{self.class}] - An unhandled error happened attempting to process a queue message. Error: #{e}")
|
111
|
+
end
|
119
112
|
|
120
|
-
|
113
|
+
def thread_process_iteration(connection, manager, queue, block)
|
114
|
+
channel = connection.create_channel
|
121
115
|
|
122
|
-
|
116
|
+
#get the queue
|
117
|
+
q = manager.get_queue(channel, queue)
|
118
|
+
retry_exchange = manager.get_retry_exchange(channel, queue)
|
123
119
|
|
124
|
-
|
125
|
-
|
126
|
-
|
120
|
+
received = false
|
121
|
+
error = false
|
122
|
+
abort = false
|
127
123
|
|
128
|
-
|
124
|
+
begin
|
125
|
+
delivery_info, properties, payload = q.pop(:manual_ack => true, :block => true)
|
129
126
|
|
130
|
-
|
131
|
-
|
132
|
-
|
127
|
+
#check that message was received
|
128
|
+
if payload != nil
|
129
|
+
|
130
|
+
message = deserialize_message(payload)
|
133
131
|
|
134
|
-
|
132
|
+
EventQ.log(:debug, "[#{self.class}] - Message received. Retry Attempts: #{message.retry_attempts}")
|
135
133
|
|
136
|
-
|
134
|
+
message_args = EventQ::MessageArgs.new(message.type, message.retry_attempts)
|
137
135
|
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
136
|
+
#begin worker block for queue message
|
137
|
+
begin
|
138
|
+
block.call(message.content, message_args)
|
139
|
+
|
140
|
+
if message_args.abort == true
|
141
|
+
abort = true
|
142
|
+
EventQ.log(:info, "[#{self.class}] - Message aborted.")
|
143
|
+
else
|
144
|
+
#accept the message as processed
|
145
|
+
channel.acknowledge(delivery_info.delivery_tag, false)
|
146
|
+
EventQ.log(:info, "[#{self.class}] - Message acknowledged.")
|
147
|
+
received = true
|
143
148
|
end
|
144
149
|
|
150
|
+
rescue => e
|
151
|
+
EventQ.log(:error, "[#{self.class}] - An unhandled error happened attempting to process a queue message. Error: #{e}")
|
152
|
+
|
153
|
+
error = true
|
154
|
+
|
145
155
|
end
|
146
156
|
|
147
|
-
|
157
|
+
if error || abort
|
158
|
+
reject_message(channel, message, delivery_info, retry_exchange, queue)
|
159
|
+
end
|
148
160
|
|
149
161
|
end
|
150
|
-
@threads.push(thr)
|
151
162
|
|
163
|
+
rescue Timeout::Error
|
164
|
+
EventQ.log(:error, "[#{self.class}] - Timeout occurred attempting to pop a message from the queue.")
|
152
165
|
end
|
153
166
|
|
154
|
-
|
155
|
-
@threads.each { |thr| thr.join }
|
156
|
-
end
|
167
|
+
channel.close
|
157
168
|
|
158
|
-
|
169
|
+
GC.start
|
159
170
|
|
171
|
+
#check if any message was received
|
172
|
+
if !received && !error
|
173
|
+
EventQ.log(:debug, "[#{self.class}] - No message received. Sleeping for #{@sleep} seconds")
|
174
|
+
#no message received so sleep before attempting to pop another message from the queue
|
175
|
+
sleep(@sleep)
|
176
|
+
end
|
160
177
|
end
|
161
178
|
|
162
179
|
def stop
|