estorm-message-processor 0.2.4 → 0.2.5
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 +5 -2
- data/lib/estorm-message-processor/base.rb +1 -1
- data/test/coverage/index.html +1 -1
- data/test/test_prefetch.rb +115 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7f4fcf267318b0b13f7e73b3f0fe742187c9fc38
|
4
|
+
data.tar.gz: fd93f6f378fd7f0bb1e7b278bb4ce714f7b6ab7f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2eaffe6631ba5e6c3e2ef75822e4a38e5b55359b06236162c8a9bbf468db51411d229c37f8c1cc4becc403651cc68ef79bde5ff59ce3ad297741be60150ac7c7
|
7
|
+
data.tar.gz: 26d54239561ba4154fac37f6a673fd2dcd4d2e5382959a1f4e9cd510ab55b7586d39c9806fb8f280f78a2f552883057f54965e82a59c5fbd93fca72921c463ff
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -31,7 +31,7 @@ This is the callback processor in the consumer. Just define this in your script
|
|
31
31
|
|
32
32
|
# Start the Message Processor
|
33
33
|
begin
|
34
|
-
config={:url => AMQPURL,:connecturlflag=> Rails.env.production? ,:queuename => CONTACT_MESSAGE, :blocking => true, :
|
34
|
+
config={:url => AMQPURL,:connecturlflag=> Rails.env.production? ,:queuename => CONTACT_MESSAGE, :blocking => true, :consumer_name => "test consumer"}
|
35
35
|
#puts "Starting SMS Gateway. Please check the log at #{LOGFILE}"
|
36
36
|
EstormMessageProcessor::Base.logger=Logger.new(STDOUT)
|
37
37
|
puts "Starting Bunny Contact Processor on #{config.inspect} "
|
@@ -42,7 +42,7 @@ This is the callback processor in the consumer. Just define this in your script
|
|
42
42
|
end
|
43
43
|
|
44
44
|
# send a message using the client
|
45
|
-
Use the client to send a message to the delegate processor (background task). Note the command set to the callback processor above. You can also see multiple sends in the test files.
|
45
|
+
Use the client to send a message to the delegate processor (background task). Note the command value set in the hash to the callback processor above. You can also see multiple sends in the test files. The hash can contain anything as long as the command is set to a delegate name. (Where the delegate name is built by joining delegate_ and the command name delegate_sendtemplates in this example)
|
46
46
|
|
47
47
|
def bunny_send
|
48
48
|
cmdhash={'command'=>'sendtemplates', 'promotion'=>self.id.to_s}
|
@@ -54,3 +54,6 @@ Use the client to send a message to the delegate processor (background task). No
|
|
54
54
|
# set the config[:exit_when_done] => true value if you want the task to exit.
|
55
55
|
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)
|
56
56
|
|
57
|
+
# :prefetch_one => true
|
58
|
+
Use this if you want the message_processor to only grab one message a time. This way you can easily spin up several message processors
|
59
|
+
|
@@ -52,7 +52,7 @@ module EstormMessageProcessor
|
|
52
52
|
msg= "[*] Waiting for messages in #{@queue.name}. blocking is #{config[:blocking]}"
|
53
53
|
logger.info msg
|
54
54
|
count=0
|
55
|
-
|
55
|
+
@channel.prefetch(1) if config[:prefetch_one] # 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
58
|
@consumer.target(@msg_count,config[:exit_when_done]) if config[:exit_when_done]
|
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-
|
17
|
+
<div class="timestamp">Generated <abbr class="timeago" title="2013-11-06T15:42:48+08:00">2013-11-06T15:42:48+08:00</abbr></div>
|
18
18
|
<ul class="group_tabs"></ul>
|
19
19
|
|
20
20
|
<div id="content">
|
@@ -0,0 +1,115 @@
|
|
1
|
+
puts File.dirname(__FILE__)
|
2
|
+
require 'yaml'
|
3
|
+
require File.dirname(__FILE__) + '/test_helper.rb'
|
4
|
+
class MessageFlag
|
5
|
+
|
6
|
+
def self.reset
|
7
|
+
puts "reset called"
|
8
|
+
@@flag=false
|
9
|
+
@@test=0
|
10
|
+
end
|
11
|
+
def self.setflag
|
12
|
+
puts "set flag called"
|
13
|
+
@@flag=true
|
14
|
+
end
|
15
|
+
def self.flag
|
16
|
+
|
17
|
+
@@flag
|
18
|
+
end
|
19
|
+
def self.testval
|
20
|
+
@@test
|
21
|
+
end
|
22
|
+
def self.increment
|
23
|
+
puts "increment called"
|
24
|
+
@@test=MessageFlag.testval+1
|
25
|
+
end
|
26
|
+
end
|
27
|
+
class EstormMessageProcessor::Consumer
|
28
|
+
|
29
|
+
def delegate_testdelegate3(cmdhash)
|
30
|
+
msg= "DELEGATE CALLED: test delegate 3 received #{cmdhash.inspect}"
|
31
|
+
logger.info msg
|
32
|
+
puts msg
|
33
|
+
MessageFlag.increment
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
class EstormMessageProcessTest < Minitest::Test
|
38
|
+
|
39
|
+
def setup
|
40
|
+
EstormMessageProcessor::Base.logger=Logger.new(STDERR)
|
41
|
+
@f=EstormMessageProcessor::Base.new
|
42
|
+
@@temp=false
|
43
|
+
MessageFlag.reset
|
44
|
+
puts "after setup"
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_basic
|
48
|
+
assert @f!=nil, "should be valid"
|
49
|
+
assert !@@temp, "should be false"
|
50
|
+
assert !MessageFlag.flag, "should be false"
|
51
|
+
MessageFlag.setflag
|
52
|
+
assert MessageFlag.flag, "should be true"
|
53
|
+
assert MessageFlag.testval==0, "should be 0"
|
54
|
+
MessageFlag.increment
|
55
|
+
assert MessageFlag.flag, "should be false"
|
56
|
+
end
|
57
|
+
def test_processor_exits_after_queue_empty
|
58
|
+
puts "test several message"
|
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", :exit_when_done => true, :prefetch_one => true}
|
61
|
+
# PRELOAD THE QUEUE WITH MESSAGES
|
62
|
+
bunnysender=EstormMessageProcessor::Client.new
|
63
|
+
bunnysender.setup_bunny(config[:url],config[:connnecturlflag])
|
64
|
+
|
65
|
+
cmdhash={'command'=>'testdelegate3', 'temp'=>'serveral messages'}
|
66
|
+
puts "----> to system [x] sending #{cmdhash.inspect}"
|
67
|
+
|
68
|
+
1.upto(7) { |i|
|
69
|
+
|
70
|
+
cmdhash['temp']="mesage #{i}"
|
71
|
+
bunnysender.bunny_send_no_close(config[:queuename],cmdhash)
|
72
|
+
puts "after bunny send test_message: #{cmdhash['temp']}"
|
73
|
+
}
|
74
|
+
|
75
|
+
puts "after client in test message"
|
76
|
+
@f.start(config)
|
77
|
+
# bunnysender.connection.close
|
78
|
+
puts " should get here this thread about to exit in tes_messag"
|
79
|
+
|
80
|
+
time=10
|
81
|
+
puts "sleeping #{time} seconds"
|
82
|
+
sleep time
|
83
|
+
|
84
|
+
sleep 1
|
85
|
+
|
86
|
+
assert MessageFlag.testval==7, "should receive 7 message and set temp #{MessageFlag.testval}"
|
87
|
+
|
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, :prefetch_one => 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
|
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.5
|
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-
|
11
|
+
date: 2013-11-06 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
|
@@ -64,6 +64,7 @@ files:
|
|
64
64
|
- test/test_consumer.rb
|
65
65
|
- test/test_estorm.rb
|
66
66
|
- test/test_helper.rb
|
67
|
+
- test/test_prefetch.rb
|
67
68
|
- test/test_single.rb
|
68
69
|
- Gemfile
|
69
70
|
- Gemfile.lock
|