rservicebus 0.1.9 → 0.1.10
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/rservicebus/AppResource/State.rb +68 -0
- data/lib/rservicebus/Transporter.rb +62 -20
- metadata +3 -2
@@ -0,0 +1,68 @@
|
|
1
|
+
module RServiceBus
|
2
|
+
|
3
|
+
class State
|
4
|
+
|
5
|
+
def initialize( path )
|
6
|
+
@path = path
|
7
|
+
end
|
8
|
+
|
9
|
+
def get( name )
|
10
|
+
return -1 unless @state.has_key?("name")
|
11
|
+
|
12
|
+
return @state["name"]
|
13
|
+
end
|
14
|
+
|
15
|
+
def set( name, id )
|
16
|
+
@state["name"] = id
|
17
|
+
end
|
18
|
+
|
19
|
+
def load
|
20
|
+
if !File.exists?( @path ) then
|
21
|
+
@state = Hash.new if !File.exists?( @path )
|
22
|
+
return
|
23
|
+
end
|
24
|
+
|
25
|
+
content = IO.read( @path )
|
26
|
+
if content == "" then
|
27
|
+
@state = Hash.new
|
28
|
+
end
|
29
|
+
|
30
|
+
|
31
|
+
@state = YAML::load( content )
|
32
|
+
end
|
33
|
+
|
34
|
+
def save
|
35
|
+
content = YAML::dump( @state )
|
36
|
+
IO.write( @path, content )
|
37
|
+
end
|
38
|
+
|
39
|
+
def close
|
40
|
+
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
|
46
|
+
class AppResource_State<AppResource
|
47
|
+
|
48
|
+
def connect(uri)
|
49
|
+
return State.new( uri.path )
|
50
|
+
end
|
51
|
+
|
52
|
+
# Transaction Semantics
|
53
|
+
def Begin
|
54
|
+
@connection.load
|
55
|
+
end
|
56
|
+
|
57
|
+
# Transaction Semantics
|
58
|
+
def Commit
|
59
|
+
@connection.save
|
60
|
+
end
|
61
|
+
|
62
|
+
# Transaction Semantics
|
63
|
+
def Rollback
|
64
|
+
@connection.load
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
@@ -48,26 +48,44 @@ class Transporter
|
|
48
48
|
abort();
|
49
49
|
end
|
50
50
|
|
51
|
-
def
|
52
|
-
|
53
|
-
job = @source.reserve @timeout
|
54
|
-
msg = YAML::load(job.body)
|
55
|
-
|
56
|
-
log "job: #{job.body}", true
|
57
|
-
|
51
|
+
def connectToRemoteSSH( remoteHostName )
|
52
|
+
return if @remoteHostName == remoteHostName
|
58
53
|
|
54
|
+
self.disconnectFromRemoteSSH
|
55
|
+
|
59
56
|
#Get destination url from job
|
60
|
-
|
61
|
-
|
62
|
-
gateway = Net::SSH::Gateway.new(
|
57
|
+
@remoteHostName = remoteHostName
|
58
|
+
@remoteUserName = getValue( "REMOTE_USER_#{remoteHostName.upcase}", "beanstalk" )
|
59
|
+
@gateway = Net::SSH::Gateway.new(remoteHostName, @remoteUserName)
|
63
60
|
|
64
61
|
# Open port 27018 to forward to 127.0.0.11300 on the remote host
|
65
|
-
gateway.open('127.0.0.1', 11300, 27018)
|
62
|
+
@gateway.open('127.0.0.1', 11300, 27018)
|
63
|
+
log "Connect to Remote SSH, #{@remoteHostName}"
|
64
|
+
|
65
|
+
return @gateway
|
66
|
+
end
|
66
67
|
|
67
|
-
|
68
|
+
def disconnectFromRemoteSSH
|
69
|
+
return if @gateway.nil?
|
70
|
+
|
71
|
+
log "Disconnect from Remote SSH, #{@remoteHostName}"
|
72
|
+
@gateway.shutdown!
|
73
|
+
@remoteHostName = nil
|
74
|
+
@gateway = nil
|
75
|
+
end
|
76
|
+
|
77
|
+
|
78
|
+
def connectToRemoteBeanstalk( remoteHostName, remoteQueueName )
|
79
|
+
self.connectToRemoteSSH( remoteHostName )
|
80
|
+
|
81
|
+
#Test connection
|
82
|
+
return if @remoteQueueName == remoteQueueName
|
83
|
+
|
84
|
+
|
85
|
+
log "Connect to Remote Beanstalk, #{remoteQueueName}"
|
68
86
|
begin
|
69
87
|
destinationUrl = '127.0.0.1:27018'
|
70
|
-
destination = Beanstalk::Pool.new([destinationUrl])
|
88
|
+
@destination = Beanstalk::Pool.new([destinationUrl])
|
71
89
|
rescue Exception => e
|
72
90
|
if e.message == "Beanstalk::NotConnected" then
|
73
91
|
puts "***Could not connect to destination, check beanstalk is running at, #{destinationUrl}"
|
@@ -75,10 +93,33 @@ class Transporter
|
|
75
93
|
end
|
76
94
|
raise
|
77
95
|
end
|
96
|
+
|
97
|
+
log "Use queue, #{remoteQueueName}", true
|
98
|
+
@destination.use( remoteQueueName )
|
99
|
+
@remoteQueueName = remoteQueueName
|
100
|
+
end
|
101
|
+
|
102
|
+
def disconnectFromRemoteBeanstalk
|
103
|
+
self.disconnectFromRemoteSSH
|
104
|
+
return if @destination.nil?
|
105
|
+
|
106
|
+
log "Disconnect from Remote Beanstalk, #{@remoteQueueName}"
|
107
|
+
@destination.close
|
108
|
+
@remoteQueueName = nil
|
109
|
+
end
|
110
|
+
|
111
|
+
|
112
|
+
def process
|
113
|
+
#Get the next job from the source queue
|
114
|
+
job = @source.reserve @timeout
|
115
|
+
msg = YAML::load(job.body)
|
116
|
+
|
117
|
+
# log "job: #{job.body}", true
|
118
|
+
|
119
|
+
self.connectToRemoteBeanstalk( msg.remoteHostName, msg.remoteQueueName )
|
78
120
|
|
79
|
-
log "Put msg
|
80
|
-
destination.
|
81
|
-
destination.put( job.body )
|
121
|
+
log "Put msg", true
|
122
|
+
@destination.put( job.body )
|
82
123
|
|
83
124
|
if !ENV['AUDIT_QUEUE_NAME'].nil? then
|
84
125
|
@source.use ENV['AUDIT_QUEUE_NAME']
|
@@ -87,11 +128,11 @@ class Transporter
|
|
87
128
|
#removeJob
|
88
129
|
job.delete
|
89
130
|
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
131
|
+
log "Job sent to, #{@remoteUserName}@#{@remoteHostName}/#{@remoteQueueName}"
|
132
|
+
|
133
|
+
|
94
134
|
rescue Exception => e
|
135
|
+
self.disconnectFromRemoteSSH
|
95
136
|
if e.message == "TIMED_OUT" then
|
96
137
|
log "No Msg", true
|
97
138
|
return
|
@@ -105,6 +146,7 @@ class Transporter
|
|
105
146
|
while true
|
106
147
|
process
|
107
148
|
end
|
149
|
+
self.disconnectFromRemoteSSH
|
108
150
|
end
|
109
151
|
end
|
110
152
|
|
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.
|
4
|
+
version: 0.1.10
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-08-
|
12
|
+
date: 2013-08-29 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: A Ruby interpretation of NServiceBus
|
15
15
|
email: guy@guyirvine.com
|
@@ -35,6 +35,7 @@ files:
|
|
35
35
|
- lib/rservicebus/AppResource/Redis.rb
|
36
36
|
- lib/rservicebus/AppResource/ScpUpload.rb
|
37
37
|
- lib/rservicebus/AppResource/Smb.rb
|
38
|
+
- lib/rservicebus/AppResource/State.rb
|
38
39
|
- lib/rservicebus/AppResource.rb
|
39
40
|
- lib/rservicebus/Config.rb
|
40
41
|
- lib/rservicebus/ConfigureAppResource.rb
|