rservicebus 0.1.45 → 0.1.46

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/bin/ReturnMessagesToSourceQueue +114 -0
  2. metadata +13 -12
@@ -0,0 +1,114 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "yaml"
4
+ require "beanstalk-client"
5
+ require "rservicebus"
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.getLastErrorMsg.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.getLastErrorMsg.sourceQueue
29
+ puts "#" + "#{request_nbr.to_s}: #{msgName} to #{queueName}"
30
+
31
+ beanstalk.use( queueName )
32
+ beanstalk.put( payload )
33
+
34
+ job.delete
35
+ end
36
+
37
+
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
46
+ else
47
+ abort( "Usage: ReturnMessagesToSourceQueue [queue name] [index]" )
48
+ end
49
+
50
+ begin
51
+ host = 'localhost:11300'
52
+ beanstalk = Beanstalk::Pool.new([host])
53
+
54
+ tubes = beanstalk.list_tubes[host]
55
+ if !tubes.include?(queueName) then
56
+ abort( "Nothing waiting on the Beanstalk queue, #{queueName}" )
57
+ 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
110
+ end
111
+
112
+ rescue Beanstalk::NotConnected=>e
113
+ puts "Beanstalk not running"
114
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rservicebus
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.45
4
+ version: 0.1.46
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-10-10 00:00:00.000000000 Z
12
+ date: 2013-10-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: uuidtools
16
- requirement: &70286679995660 !ruby/object:Gem::Requirement
16
+ requirement: &70280120092440 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70286679995660
24
+ version_requirements: *70280120092440
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: json
27
- requirement: &70286679994800 !ruby/object:Gem::Requirement
27
+ requirement: &70280120091760 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70286679994800
35
+ version_requirements: *70280120091760
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: beanstalk-client
38
- requirement: &70286680016340 !ruby/object:Gem::Requirement
38
+ requirement: &70280120090960 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *70286680016340
46
+ version_requirements: *70280120090960
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: fluiddb
49
- requirement: &70286680015220 !ruby/object:Gem::Requirement
49
+ requirement: &70280120089780 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *70286680015220
57
+ version_requirements: *70280120089780
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: parse-cron
60
- requirement: &70286680014580 !ruby/object:Gem::Requirement
60
+ requirement: &70280120088700 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,7 +65,7 @@ dependencies:
65
65
  version: '0'
66
66
  type: :runtime
67
67
  prerelease: false
68
- version_requirements: *70286680014580
68
+ version_requirements: *70280120088700
69
69
  description: A Ruby interpretation of NServiceBus
70
70
  email: guy@guyirvine.com
71
71
  executables:
@@ -138,6 +138,7 @@ files:
138
138
  - lib/rservicebus/UserMessage/WithPayload.rb
139
139
  - lib/rservicebus.rb
140
140
  - bin/ReturnErroredMessagesToSourceQueue
141
+ - bin/ReturnMessagesToSourceQueue
141
142
  - bin/rservicebus
142
143
  - bin/rservicebus-init
143
144
  - bin/rservicebus-transport