estorm-message-processor 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +1 -1
- data/lib/estorm-message-processor/base.rb +15 -11
- data/lib/estorm-message-processor/consumer.rb +8 -1
- data/test/coverage/index.html +1 -1
- data/test/test_single.rb +2 -2
- 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: e6a52e4b1ac7f490d976dc431a158b41e795f23e
|
4
|
+
data.tar.gz: d66c939e9b7c6954e21e06dc5d02f85b6927867f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a590b654b7d6f0d2a5e8fd9d08659e887233e0a2166280ee432ac26360bf3f5196c3c1ab37ab0d9cba15b40824fd4ec0c7c33d319d7bdbe125d6e837c099ba0e
|
7
|
+
data.tar.gz: 56db9ed1d5ae2cebec0151be6f04c22ceae6e325c5376523a5cd65bae01dc13d6b2ff1aacdde3d1ad00f7479f999b780b0a06a791c2cd8aaf5738d5090bf089e
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -47,6 +47,6 @@ Use the client to send a message to the delegate processor (background task). No
|
|
47
47
|
bunny.bunny_send(AMQPURL,Rails.env.production?,CONTACT_MESSAGE,cmdhash)
|
48
48
|
end
|
49
49
|
|
50
|
-
# set the config[:
|
50
|
+
# set the config[:exit_when_done] => true value if you want the task to exit.
|
51
51
|
This is useful if you have a back ground task that you want to run occasionally and just process the messages and exit. For example on heroku you can schedule a job to run every hour and it will process the messages and exit. This will keep the costs down for the background task on heroku. (Of course you need to ensure that the job time is shorter than the heroku scheduler time)
|
52
52
|
|
@@ -55,30 +55,33 @@ module EstormMessageProcessor
|
|
55
55
|
# @channel.prefetch(1) # set quality of service to only delivery one message at a time....
|
56
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
59
|
@consumer.on_delivery() do |delivery_info, metadata, payload|
|
59
60
|
@consumer.process_messages(delivery_info,metadata,payload)
|
60
61
|
# @consumer.channel.acknowledge(delivery_info.delivery_tag, false) if @consumer.channel!=nil && @consumer.channel.open?
|
61
62
|
msg= "ON DELIVERY: #{@consumer.count}: messages processed"
|
62
63
|
logger.info msg
|
63
|
-
|
64
|
+
@channel.close if @consumer.cancelled?
|
64
65
|
# ack the message to get the next message
|
65
66
|
#msg_count,consumer_count = @consumer.queue_statistics # POSSIBLE RACE CONDITION
|
66
67
|
# @consumer.cancel if msg_count==0 && config[:exit_when_empty]
|
67
68
|
end
|
68
69
|
end
|
69
|
-
|
70
|
+
def queue_creation(config)
|
71
|
+
setup_bunny_communications(config[:url],config[:connecturlflag],config[:queuename])
|
72
|
+
#@consumer=EstormMessageProcessor::Consumer.new(@channel, @queue, config[:consumer_name], true, false, config)
|
73
|
+
@consumer=EstormMessageProcessor::Consumer.new(@channel, @queue)
|
74
|
+
|
75
|
+
@consumer.logger=logger
|
76
|
+
raise "consumer creation problem" if @consumer==nil
|
77
|
+
msg_count,consumer_count =@consumer.queue_statistics
|
78
|
+
queue_mgmt(config)
|
79
|
+
end
|
70
80
|
|
71
81
|
def start(config)
|
72
82
|
msg= "Connecting to bunny environment #{config.inspect}"
|
73
83
|
logger.info msg
|
74
|
-
|
75
|
-
#@consumer=EstormMessageProcessor::Consumer.new(@channel, @queue, config[:consumer_name], true, false, config)
|
76
|
-
@consumer=EstormMessageProcessor::Consumer.new(@channel, @queue)
|
77
|
-
|
78
|
-
@consumer.logger=logger
|
79
|
-
raise "consumer creation problem" if @consumer==nil
|
80
|
-
msg_count,consumer_count =@consumer.queue_statistics
|
81
|
-
queue_mgmt(config)
|
84
|
+
queue_creation(config)
|
82
85
|
# the block flag shuts down the thread. the timeout values says whether to unsubscriber
|
83
86
|
#need to set ack to true to manage the qos parameter
|
84
87
|
# retval= @queue.subscribe_with(@consumer,:ack => true, :block => config[:blocking], :timeout => config[:timeout])
|
@@ -93,7 +96,8 @@ module EstormMessageProcessor
|
|
93
96
|
tear_down_bunny
|
94
97
|
|
95
98
|
end
|
96
|
-
|
99
|
+
|
100
|
+
|
97
101
|
|
98
102
|
|
99
103
|
|
@@ -12,12 +12,19 @@ module EstormMessageProcessor
|
|
12
12
|
@mycount=0 if @mycount==nil
|
13
13
|
@mycount
|
14
14
|
end
|
15
|
+
@exit_flag=false
|
16
|
+
def target(count,flag)
|
17
|
+
puts "target is #{count} flag is #{flag}"
|
18
|
+
@exit_flag=flag
|
19
|
+
@exit_count=count-1
|
20
|
+
end
|
15
21
|
def increment
|
16
22
|
@mycount=self.count+1
|
23
|
+
@cancelled=true if @exit_flag && @exit_count < @mycount
|
24
|
+
@mycount
|
17
25
|
end
|
18
26
|
|
19
27
|
def handle_cancellation(_)
|
20
|
-
|
21
28
|
msg="consumer cancellation queue called"
|
22
29
|
@logger.info msg
|
23
30
|
@cancelled = true
|
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-17T21:16:46+08:00">2013-10-17T21:16:46+08:00</abbr></div>
|
18
18
|
<ul class="group_tabs"></ul>
|
19
19
|
|
20
20
|
<div id="content">
|
data/test/test_single.rb
CHANGED
@@ -57,7 +57,7 @@ class EstormMessageProcessTest < Minitest::Test
|
|
57
57
|
def test_processor_exits_after_queue_empty
|
58
58
|
puts "test several message"
|
59
59
|
assert MessageFlag.flag==false, "should be flase #{MessageFlag.inspect}"
|
60
|
-
config={:url => 'fakeurl',:connecturlflag=> false,:queuename => 'testqueueMessageExit', :blocking => true, :consumer_name => "test exit consumer",
|
60
|
+
config={:url => 'fakeurl',:connecturlflag=> false,:queuename => 'testqueueMessageExit', :blocking => true, :consumer_name => "test exit consumer", :exit_when_done => true}
|
61
61
|
# PRELOAD THE QUEUE WITH MESSAGES
|
62
62
|
bunnysender=EstormMessageProcessor::Client.new
|
63
63
|
bunnysender.setup_bunny(config[:url],config[:connnecturlflag])
|
@@ -77,7 +77,7 @@ class EstormMessageProcessTest < Minitest::Test
|
|
77
77
|
# bunnysender.connection.close
|
78
78
|
puts " should get here this thread about to exit in tes_messag"
|
79
79
|
|
80
|
-
time=
|
80
|
+
time=10
|
81
81
|
puts "sleeping #{time} seconds"
|
82
82
|
sleep time
|
83
83
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
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.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Scott Sproule
|
@@ -88,7 +88,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
88
88
|
version: 1.3.4
|
89
89
|
requirements: []
|
90
90
|
rubyforge_project: estorm-message-processor
|
91
|
-
rubygems_version: 2.
|
91
|
+
rubygems_version: 2.1.7
|
92
92
|
signing_key:
|
93
93
|
specification_version: 4
|
94
94
|
summary: Using a AMQP to process a queue. Primarily support for scripting
|