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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2b81f8b2169e098058d7854e7aa8c485575d545f
4
- data.tar.gz: 1503e3b04071f9874f3412d6a5d40e4ee3c41245
3
+ metadata.gz: e6a52e4b1ac7f490d976dc431a158b41e795f23e
4
+ data.tar.gz: d66c939e9b7c6954e21e06dc5d02f85b6927867f
5
5
  SHA512:
6
- metadata.gz: d799962de1b19fca425f5e875339ea1c8de9fba92d3f012a42c92ba07113e38b8cc78595bc4cc262349ea654ffbe74f222bf910abb1aa8c885352d09bc35781c
7
- data.tar.gz: a8160bd65e5e878a7b2df3f04eba6f85e97bab2e7618bf6d9f23d482ce2765b3944c97d29e8722c35a99e30890c943f908b449d8651c19c2fdb5fa104e5ca14c
6
+ metadata.gz: a590b654b7d6f0d2a5e8fd9d08659e887233e0a2166280ee432ac26360bf3f5196c3c1ab37ab0d9cba15b40824fd4ec0c7c33d319d7bdbe125d6e837c099ba0e
7
+ data.tar.gz: 56db9ed1d5ae2cebec0151be6f04c22ceae6e325c5376523a5cd65bae01dc13d6b2ff1aacdde3d1ad00f7479f999b780b0a06a791c2cd8aaf5738d5090bf089e
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- estorm-message-processor (0.2.0)
4
+ estorm-message-processor (0.2.1)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
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[:timeout] value if you want the task to exit. (eg supposedly this is how long until no message is received for the consumer to exist the processing loop)
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
- setup_bunny_communications(config[:url],config[:connecturlflag],config[:queuename])
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
@@ -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-17T08:53:34+08:00">2013-10-17T08:53:34+08:00</abbr></div>
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", :timeout => 10 }
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=30
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.1
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.0.6
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