estorm-message-processor 0.2.3 → 0.2.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +5 -1
- data/lib/estorm-message-processor/base.rb +8 -9
- data/lib/estorm-message-processor/consumer.rb +3 -1
- data/test/coverage/index.html +1 -1
- data/test/test_consumer.rb +1 -0
- data/test/test_single.rb +26 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 59894a7026a89b5051d9c38d91b287e83b33efd4
|
4
|
+
data.tar.gz: 8cee09cd6216eed0413476468e62b13fa7c685f2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0ff1bca8a78f3c8af4c98fb5b6c7bcf3a36441ceca7eb4096d6f72f9ce544b7547f29ec6275b485fd88320342b965930beb67ea8444877b432abb087b9632d20
|
7
|
+
data.tar.gz: 43627967020def843be31fce67df66e402ae5804bde7dadee8431e77f55fc1707d5e2b4fbd87c969b60c35c33ff44e35292ae3cca3e34c92427a2cf9e7a1e966
|
data/README.md
CHANGED
@@ -6,7 +6,11 @@ estorm-message-processor gem
|
|
6
6
|
============
|
7
7
|
|
8
8
|
|
9
|
-
Simple gem to use in rails apps for AMQP inclusion. Send a hash via AMQP and then have the message processor process the files. See the test pages
|
9
|
+
Simple gem to use in rails apps for AMQP inclusion. Send a hash via AMQP and then have the message processor process the files. See the test pages. They key use cases for this are
|
10
|
+
* When you want a back ground task to continually process messages (see _test_estorm.rb_ for examples)
|
11
|
+
* When you want to schedule a background task to periodically consume and process messages. (eg every 30 minutes perform the task see _test_single.rb_)
|
12
|
+
|
13
|
+
The second usage case allows you to use periodic jobs on heroku. Thus your costing is just for time taken to process all the messages. IN hte first case you need to pay for a dyno for a 24 hour period. The difference between the two usage patterns is a simple flag so it is convenient to start inexpensively and scale when needed.
|
10
14
|
|
11
15
|
Usage
|
12
16
|
=======
|
@@ -53,19 +53,17 @@ module EstormMessageProcessor
|
|
53
53
|
logger.info msg
|
54
54
|
count=0
|
55
55
|
# @channel.prefetch(1) # set quality of service to only delivery one message at a time....
|
56
|
-
msg_count,consumer_count = @consumer.queue_statistics # just to get the stats before entering hte queue
|
56
|
+
@msg_count,consumer_count = @consumer.queue_statistics # just to get the stats before entering hte queue
|
57
57
|
# @queue.subscribe(:block => config[:blocking]) do |delivery_info, properties, body|
|
58
|
-
@consumer.target(msg_count,config[:exit_when_done]) if config[:exit_when_done]
|
58
|
+
@consumer.target(@msg_count,config[:exit_when_done]) if config[:exit_when_done]
|
59
59
|
@consumer.on_delivery() do |delivery_info, metadata, payload|
|
60
60
|
@consumer.process_messages(delivery_info,metadata,payload)
|
61
|
-
# @consumer.channel.acknowledge(delivery_info.delivery_tag, false) if @consumer.channel!=nil && @consumer.channel.open?
|
62
61
|
msg= "ON DELIVERY: #{@consumer.count}: messages processed"
|
63
62
|
logger.info msg
|
64
63
|
@channel.close if @consumer.cancelled?
|
65
|
-
|
66
|
-
#msg_count,consumer_count = @consumer.queue_statistics # POSSIBLE RACE CONDITION
|
64
|
+
|
67
65
|
# @consumer.cancel if msg_count==0 && config[:exit_when_empty]
|
68
|
-
end
|
66
|
+
end
|
69
67
|
end
|
70
68
|
def queue_creation(config)
|
71
69
|
setup_bunny_communications(config[:url],config[:connecturlflag],config[:queuename])
|
@@ -74,20 +72,21 @@ module EstormMessageProcessor
|
|
74
72
|
|
75
73
|
@consumer.logger=logger
|
76
74
|
raise "consumer creation problem" if @consumer==nil
|
77
|
-
msg_count,consumer_count =@consumer.queue_statistics
|
78
75
|
queue_mgmt(config)
|
79
76
|
end
|
80
77
|
|
81
78
|
def start(config)
|
82
79
|
msg= "Connecting to bunny environment #{config.inspect}"
|
83
80
|
logger.info msg
|
84
|
-
queue_creation(config)
|
85
81
|
config[:exit_when_done]=false if config[:exit_when_done]==nil
|
82
|
+
queue_creation(config)
|
83
|
+
|
86
84
|
# the block flag shuts down the thread. the timeout values says whether to unsubscriber
|
87
85
|
#need to set ack to true to manage the qos parameter
|
88
86
|
# retval= @queue.subscribe_with(@consumer,:ack => true, :block => config[:blocking], :timeout => config[:timeout])
|
89
87
|
# retval= @queue.subscribe_with(@consumer,:ack => true, :block => config[:blocking])
|
90
|
-
retval=
|
88
|
+
retval ="[did not subscribe as msg count = 0]"
|
89
|
+
retval= @queue.subscribe_with(@consumer, :block => config[:blocking]) if !config[:exit_when_done] or @msg_count >0
|
91
90
|
# loop do
|
92
91
|
#should loop forever if blocking... otherwise needs a loop
|
93
92
|
# sleep 1
|
@@ -13,8 +13,10 @@ module EstormMessageProcessor
|
|
13
13
|
@mycount
|
14
14
|
end
|
15
15
|
@exit_flag=false
|
16
|
+
# this is a target to count messages and exit if needed
|
16
17
|
def target(count,flag)
|
17
|
-
|
18
|
+
msg = "-- Message Processor exit when complete flag set: target messages is #{count} flag is #{flag}"
|
19
|
+
logger.info msg
|
18
20
|
@exit_flag=flag
|
19
21
|
@exit_count=count-1
|
20
22
|
end
|
data/test/coverage/index.html
CHANGED
@@ -14,7 +14,7 @@
|
|
14
14
|
<img src="./assets/0.7.1/loading.gif" alt="loading"/>
|
15
15
|
</div>
|
16
16
|
<div id="wrapper" style="display:none;">
|
17
|
-
<div class="timestamp">Generated <abbr class="timeago" title="2013-10-
|
17
|
+
<div class="timestamp">Generated <abbr class="timeago" title="2013-10-18T19:42:06+08:00">2013-10-18T19:42:06+08:00</abbr></div>
|
18
18
|
<ul class="group_tabs"></ul>
|
19
19
|
|
20
20
|
<div id="content">
|
data/test/test_consumer.rb
CHANGED
@@ -99,6 +99,7 @@ class EstormConsumerProcessTest < Minitest::Test
|
|
99
99
|
@consumer.logger=@f.logger
|
100
100
|
assert @consumer.consumer_tag=config[:consumer_name]
|
101
101
|
mc,cc=@consumer.queue_statistics
|
102
|
+
puts "MESSAGE COUNT #{mc.inspect}"
|
102
103
|
assert mc!=nil, "mc should have vlue"
|
103
104
|
assert cc!=nil, "concsumer count should have value"
|
104
105
|
assert true, "should get here without a problem"
|
data/test/test_single.rb
CHANGED
@@ -86,4 +86,30 @@ class EstormMessageProcessTest < Minitest::Test
|
|
86
86
|
assert MessageFlag.testval==7, "should receive 7 message and set temp #{MessageFlag.testval}"
|
87
87
|
|
88
88
|
end
|
89
|
+
def test_processor_exits_when_queue_empty
|
90
|
+
puts "test several message"
|
91
|
+
assert MessageFlag.flag==false, "should be flase #{MessageFlag.inspect}"
|
92
|
+
config={:url => 'fakeurl',:connecturlflag=> false,:queuename => 'testEmptyqueueMessageExit', :blocking => true, :consumer_name => "test exit consumer", :exit_when_done => true}
|
93
|
+
# PRELOAD THE QUEUE WITH MESSAGES
|
94
|
+
bunnysender=EstormMessageProcessor::Client.new
|
95
|
+
conn,chan=bunnysender.setup_bunny(config[:url],config[:connnecturlflag])
|
96
|
+
assert conn!=nil, "connection shold be established"
|
97
|
+
assert chan!=nil, "connection shold be established"
|
98
|
+
chan.queue(config[:queuename]).purge
|
99
|
+
|
100
|
+
|
101
|
+
puts "after purging queue in test message"
|
102
|
+
@f.start(config)
|
103
|
+
# bunnysender.connection.close
|
104
|
+
puts " should get here this thread about to exit in tes_messag"
|
105
|
+
|
106
|
+
time=10
|
107
|
+
puts "sleeping #{time} seconds"
|
108
|
+
sleep time
|
109
|
+
|
110
|
+
sleep 1
|
111
|
+
|
112
|
+
assert true,"should get here..."
|
113
|
+
|
114
|
+
end
|
89
115
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: estorm-message-processor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Scott Sproule
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-10-
|
11
|
+
date: 2013-10-18 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: a gem to help rails app process AMQP queues for background jobs
|
14
14
|
email: scott.sproule@ficonab.com
|