eventq_rabbitmq 1.6.20 → 1.7.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ffa92e29bdbb46174ff094aed246daf2e2583bf2
4
- data.tar.gz: 3288a193efc8ac49bcf3fdf88778b7de48d88e60
3
+ metadata.gz: e5d18c5f1558513c4230028b4551794ed95f1b82
4
+ data.tar.gz: 219e41df27fe185358b86db4928b10b306e7aab1
5
5
  SHA512:
6
- metadata.gz: 3100086d3bf2a228b7783ca62e652534f6d2c3533a235c40cc6847dd9499c9d39c693e1ef94fa809af59102af46cb4bf57133076525b965b01e80967dd9beb87
7
- data.tar.gz: a09da0f86ddd2f134c118ee33ee41aad1227cfb8c5511ff4090a97c2640cecb016aebc91369deb7dd7aaee9a6e263f32c45febe3ba52d44bcf2df6788cab564b
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
- channel = connection.create_channel
83
+ if ENV[PROFILE_MEMORY] != nil
84
+ require 'memory_profiler'
82
85
 
83
- #get the queue
84
- q = manager.get_queue(channel, queue)
85
- retry_exchange = manager.get_retry_exchange(channel, queue)
86
+ report = MemoryProfiler.report do
87
+ thread_process_iteration(connection, manager, queue, block)
88
+ end
86
89
 
87
- received = false
88
- error = false
89
- abort = false
90
+ EventQ.log(:debug, report.pretty_print.to_s)
90
91
 
91
- begin
92
- delivery_info, properties, payload = q.pop(:manual_ack => true, :block => true)
92
+ else
93
+ thread_process_iteration(connection, manager, queue, block)
94
+ end
93
95
 
94
- #check that message was received
95
- if payload != nil
96
+ end
96
97
 
97
- message = deserialize_message(payload)
98
+ connection.close
98
99
 
99
- EventQ.log(:debug, "[#{self.class}] - Message received. Retry Attempts: #{message.retry_attempts}")
100
+ end
101
+ @threads.push(thr)
100
102
 
101
- message_args = EventQ::MessageArgs.new(message.type, message.retry_attempts)
103
+ end
102
104
 
103
- #begin worker block for queue message
104
- begin
105
- block.call(message.content, message_args)
105
+ if options.key?(:wait) && options[:wait] == true
106
+ @threads.each { |thr| thr.join }
107
+ end
106
108
 
107
- if message_args.abort == true
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
- rescue => e
118
- EventQ.log(:error, "[#{self.class}] - An unhandled error happened attempting to process a queue message. Error: #{e}")
111
+ end
119
112
 
120
- error = true
113
+ def thread_process_iteration(connection, manager, queue, block)
114
+ channel = connection.create_channel
121
115
 
122
- end
116
+ #get the queue
117
+ q = manager.get_queue(channel, queue)
118
+ retry_exchange = manager.get_retry_exchange(channel, queue)
123
119
 
124
- if error || abort
125
- reject_message(channel, message, delivery_info, retry_exchange, queue)
126
- end
120
+ received = false
121
+ error = false
122
+ abort = false
127
123
 
128
- end
124
+ begin
125
+ delivery_info, properties, payload = q.pop(:manual_ack => true, :block => true)
129
126
 
130
- rescue Timeout::Error
131
- EventQ.log(:error, "[#{self.class}] - Timeout occurred attempting to pop a message from the queue.")
132
- end
127
+ #check that message was received
128
+ if payload != nil
129
+
130
+ message = deserialize_message(payload)
133
131
 
134
- channel.close
132
+ EventQ.log(:debug, "[#{self.class}] - Message received. Retry Attempts: #{message.retry_attempts}")
135
133
 
136
- GC.start
134
+ message_args = EventQ::MessageArgs.new(message.type, message.retry_attempts)
137
135
 
138
- #check if any message was received
139
- if !received && !error
140
- EventQ.log(:debug, "[#{self.class}] - No message received. Sleeping for #{@sleep} seconds")
141
- #no message received so sleep before attempting to pop another message from the queue
142
- sleep(@sleep)
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
- connection.close
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
- if options.key?(:wait) && options[:wait] == true
155
- @threads.each { |thr| thr.join }
156
- end
167
+ channel.close
157
168
 
158
- return true
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
@@ -1,3 +1,3 @@
1
1
  module EventqRabbitmq
2
- VERSION = "1.6.20"
2
+ VERSION = "1.7.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: eventq_rabbitmq
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.20
4
+ version: 1.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - vaughanbrittonsage