rservicebus2 0.0.1 → 0.0.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: 6390a6216fea31b5315a309af0f998af347c539a
4
- data.tar.gz: 50415a26cf33df5771b1072d7d263a7ce44e4b36
3
+ metadata.gz: af6224237bfbbe009d831bb7b31479fdea298c2a
4
+ data.tar.gz: f51e1bcd024999a267dbecdafb39ecc13c41e22e
5
5
  SHA512:
6
- metadata.gz: db4ba7b7a200ace966ea8edf6a6f2a00496e34096964acf35c09c0156fd4e0f7f1839669b0be42acc720ba0a763ebc99bcf511a8b61acdf12ab1145b7dace7ee
7
- data.tar.gz: 0529c38bae3eaa9f024ac54d2c1c4c09a7a665d571f3dd4fef19f61175fac9acbf69e06e2b4cd5cabb32af485f3fcbc154a8bda6926a9909a41fb2afd4f52299
6
+ metadata.gz: 239da2f85596cf0778b3c14dd555ba7e5827bab4f162242119d426aa664274cddf2894845acbe30c9910eab3442d236d32a34adf7d533bf1bec6cada55b695fb
7
+ data.tar.gz: d542ad8d463be94176ad3e776d23c5253e2cced5b9afd55f29be3557f7081f9edff6ce490f2ad4ad3c3557d9eded598160bf3cf47be93eeeb2853f8af21a3e46
@@ -4,111 +4,111 @@ require 'yaml'
4
4
  require 'beanstalk-client'
5
5
  require 'rservicebus'
6
6
 
7
- def returnMsg( beanstalk, job, request_nbr )
8
- firstMatch = 'ruby/object:'
9
-
10
- payload = job.body
11
-
12
- firstIndex = payload.index( firstMatch )
13
- startIndex = payload.index( firstMatch, firstIndex + 1 ) + firstMatch.length
14
-
15
- msgName = payload.match( '(\w*)', startIndex )[1]
16
-
17
- msg = YAML::load(payload)
18
- if msg.lastErrorString.nil? then
19
- puts "*** Requested msg, #{request_nbr}, does not have a sourceQueue to which it can be returned"
20
- puts '*** Only errored msgs can be Returned'
21
- puts '*** Generally, msgs would not be manually moved between queues'
22
- puts '*** If you do need to, try'
23
- puts '*** beanstalk-admin-dump <source queue name> | beanstalk-admin-load <destination queue name>'
24
-
25
- job.release
26
- return
27
- end
28
- queueName = msg.lastErrorSourceQueue
29
- puts '#' + "#{request_nbr.to_s}: #{msgName} to #{queueName}"
30
-
31
- beanstalk.use( queueName )
32
- beanstalk.put( payload )
33
-
34
- job.delete
35
- end
7
+ def return_msg(beanstalk, job, request_nbr)
8
+ first_match = 'ruby/object:'
9
+ payload = job.body
10
+
11
+ first_index = payload.index(first_match)
12
+ start_index = payload.index(first_match, first_index + 1) + first_match.length
13
+
14
+ msg_name = payload.match('(\w*)', start_index)[1]
15
+
16
+ msg = YAML.load(payload)
17
+ if msg.last_error_string.nil?
18
+ puts "*** Requested msg, #{request_nbr}, does not have a sourceQueue to
19
+ which it can be returned"
20
+ puts '*** Only errored msgs can be Returned'
21
+ puts '*** Generally, msgs would not be manually moved between queues'
22
+ puts '*** If you do need to, try'
23
+ puts '*** beanstalk-admin-dump <source queue name> | beanstalk-admin-load
24
+ <destination queue name>'
25
+
26
+ job.release
27
+ return
28
+ end
36
29
 
30
+ queue_name = msg.last_error_source_queue
31
+ puts '#' + "#{request_nbr}: #{msg_name} to #{queue_name}"
37
32
 
38
- index=nil
39
- if ARGV.length == 0 then
40
- queueName = 'error'
41
- elsif ARGV.length == 1 then
42
- queueName = ARGV[0]
43
- elsif ARGV.length == 2 then
44
- queueName = ARGV[0]
45
- index = ARGV[1].to_i
33
+ beanstalk.use(queue_name)
34
+ beanstalk.put(payload)
35
+
36
+ job.delete
37
+ end
38
+
39
+ index = nil
40
+ if ARGV.length == 0
41
+ queue_name = 'error'
42
+ elsif ARGV.length == 1
43
+ queue_name = ARGV[0]
44
+ elsif ARGV.length == 2
45
+ queue_name = ARGV[0]
46
+ index = ARGV[1].to_i
46
47
  else
47
- abort('Usage: ReturnMessagesToSourceQueue [queue name] [index]')
48
+ abort('Usage: ReturnMessagesToSourceQueue [queue name] [index]')
48
49
  end
49
50
 
50
51
  begin
51
- host = 'localhost:11300'
52
- beanstalk = Beanstalk::Pool.new([host])
53
-
54
- tubes = beanstalk.list_tubes[host]
55
- unless tubes.include?(queueName) then
56
- abort("Nothing waiting on the Beanstalk queue, #{queueName}")
52
+ host = 'localhost:11300'
53
+ beanstalk = Beanstalk::Pool.new([host])
54
+
55
+ tubes = beanstalk.list_tubes[host]
56
+ abort("Nothing waiting on the Beanstalk queue, #{queue_name}") unless
57
+ tubes.include?(queue_name)
58
+
59
+ tube_stats = beanstalk.stats_tube(queue_name)
60
+ number_of_messages = tube_stats['current-jobs-ready']
61
+ if index.nil?
62
+ puts
63
+ puts "Attempting to return #{number_of_messages} to their source queue"
64
+ puts
65
+
66
+ begin
67
+ beanstalk.watch(queue_name)
68
+ 1.upto(number_of_messages) do |request_nbr|
69
+ job = beanstalk.reserve 1
70
+
71
+ return_msg( beanstalk, job, request_nbr )
72
+ end
73
+ rescue StandardError => e
74
+ if e.message == 'TIMED_OUT'
75
+ else
76
+ raise
77
+ end
57
78
  end
58
-
59
- tubeStats = beanstalk.stats_tube(queueName)
60
- number_of_messages = tubeStats['current-jobs-ready']
61
- if index.nil? then
62
- puts
63
- puts "Attempting to return #{number_of_messages} to their source queue"
64
- puts
65
-
66
- begin
67
- beanstalk.watch(queueName)
68
- 1.upto(number_of_messages) do |request_nbr|
69
- job = beanstalk.reserve 1
70
-
71
- returnMsg( beanstalk, job, request_nbr )
72
- end
73
- rescue Exception => e
74
- if e.message == 'TIMED_OUT' then
75
- else
76
- raise
77
- end
78
- end
79
- else
80
- if index > number_of_messages then
81
- puts "*** Requested msg, #{index}, is greater than the number of msgs in the queue, #{number_of_messages}"
82
- puts '*** Try a smaller index, or remove the index number to return all msgs'
83
- abort();
84
- end
85
-
86
- puts
87
- puts "Attempting to msg number, #{index} to it's source queue"
88
- puts
89
-
90
- begin
91
- beanstalk.watch(queueName)
92
- jobList = Array.new
93
- 1.upto(index-1) do |request_nbr|
94
- job = beanstalk.reserve 1
95
- jobList << job
96
- end
97
- job = beanstalk.reserve 1
98
- returnMsg( beanstalk, job, index )
99
-
100
- jobList.each do |job|
101
- job.release
102
- end
103
-
104
- rescue Exception => e
105
- if e.message == 'TIMED_OUT' then
106
- else
107
- raise
108
- end
109
- end
79
+ else
80
+ if index > number_of_messages
81
+ puts "*** Requested msg, #{index}, is greater than the number of msgs in
82
+ the queue, #{number_of_messages}"
83
+ puts '*** Try a smaller index, or remove the index number to return all
84
+ msgs'
85
+ abort
110
86
  end
111
-
112
- rescue Beanstalk::NotConnected=>e
87
+
88
+ puts
89
+ puts "Attempting to msg number, #{index} to it's source queue"
90
+ puts
91
+
92
+ begin
93
+ beanstalk.watch(queue_name)
94
+ job_list = []
95
+ 1.upto(index-1) do |request_nbr|
96
+ job = beanstalk.reserve 1
97
+ job_list << job
98
+ end
99
+ job = beanstalk.reserve 1
100
+ return_msg(beanstalk, job, index)
101
+
102
+ job_list.each(&:release)
103
+
104
+ rescue StandardError => e
105
+ if e.message == 'TIMED_OUT'
106
+ else
107
+ raise
108
+ end
109
+ end
110
+ end
111
+
112
+ rescue Beanstalk::NotConnected
113
113
  puts 'Beanstalk not running'
114
- end
114
+ end
@@ -1,2 +1 @@
1
1
  require 'rservicebus/test/bus'
2
- require 'rservicebus/test/redis'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rservicebus2
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Guy Irvine
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-07-12 00:00:00.000000000 Z
11
+ date: 2016-07-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: uuidtools