rservicebus 0.0.44 → 0.0.46

Sign up to get free protection for your applications and to get access to all the features.
@@ -240,8 +240,8 @@ module RServiceBus
240
240
  end
241
241
 
242
242
  errorString = e.message + ". " + e.backtrace.join( ". " )
243
- log errorString
244
-
243
+ # log errorString
244
+
245
245
  @msg.addErrorMsg( @config.localQueueName, errorString )
246
246
  serialized_object = YAML::dump(@msg)
247
247
  self._SendAlreadyWrappedAndSerialised(serialized_object, @config.errorQueueName)
@@ -284,8 +284,8 @@ module RServiceBus
284
284
 
285
285
  if handlerList == nil then
286
286
  log "No handler found for: " + msgName
287
- puts "No handler found for: " + msgName
288
- puts YAML::dump(@msg)
287
+ # puts "No handler found for: " + msgName
288
+ # puts YAML::dump(@msg)
289
289
  raise "No Handler Found"
290
290
 
291
291
  else
@@ -295,7 +295,7 @@ module RServiceBus
295
295
  handler.Handle( @msg.msg )
296
296
  rescue Exception => e
297
297
  log "An error occured in Handler: " + handler.class.name
298
- log e.message + ". " + e.backtrace[0]
298
+ #log e.message + ". " + e.backtrace[0]
299
299
  raise e
300
300
  end
301
301
  end
@@ -4,8 +4,8 @@ require 'csv'
4
4
  class Monitor_CsvDir<Monitor_Dir
5
5
 
6
6
 
7
- def ProcessPath( path )
8
- return CSV.read( path )
7
+ def ProcessContent( content )
8
+ return CSV.parse( content )
9
9
  end
10
10
 
11
11
  end
@@ -4,10 +4,15 @@ require 'csv'
4
4
  class Monitor_CsvPerLineDir<Monitor_Dir
5
5
 
6
6
 
7
- def ProcessFile( file )
8
- CSV.read( file ).each do |csvline|
9
- self.send( csvline )
7
+ def ProcessPath( filePath )
8
+ uri = URI.parse( "file://#{filePath}" )
9
+
10
+ content = IO.read( filePath )
11
+ CSV.parse( content ).each do |csvline|
12
+ self.send( csvline, uri )
10
13
  end
14
+
15
+ return content
11
16
  end
12
17
 
13
18
  end
@@ -1,52 +1,131 @@
1
+ require 'rubygems/package'
1
2
  require 'cgi'
3
+ require 'zip/zip'
4
+ require 'zlib'
2
5
 
3
6
  class Monitor_Dir<Monitor
4
7
 
5
8
  @Path
6
9
  @ArchiveDir
10
+ @InputFilter
7
11
 
8
12
  def connect(uri)
9
13
  #Pass the path through the Dir object to check syntax on startup
10
14
  inputDir = Dir.new( uri.path )
11
15
  @Path = inputDir.path
16
+ @InputFilter = Array.new
12
17
 
13
18
  return if uri.query.nil?
14
19
  parts = CGI.parse(uri.query)
15
- return if parts["archive"].nil?
20
+ if parts.has_key?("archive") then
21
+ archiveUri = URI.parse( parts["archive"][0] )
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
16
29
 
17
- archiveUri = URI.parse( parts["archive"][0] )
18
- if !File.directory?( archiveUri.path ) then
19
- puts "***** Archive file name templating not yet supported."
20
- puts "***** Directory's only."
21
- abort()
30
+ if parts.has_key?("inputfilter") then
31
+ if parts["inputfilter"].count > 1 then
32
+ puts "Too many inputfilters specified."
33
+ puts "*** ZIP, or GZ are the only valid inputfilters."
34
+ abort();
35
+ end
36
+
37
+ if parts["inputfilter"][0] == "ZIP" then
38
+ elsif parts["inputfilter"][0] == "GZ" then
39
+ elsif parts["inputfilter"][0] == "TAR" then
40
+ else
41
+ puts "Invalid inputfilter specified."
42
+ puts "*** ZIP, or GZ are the only valid inputfilters."
43
+ abort();
44
+ end
45
+ @InputFilter << parts["inputfilter"][0]
22
46
  end
23
47
 
24
- @ArchiveDir = archiveUri.path
25
48
 
26
49
  end
27
50
 
28
- def ProcessPath( path )
29
- return IO.read( path )
51
+ def ProcessContent( content )
52
+ return content
30
53
  end
31
54
 
32
- def ProcessFile( file )
33
- payload = self.ProcessPath( file )
55
+ def ReadContentFromZipFile( filePath )
56
+ zip = Zip::ZipInputStream::open(filePath)
57
+ entry = zip.get_next_entry
58
+ content = zip.read
59
+ zip.close
34
60
 
35
- self.send( payload )
61
+ return entry, content
62
+ end
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
74
+ end
75
+ end
76
+
77
+ def ReadContentFromFile( filePath )
78
+ content = ""
79
+ if @InputFilter.length > 0 then
80
+ if @InputFilter[0] == 'ZIP' then
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 )
86
+ end
87
+
88
+ else
89
+ content = IO.read( filePath )
90
+ end
91
+
92
+ return content
93
+ end
94
+
95
+ def ProcessPath( filePath )
96
+ content = self.ReadContentFromFile( filePath )
97
+ payload = self.ProcessContent( content )
98
+
99
+ self.send( payload, URI.parse( "file://#{filePath}" ) )
100
+ return content
36
101
  end
37
102
 
38
103
  def Look
39
- Dir.glob( "#{@Path}/*" ).each do |file|
40
- self.ProcessFile( file )
41
-
42
- if @ArchiveDir.nil? then
43
- File.unlink( file )
44
- else
45
- basename = File.basename( file )
46
- newFilePath = @ArchiveDir + "/" + basename + "." + DateTime.now.strftime( "%Y%m%d%H%M%S%L")
104
+ fileProcessed = 0
105
+ maxFilesProcessed = 10
106
+
107
+ fileList = Dir.glob( "#{@Path}/*" )
108
+ fileList.each do |filePath|
109
+ @Bus.log "Ready to process, #{filePath}", true
110
+ content = self.ProcessPath( filePath )
111
+
112
+ if !@ArchiveDir.nil? then
113
+ basename = File.basename( filePath )
114
+ newFilePath = @ArchiveDir + "/" + basename + "." + DateTime.now.strftime( "%Y%m%d%H%M%S%L") + ".zip"
47
115
  @Bus.log "Writing to archive, #{newFilePath}", true
48
- File.rename( file, newFilePath )
116
+
117
+ Zip::ZipOutputStream.open(newFilePath) {
118
+ |zos|
119
+ zos.put_next_entry(basename)
120
+ zos.puts content
121
+ }
49
122
  end
123
+ File.unlink( filePath )
124
+
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
50
129
  end
51
130
 
52
131
  end
@@ -1,10 +1,12 @@
1
1
  class Monitor_Message
2
- attr_reader :payload
2
+ attr_reader :payload, :uri
3
3
 
4
4
  @payload
5
+ @uri
5
6
 
6
- def initialize( payload )
7
+ def initialize( payload, uri )
7
8
  @payload = payload
9
+ @uri = uri
8
10
  end
9
11
 
10
12
  end
@@ -4,9 +4,8 @@ require 'xmlsimple'
4
4
  class Monitor_XmlDir<Monitor_Dir
5
5
 
6
6
 
7
- def ProcessPath( path )
8
- # return Nokogiri::XML( File.open(path) )
9
- return XmlSimple.xml_in( path )
7
+ def ProcessContent( content )
8
+ return XmlSimple.xml_in( content )
10
9
  end
11
10
 
12
11
  end
@@ -56,8 +56,8 @@ class Monitor
56
56
  self._connect
57
57
  end
58
58
 
59
- def send( payload )
60
- msg = @MsgType.new( payload )
59
+ def send( payload, uri )
60
+ msg = @MsgType.new( payload, uri )
61
61
 
62
62
  @Bus.Send( msg )
63
63
  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.44
4
+ version: 0.0.46
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-10 00:00:00.000000000 Z
12
+ date: 2013-03-11 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: A Ruby interpretation of NServiceBus
15
15
  email: guy@guyirvine.com