eventq_aws 1.2.2 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/eventq_aws/aws_queue_worker.rb +73 -56
- data/lib/eventq_aws/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: 61dd697f2cae3536df5c038b54f0711f10be98ae
|
4
|
+
data.tar.gz: 3b1ff6413378e960b6e07353b1e4c50ecbdb7604
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 992ded70af4c8627c41ccabcf0da5e29501dc94d8a17889a313a5dd92aa71dd9ed527893425c51a97cd3b7afb17730f826e3fdb6fb3bafca3c465f218f02b5fa
|
7
|
+
data.tar.gz: 3197bbcd72eaeefb0997c100200f65c4911b7ae83ffbcfde4a342fab72122ebe064cabb2d488d631ea03e83affb3a765614cb3fa5a04e113605f53a719e32b30
|
@@ -2,6 +2,8 @@ module EventQ
|
|
2
2
|
module Amazon
|
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
|
@@ -77,90 +79,105 @@ module EventQ
|
|
77
79
|
break
|
78
80
|
end
|
79
81
|
|
80
|
-
|
81
|
-
|
82
|
+
if ENV[PROFILE_MEMORY] != nil
|
83
|
+
require 'memory_profiler'
|
82
84
|
|
83
|
-
|
84
|
-
|
85
|
-
|
85
|
+
report = MemoryProfiler.report do
|
86
|
+
thread_process_iteration(client, manager, queue, block)
|
87
|
+
end
|
86
88
|
|
87
|
-
|
89
|
+
EventQ.log(:debug, report.pretty_print.to_s)
|
88
90
|
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
max_number_of_messages: 1,
|
93
|
-
wait_time_seconds: 1,
|
94
|
-
attribute_names: ['ApproximateReceiveCount']
|
95
|
-
})
|
91
|
+
else
|
92
|
+
thread_process_iteration(client, manager, queue, block)
|
93
|
+
end
|
96
94
|
|
97
|
-
|
98
|
-
if response.messages.length > 0
|
95
|
+
end
|
99
96
|
|
100
|
-
|
101
|
-
|
97
|
+
end
|
98
|
+
@threads.push(thr)
|
102
99
|
|
103
|
-
|
104
|
-
payload = JSON.load(msg.body)
|
105
|
-
message = deserialize_message(payload["Message"])
|
100
|
+
end
|
106
101
|
|
107
|
-
|
102
|
+
if options.key?(:wait) && options[:wait] == true
|
103
|
+
@threads.each { |thr| thr.join }
|
104
|
+
end
|
108
105
|
|
109
|
-
|
106
|
+
end
|
110
107
|
|
111
|
-
|
112
|
-
|
108
|
+
def thread_process_iteration(client, manager, queue, block)
|
109
|
+
#get the queue
|
110
|
+
q = manager.get_queue(queue)
|
113
111
|
|
114
|
-
|
112
|
+
received = false
|
113
|
+
error = false
|
114
|
+
abort = false
|
115
115
|
|
116
|
-
|
117
|
-
abort = true
|
118
|
-
EventQ.log(:info, "[#{self.class}] - Message aborted.")
|
119
|
-
else
|
120
|
-
#accept the message as processed
|
121
|
-
client.sqs.delete_message({ queue_url: q, receipt_handle: msg.receipt_handle })
|
122
|
-
EventQ.log(:info, "[#{self.class}] - Message acknowledged.")
|
123
|
-
received = true
|
124
|
-
end
|
116
|
+
begin
|
125
117
|
|
126
|
-
|
127
|
-
|
118
|
+
#request a message from the queue
|
119
|
+
response = client.sqs.receive_message({
|
120
|
+
queue_url: q,
|
121
|
+
max_number_of_messages: 1,
|
122
|
+
wait_time_seconds: 1,
|
123
|
+
attribute_names: ['ApproximateReceiveCount']
|
124
|
+
})
|
128
125
|
|
129
|
-
|
126
|
+
#check that a message was received
|
127
|
+
if response.messages.length > 0
|
130
128
|
|
131
|
-
|
129
|
+
msg = response.messages[0]
|
130
|
+
retry_attempts = msg.attributes['ApproximateReceiveCount'].to_i - 1
|
132
131
|
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
end
|
132
|
+
#deserialize the message payload
|
133
|
+
payload = JSON.load(msg.body)
|
134
|
+
message = deserialize_message(payload["Message"])
|
137
135
|
|
138
|
-
|
136
|
+
message_args = EventQ::MessageArgs.new(message.type, retry_attempts)
|
139
137
|
|
140
|
-
|
141
|
-
|
142
|
-
|
138
|
+
EventQ.log(:debug, "[#{self.class}] - Message received. Retry Attempts: #{retry_attempts}")
|
139
|
+
|
140
|
+
#begin worker block for queue message
|
141
|
+
begin
|
143
142
|
|
144
|
-
|
143
|
+
block.call(message.content, message_args)
|
145
144
|
|
146
|
-
|
147
|
-
|
148
|
-
EventQ.log(:
|
149
|
-
|
150
|
-
|
145
|
+
if message_args.abort == true
|
146
|
+
abort = true
|
147
|
+
EventQ.log(:info, "[#{self.class}] - Message aborted.")
|
148
|
+
else
|
149
|
+
#accept the message as processed
|
150
|
+
client.sqs.delete_message({ queue_url: q, receipt_handle: msg.receipt_handle })
|
151
|
+
EventQ.log(:info, "[#{self.class}] - Message acknowledged.")
|
152
|
+
received = true
|
151
153
|
end
|
152
154
|
|
155
|
+
rescue => e
|
156
|
+
EventQ.log(:error, "[#{self.class}] - An unhandled error happened while attempting to process a queue message. Error: #{e}")
|
157
|
+
|
158
|
+
error = true
|
159
|
+
|
160
|
+
end
|
161
|
+
|
162
|
+
if abort || error
|
163
|
+
EventQ.log(:info, "[#{self.class}] - Message rejected.")
|
164
|
+
reject_message(queue, client, msg, q, retry_attempts)
|
153
165
|
end
|
154
166
|
|
155
167
|
end
|
156
|
-
@threads.push(thr)
|
157
168
|
|
169
|
+
rescue => e
|
170
|
+
EventQ.log(:error, "[#{self.class}] - An error occurred attempting to retrieve a message from the queue. Error: #{e}")
|
158
171
|
end
|
159
172
|
|
160
|
-
|
161
|
-
@threads.each { |thr| thr.join }
|
162
|
-
end
|
173
|
+
GC.start
|
163
174
|
|
175
|
+
#check if any message was received
|
176
|
+
if !received && !error
|
177
|
+
EventQ.log(:debug, "[#{self.class}] - No message received. Sleeping for #{@sleep} seconds")
|
178
|
+
#no message received so sleep before attempting to pop another message from the queue
|
179
|
+
sleep(@sleep)
|
180
|
+
end
|
164
181
|
end
|
165
182
|
|
166
183
|
def stop
|
data/lib/eventq_aws/version.rb
CHANGED