eventq_aws 1.2.2 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fded176e3324667c0120ab7b96e99413fc9a93b6
4
- data.tar.gz: 436eab4fb1a3ba5e0ae8a33c5f6639fe5e80495f
3
+ metadata.gz: 61dd697f2cae3536df5c038b54f0711f10be98ae
4
+ data.tar.gz: 3b1ff6413378e960b6e07353b1e4c50ecbdb7604
5
5
  SHA512:
6
- metadata.gz: 98aa288d2595bce084f5fc25c4c0c5bcaafa11703062309ed3aff790de78d78c13ceff8036c897e00ce89ac5e72fa4ecf7d8279c4b3303bb3208a338d1d619b8
7
- data.tar.gz: e0cc37a6ba4ecd312bc6d39b118b1d2a6aac4c7050143be16aeac172af37d83073064fa49b744bacde44f5eeea0ffe79ba9ff26d4464342765a8582371003dd5
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
- #get the queue
81
- q = manager.get_queue(queue)
82
+ if ENV[PROFILE_MEMORY] != nil
83
+ require 'memory_profiler'
82
84
 
83
- received = false
84
- error = false
85
- abort = false
85
+ report = MemoryProfiler.report do
86
+ thread_process_iteration(client, manager, queue, block)
87
+ end
86
88
 
87
- begin
89
+ EventQ.log(:debug, report.pretty_print.to_s)
88
90
 
89
- #request a message from the queue
90
- response = client.sqs.receive_message({
91
- queue_url: q,
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
- #check that a message was received
98
- if response.messages.length > 0
95
+ end
99
96
 
100
- msg = response.messages[0]
101
- retry_attempts = msg.attributes['ApproximateReceiveCount'].to_i - 1
97
+ end
98
+ @threads.push(thr)
102
99
 
103
- #deserialize the message payload
104
- payload = JSON.load(msg.body)
105
- message = deserialize_message(payload["Message"])
100
+ end
106
101
 
107
- message_args = EventQ::MessageArgs.new(message.type, retry_attempts)
102
+ if options.key?(:wait) && options[:wait] == true
103
+ @threads.each { |thr| thr.join }
104
+ end
108
105
 
109
- EventQ.log(:debug, "[#{self.class}] - Message received. Retry Attempts: #{retry_attempts}")
106
+ end
110
107
 
111
- #begin worker block for queue message
112
- begin
108
+ def thread_process_iteration(client, manager, queue, block)
109
+ #get the queue
110
+ q = manager.get_queue(queue)
113
111
 
114
- block.call(message.content, message_args)
112
+ received = false
113
+ error = false
114
+ abort = false
115
115
 
116
- if message_args.abort == true
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
- rescue => e
127
- EventQ.log(:error, "[#{self.class}] - An unhandled error happened while attempting to process a queue message. Error: #{e}")
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
- error = true
126
+ #check that a message was received
127
+ if response.messages.length > 0
130
128
 
131
- end
129
+ msg = response.messages[0]
130
+ retry_attempts = msg.attributes['ApproximateReceiveCount'].to_i - 1
132
131
 
133
- if abort || error
134
- EventQ.log(:info, "[#{self.class}] - Message rejected.")
135
- reject_message(queue, client, msg, q, retry_attempts)
136
- end
132
+ #deserialize the message payload
133
+ payload = JSON.load(msg.body)
134
+ message = deserialize_message(payload["Message"])
137
135
 
138
- end
136
+ message_args = EventQ::MessageArgs.new(message.type, retry_attempts)
139
137
 
140
- rescue => e
141
- EventQ.log(:error, "[#{self.class}] - An error occurred attempting to retrieve a message from the queue. Error: #{e}")
142
- end
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
- GC.start
143
+ block.call(message.content, message_args)
145
144
 
146
- #check if any message was received
147
- if !received && !error
148
- EventQ.log(:debug, "[#{self.class}] - No message received. Sleeping for #{@sleep} seconds")
149
- #no message received so sleep before attempting to pop another message from the queue
150
- sleep(@sleep)
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
- if options.key?(:wait) && options[:wait] == true
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
@@ -1,5 +1,5 @@
1
1
  module EventQ
2
2
  module Amazon
3
- VERSION = "1.2.2"
3
+ VERSION = "1.3.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: eventq_aws
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.2
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - vaughanbrittonsage