rservicebus 0.0.46 → 0.0.47
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/rservicebus/Monitor/CsvDir.rb +25 -6
- data/lib/rservicebus/Monitor/CsvPerLine.rb +30 -9
- data/lib/rservicebus/Monitor/Dir.rb +109 -104
- data/lib/rservicebus/Monitor/Message.rb +13 -9
- data/lib/rservicebus/Monitor/XmlDir.rb +10 -6
- data/lib/rservicebus/Monitor.rb +61 -58
- metadata +2 -2
@@ -1,11 +1,30 @@
|
|
1
1
|
require 'rservicebus/Monitor/Dir'
|
2
2
|
require 'csv'
|
3
3
|
|
4
|
-
|
4
|
+
module RServiceBus
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
6
|
+
class Monitor_CsvDir<Monitor_Dir
|
7
|
+
|
8
|
+
|
9
|
+
def checkPayloadForNumberOfColumns( payload )
|
10
|
+
if @QueryStringParts.has_key?("cols") then
|
11
|
+
|
12
|
+
cols = @QueryStringParts["cols"][0].to_i
|
13
|
+
payload.each_with_index do |row, idx|
|
14
|
+
if row.length != cols then
|
15
|
+
raise "Expected number of columns, #{cols}, Actual number of columns, #{row.length}, on line, #{idx}"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
def ProcessContent( content )
|
23
|
+
payload = CSV.parse( content )
|
24
|
+
self.checkPayloadForNumberOfColumns( payload )
|
25
|
+
return payload
|
26
|
+
end
|
27
|
+
|
9
28
|
end
|
10
|
-
|
11
|
-
end
|
29
|
+
|
30
|
+
end
|
@@ -1,18 +1,39 @@
|
|
1
1
|
require 'rservicebus/Monitor/Dir'
|
2
2
|
require 'csv'
|
3
3
|
|
4
|
-
|
4
|
+
module RServiceBus
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
uri = URI.parse( "file://#{filePath}" )
|
6
|
+
class Monitor_CsvPerLineDir<Monitor_Dir
|
7
|
+
|
9
8
|
|
10
|
-
|
11
|
-
|
12
|
-
|
9
|
+
def checkPayloadForNumberOfColumns( payload )
|
10
|
+
if @QueryStringParts.has_key?("cols") then
|
11
|
+
|
12
|
+
cols = @QueryStringParts["cols"][0].to_i
|
13
|
+
payload.each_with_index do |row, idx|
|
14
|
+
if row.length != cols then
|
15
|
+
raise "Expected number of columns, #{cols}, Actual number of columns, #{row.length}, on line, #{idx}"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
13
20
|
end
|
14
21
|
|
15
|
-
|
16
|
-
|
22
|
+
def ProcessPath( filePath )
|
23
|
+
uri = URI.parse( "file://#{filePath}" )
|
24
|
+
|
25
|
+
content = IO.read( filePath )
|
26
|
+
payload = CSV.parse( content )
|
27
|
+
|
28
|
+
self.checkPayloadForNumberOfColumns( payload )
|
29
|
+
|
30
|
+
payload.each do |csvline|
|
31
|
+
self.send( csvline, uri )
|
32
|
+
end
|
17
33
|
|
34
|
+
return content
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
|
18
39
|
end
|
@@ -3,131 +3,136 @@ require 'cgi'
|
|
3
3
|
require 'zip/zip'
|
4
4
|
require 'zlib'
|
5
5
|
|
6
|
-
|
6
|
+
module RServiceBus
|
7
7
|
|
8
|
-
|
9
|
-
@ArchiveDir
|
10
|
-
@InputFilter
|
11
|
-
|
12
|
-
def connect(uri)
|
13
|
-
#Pass the path through the Dir object to check syntax on startup
|
14
|
-
inputDir = Dir.new( uri.path )
|
15
|
-
@Path = inputDir.path
|
16
|
-
@InputFilter = Array.new
|
8
|
+
class Monitor_Dir<Monitor
|
17
9
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
if !File.directory?( archiveUri.path ) then
|
23
|
-
puts "***** Archive file name templating not yet supported."
|
24
|
-
puts "***** Directory's only."
|
25
|
-
abort()
|
26
|
-
end
|
27
|
-
@ArchiveDir = archiveUri.path
|
28
|
-
end
|
10
|
+
@Path
|
11
|
+
@ArchiveDir
|
12
|
+
@InputFilter
|
13
|
+
@QueryStringParts
|
29
14
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
15
|
+
def connect(uri)
|
16
|
+
#Pass the path through the Dir object to check syntax on startup
|
17
|
+
inputDir = Dir.new( uri.path )
|
18
|
+
@Path = inputDir.path
|
19
|
+
@InputFilter = Array.new
|
20
|
+
|
21
|
+
return if uri.query.nil?
|
22
|
+
parts = CGI.parse(uri.query)
|
23
|
+
@QueryStringParts = parts
|
24
|
+
if parts.has_key?("archive") then
|
25
|
+
archiveUri = URI.parse( parts["archive"][0] )
|
26
|
+
if !File.directory?( archiveUri.path ) then
|
27
|
+
puts "***** Archive file name templating not yet supported."
|
28
|
+
puts "***** Directory's only."
|
29
|
+
abort()
|
30
|
+
end
|
31
|
+
@ArchiveDir = archiveUri.path
|
35
32
|
end
|
36
33
|
|
37
|
-
if parts
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
34
|
+
if parts.has_key?("inputfilter") then
|
35
|
+
if parts["inputfilter"].count > 1 then
|
36
|
+
puts "Too many inputfilters specified."
|
37
|
+
puts "*** ZIP, or GZ are the only valid inputfilters."
|
38
|
+
abort();
|
39
|
+
end
|
40
|
+
|
41
|
+
if parts["inputfilter"][0] == "ZIP" then
|
42
|
+
elsif parts["inputfilter"][0] == "GZ" then
|
43
|
+
elsif parts["inputfilter"][0] == "TAR" then
|
44
|
+
else
|
45
|
+
puts "Invalid inputfilter specified."
|
46
|
+
puts "*** ZIP, or GZ are the only valid inputfilters."
|
47
|
+
abort();
|
48
|
+
end
|
49
|
+
@InputFilter << parts["inputfilter"][0]
|
44
50
|
end
|
45
|
-
|
51
|
+
|
52
|
+
|
46
53
|
end
|
47
54
|
|
55
|
+
def ProcessContent( content )
|
56
|
+
return content
|
57
|
+
end
|
48
58
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
entry = zip.get_next_entry
|
58
|
-
content = zip.read
|
59
|
-
zip.close
|
59
|
+
def ReadContentFromZipFile( filePath )
|
60
|
+
zip = Zip::ZipInputStream::open(filePath)
|
61
|
+
entry = zip.get_next_entry
|
62
|
+
content = zip.read
|
63
|
+
zip.close
|
64
|
+
|
65
|
+
return entry, content
|
66
|
+
end
|
60
67
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
def ReadContentFromGzFile( filePath )
|
65
|
-
gz = Zlib::GzipReader.open(filePath)
|
66
|
-
return gz.read
|
67
|
-
end
|
68
|
-
|
69
|
-
def ReadContentFromTarFile( filePath )
|
70
|
-
content = ""
|
71
|
-
Gem::Package::TarReader.new( filePath ).each do |entry|
|
72
|
-
content = entry.read
|
73
|
-
return content
|
68
|
+
def ReadContentFromGzFile( filePath )
|
69
|
+
gz = Zlib::GzipReader.open(filePath)
|
70
|
+
return gz.read
|
74
71
|
end
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
entry, content = self.ReadContentFromZipFile( filePath )
|
82
|
-
elsif @InputFilter[0] == 'GZ' then
|
83
|
-
content = self.ReadContentFromGzFile( filePath )
|
84
|
-
elsif @InputFilter[0] == 'TAR' then
|
85
|
-
content = self.ReadContentFromTarFile( filePath )
|
72
|
+
|
73
|
+
def ReadContentFromTarFile( filePath )
|
74
|
+
content = ""
|
75
|
+
Gem::Package::TarReader.new( filePath ).each do |entry|
|
76
|
+
content = entry.read
|
77
|
+
return content
|
86
78
|
end
|
87
|
-
|
88
|
-
else
|
89
|
-
content = IO.read( filePath )
|
90
79
|
end
|
91
80
|
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
81
|
+
def ReadContentFromFile( filePath )
|
82
|
+
content = ""
|
83
|
+
if @InputFilter.length > 0 then
|
84
|
+
if @InputFilter[0] == 'ZIP' then
|
85
|
+
entry, content = self.ReadContentFromZipFile( filePath )
|
86
|
+
elsif @InputFilter[0] == 'GZ' then
|
87
|
+
content = self.ReadContentFromGzFile( filePath )
|
88
|
+
elsif @InputFilter[0] == 'TAR' then
|
89
|
+
content = self.ReadContentFromTarFile( filePath )
|
90
|
+
end
|
91
|
+
|
92
|
+
else
|
93
|
+
content = IO.read( filePath )
|
94
|
+
end
|
95
|
+
|
96
|
+
return content
|
97
|
+
end
|
98
98
|
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
99
|
+
def ProcessPath( filePath )
|
100
|
+
content = self.ReadContentFromFile( filePath )
|
101
|
+
payload = self.ProcessContent( content )
|
102
|
+
|
103
|
+
self.send( payload, URI.parse( "file://#{filePath}" ) )
|
104
|
+
return content
|
105
|
+
end
|
106
106
|
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
content = self.ProcessPath( filePath )
|
107
|
+
def Look
|
108
|
+
fileProcessed = 0
|
109
|
+
maxFilesProcessed = 10
|
111
110
|
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
111
|
+
fileList = Dir.glob( "#{@Path}/*" )
|
112
|
+
fileList.each do |filePath|
|
113
|
+
@Bus.log "Ready to process, #{filePath}", true
|
114
|
+
content = self.ProcessPath( filePath )
|
116
115
|
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
116
|
+
if !@ArchiveDir.nil? then
|
117
|
+
basename = File.basename( filePath )
|
118
|
+
newFilePath = @ArchiveDir + "/" + basename + "." + DateTime.now.strftime( "%Y%m%d%H%M%S%L") + ".zip"
|
119
|
+
@Bus.log "Writing to archive, #{newFilePath}", true
|
120
|
+
|
121
|
+
Zip::ZipOutputStream.open(newFilePath) {
|
122
|
+
|zos|
|
123
|
+
zos.put_next_entry(basename)
|
124
|
+
zos.puts content
|
125
|
+
}
|
126
|
+
end
|
127
|
+
File.unlink( filePath )
|
128
|
+
|
129
|
+
fileProcessed = fileProcessed + 1
|
130
|
+
@Bus.log "Processed #{fileProcessed} of #{fileList.length}.", true
|
131
|
+
@Bus.log "Allow system tick #{self.class.name}", true
|
132
|
+
return if fileProcessed >= maxFilesProcessed
|
122
133
|
end
|
123
|
-
File.unlink( filePath )
|
124
134
|
|
125
|
-
fileProcessed = fileProcessed + 1
|
126
|
-
@Bus.log "Processed #{fileProcessed} of #{fileList.length}.", true
|
127
|
-
@Bus.log "Allow system tick #{self.class.name}", true
|
128
|
-
return if fileProcessed >= maxFilesProcessed
|
129
135
|
end
|
130
136
|
|
131
137
|
end
|
132
|
-
|
133
138
|
end
|
@@ -1,12 +1,16 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
1
|
+
module RServiceBus
|
2
|
+
|
3
|
+
class Monitor_Message
|
4
|
+
attr_reader :payload, :uri
|
5
|
+
|
6
|
+
@payload
|
7
|
+
@uri
|
8
|
+
|
9
|
+
def initialize( payload, uri )
|
10
|
+
@payload = payload
|
11
|
+
@uri = uri
|
12
|
+
end
|
13
|
+
|
10
14
|
end
|
11
15
|
|
12
16
|
end
|
@@ -1,11 +1,15 @@
|
|
1
1
|
require 'rservicebus/Monitor/Dir'
|
2
2
|
require 'xmlsimple'
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
4
|
+
module RServiceBus
|
5
|
+
|
6
|
+
class Monitor_XmlDir<Monitor_Dir
|
7
|
+
|
8
|
+
|
9
|
+
def ProcessContent( content )
|
10
|
+
return XmlSimple.xml_in( content )
|
11
|
+
end
|
12
|
+
|
9
13
|
end
|
10
|
-
|
14
|
+
|
11
15
|
end
|
data/lib/rservicebus/Monitor.rb
CHANGED
@@ -1,64 +1,67 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
attr_accessor :Bus
|
4
|
-
|
5
|
-
@Bus
|
6
|
-
@uri
|
7
|
-
@connection
|
8
|
-
@MsgType
|
1
|
+
module RServiceBus
|
9
2
|
|
10
|
-
|
11
|
-
#
|
12
|
-
def connect(uri)
|
13
|
-
raise "Method, connect, needs to be implemented for resource"
|
14
|
-
end
|
15
|
-
|
16
|
-
# The method which actually connects to the resource.
|
17
|
-
#
|
18
|
-
def Look
|
19
|
-
raise "Method, Look, needs to be implemented for the Monitor"
|
20
|
-
end
|
21
|
-
|
22
|
-
def _connect
|
23
|
-
@connection = self.connect(@uri)
|
24
|
-
@Bus.log "#{self.class.name}. Connected to, #{@uri.to_s}" unless !ENV["QUIET"].nil?
|
25
|
-
end
|
26
|
-
|
27
|
-
# Resources are attached resources, and can be specified using the URI syntax.
|
28
|
-
#
|
29
|
-
# @param [String] uri a location for the resource to which we will attach, eg redis://127.0.0.1/foo
|
30
|
-
def initialize( bus, name, uri )
|
31
|
-
@Bus = bus
|
32
|
-
# @MsgType = Object.const_get( name )
|
33
|
-
newAnonymousClass = Class.new(Monitor_Message)
|
34
|
-
Object.const_set( name, newAnonymousClass )
|
35
|
-
@MsgType = Object.const_get( name )
|
3
|
+
class Monitor
|
36
4
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
begin
|
49
|
-
self.finished
|
50
|
-
rescue Exception => e
|
51
|
-
puts "** Monitor. An error was raised while closing connection to, " + @uri.to_s
|
52
|
-
puts "Message: " + e.message
|
53
|
-
puts e.backtrace
|
5
|
+
attr_accessor :Bus
|
6
|
+
|
7
|
+
@Bus
|
8
|
+
@uri
|
9
|
+
@connection
|
10
|
+
@MsgType
|
11
|
+
|
12
|
+
# The method which actually connects to the resource.
|
13
|
+
#
|
14
|
+
def connect(uri)
|
15
|
+
raise "Method, connect, needs to be implemented for resource"
|
54
16
|
end
|
55
17
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
18
|
+
# The method which actually connects to the resource.
|
19
|
+
#
|
20
|
+
def Look
|
21
|
+
raise "Method, Look, needs to be implemented for the Monitor"
|
22
|
+
end
|
23
|
+
|
24
|
+
def _connect
|
25
|
+
@connection = self.connect(@uri)
|
26
|
+
@Bus.log "#{self.class.name}. Connected to, #{@uri.to_s}" unless !ENV["QUIET"].nil?
|
27
|
+
end
|
28
|
+
|
29
|
+
# Resources are attached resources, and can be specified using the URI syntax.
|
30
|
+
#
|
31
|
+
# @param [String] uri a location for the resource to which we will attach, eg redis://127.0.0.1/foo
|
32
|
+
def initialize( bus, name, uri )
|
33
|
+
@Bus = bus
|
34
|
+
# @MsgType = Object.const_get( name )
|
35
|
+
newAnonymousClass = Class.new(Monitor_Message)
|
36
|
+
Object.const_set( name, newAnonymousClass )
|
37
|
+
@MsgType = Object.const_get( name )
|
38
|
+
|
39
|
+
|
40
|
+
@uri = uri
|
41
|
+
self._connect
|
42
|
+
end
|
43
|
+
|
44
|
+
# A notification that allows cleanup
|
45
|
+
def finished
|
46
|
+
end
|
47
|
+
|
48
|
+
# At least called in the Host rescue block, to ensure all network links are healthy
|
49
|
+
def reconnect
|
50
|
+
begin
|
51
|
+
self.finished
|
52
|
+
rescue Exception => e
|
53
|
+
puts "** Monitor. An error was raised while closing connection to, " + @uri.to_s
|
54
|
+
puts "Message: " + e.message
|
55
|
+
puts e.backtrace
|
56
|
+
end
|
57
|
+
|
58
|
+
self._connect
|
59
|
+
end
|
60
|
+
|
61
|
+
def send( payload, uri )
|
62
|
+
msg = @MsgType.new( payload, uri )
|
63
|
+
|
64
|
+
@Bus.Send( msg )
|
65
|
+
end
|
63
66
|
end
|
64
67
|
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.0.
|
4
|
+
version: 0.0.47
|
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-03-
|
12
|
+
date: 2013-03-12 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: A Ruby interpretation of NServiceBus
|
15
15
|
email: guy@guyirvine.com
|