rservicebus2 0.2.15 → 0.2.17

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
  SHA256:
3
- metadata.gz: 69007cfc230952eb00fdc713bc27b4d596eb7e59502331d7f30d22d52792c317
4
- data.tar.gz: b48dab985640e9a8daf6a311f70a028031b69bdf0762013a10b83bffff29dda9
3
+ metadata.gz: 920ff69a3fdd0f96882ed1c8bc12dd82d78ed789fa92c664f1b80f1484365058
4
+ data.tar.gz: c41fa4a4284bfba83865cc6bac87e54312c26b556a6605f6e73022b8716c921c
5
5
  SHA512:
6
- metadata.gz: 6e9eed975d128ba3a8c664b246e1494d9f0dfbf6b5a38bcf7c5794e38949d264c54ecbcbabee7cdb707dc272a0476675da06c0451b23392a86fbf23481269492
7
- data.tar.gz: 4934bf11567524616a8357d6d3f8d222b1b5a5b22a72021a3468b1c3a69c860f1f1ce7c58262f2c30a813c19b10ac0b60cb49d7b98107bc934d2d27274d48a4b
6
+ metadata.gz: e68d15cc10acdb2565ab02d6d8cfd3dc8b1a871becfe9a6b66f319d763526c16df8977456aadec9b5c2cc66595082bfde320a02458e384b2753b7be68cc01726
7
+ data.tar.gz: f1c1c5ea85bf0920206067b92b58544068084b0e631c29ce6fdb00783114f87e507d59d3f2c237d1b307a9b3df7430deaf8ef74bf020ca6874c029801bfe99b0
@@ -252,18 +252,30 @@ module RServiceBus2
252
252
  message_loop = false
253
253
  rescue NoMsgToProcess => e
254
254
  # This exception is just saying there are no messages to process
255
- @queue_for_msgs_to_be_sent_on_complete = []
256
- @monitors.each(&:look)
257
- send_queued_msgs
258
- @queue_for_msgs_to_be_sent_on_complete = nil
259
-
260
- @queue_for_msgs_to_be_sent_on_complete = []
261
- @cron_manager.run
262
- send_queued_msgs
263
- @queue_for_msgs_to_be_sent_on_complete = nil
264
-
265
- @send_at_manager.process
266
- @circuit_breaker.success
255
+ begin
256
+ @queue_for_msgs_to_be_sent_on_complete = []
257
+ @monitors.each(&:look)
258
+ send_queued_msgs
259
+ @queue_for_msgs_to_be_sent_on_complete = nil
260
+
261
+ @queue_for_msgs_to_be_sent_on_complete = []
262
+ @cron_manager.run
263
+ send_queued_msgs
264
+ @queue_for_msgs_to_be_sent_on_complete = nil
265
+
266
+ @send_at_manager.process
267
+ @circuit_breaker.success
268
+ rescue StandardError => e
269
+ if e.message == 'SIGTERM' || e.message == 'SIGINT'
270
+ puts 'Exiting on request ...'
271
+ message_loop = false
272
+ else
273
+ puts '*** This is really unexpected.'
274
+ message_loop = false
275
+ puts "Message: #{e.message}"
276
+ puts e.backtrace
277
+ end
278
+ end
267
279
  rescue StandardError => e
268
280
  if e.message == 'SIGTERM' || e.message == 'SIGINT'
269
281
  puts 'Exiting on request ...'
@@ -12,7 +12,7 @@ module RServiceBus2
12
12
  CGI.parse(u.query)['timeout1']&.first || 5
13
13
  end
14
14
 
15
- # rubocop:disable Metrics/MethodLength
15
+ # rubocop:disable Metrics/MethodLength,Metrics/AbcSize
16
16
  def connect(uri)
17
17
  @uri = uri
18
18
  @timeout = deduce_timeout(uri)
@@ -36,7 +36,7 @@ module RServiceBus2
36
36
  puts e.message
37
37
  puts e.backtrace
38
38
  end
39
- # rubocop:enable Metrics/MethodLength
39
+ # rubocop:enable Metrics/MethodLength,Metrics/AbcSize
40
40
 
41
41
  def look
42
42
  job = @beanstalk.reserve @timeout
@@ -28,6 +28,7 @@ module RServiceBus2
28
28
  abort
29
29
  end
30
30
 
31
+ # rubocop:disable Metrics/MethodLength
31
32
  def connect(uri)
32
33
  @path = input_dir(uri).path
33
34
  @input_filter = []
@@ -54,16 +55,14 @@ module RServiceBus2
54
55
  abort
55
56
  end
56
57
 
57
- if parts['input_filter'][0] == 'ZIP'
58
- elsif parts['input_filter'][0] == 'GZ'
59
- elsif parts['input_filter'][0] == 'TAR'
60
- else
58
+ unless %w[ZIP GZ TAR].include?(parts['input_filter'][0]).nil?
61
59
  puts 'Invalid input_filter specified.'
62
60
  puts '*** ZIP, or GZ are the only valid input_filters.'
63
61
  abort
64
62
  end
65
63
  @input_filter << parts['input_filter'][0]
66
64
  end
65
+ # rubocop:enable Metrics/MethodLength
67
66
 
68
67
  def process_content(content)
69
68
  content
@@ -86,13 +85,14 @@ module RServiceBus2
86
85
  # rubocop:disable Metrics/MethodLength
87
86
  def read_content_from_file(file_path)
88
87
  content = ''
89
- if @input_filter.length > 0
90
- if @input_filter[0] == 'ZIP'
88
+ if @input_filter.positive?
89
+ case @input_filter[0]
90
+ when 'ZIP'
91
91
  content = read_content_from_zip_file(file_path)
92
- elsif @input_filter[0] == 'GZ'
92
+ when 'GZ'
93
93
  content = read_content_from_gz_file(file_path)
94
- elsif @input_filter[0] == 'TAR'
95
- fail 'TAR reader not implemented'
94
+ when 'TAR'
95
+ raise 'TAR reader not implemented'
96
96
  end
97
97
 
98
98
  else
@@ -101,15 +101,27 @@ module RServiceBus2
101
101
 
102
102
  content
103
103
  end
104
+ # rubocop:enable Metrics/MethodLength
104
105
 
105
106
  def process_path(file_path)
106
107
  content = read_content_from_file(file_path)
107
108
  payload = process_content(content)
108
109
 
109
- send(payload, URI.parse(URI.encode("file://#{file_path}")))
110
+ send(payload, URI.parse(CGI.escape("file://#{file_path}")))
110
111
  content
111
112
  end
112
113
 
114
+ def archive_file(file_path, content)
115
+ basename = File.basename(file_path)
116
+ new_file_path = "#{@archivedir}/#{basename}.#{Time.now.strftime('%Y%m%d%H%M%S%L')}.zip"
117
+ RServiceBus2.log "Writing to archive, #{new_file_path}"
118
+
119
+ Zip::ZipOutputStream.open(new_file_path) do |zos|
120
+ zos.put_next_entry(basename)
121
+ zos.puts content
122
+ end
123
+ end
124
+
113
125
  def look
114
126
  file_processed = 0
115
127
  max_files_processed = 10
@@ -123,21 +135,12 @@ module RServiceBus2
123
135
  RServiceBus2.log "Ready to process, #{file_path}"
124
136
  content = process_path(file_path)
125
137
 
126
- unless @archivedir.nil?
127
- basename = File.basename(file_path)
128
- new_file_path = "#{@archivedir}/#{basename}.#{Time.now.strftime('%Y%m%d%H%M%S%L')}.zip"
129
- RServiceBus2.log "Writing to archive, #{new_file_path}"
130
-
131
- Zip::ZipOutputStream.open(new_file_path) do |zos|
132
- zos.put_next_entry(basename)
133
- zos.puts content
134
- end
135
- end
138
+ archive_file(file_path, content) unless @archivedir.nil?
136
139
  File.unlink(file_path)
137
140
 
138
141
  file_processed += 1
139
- RServiceBus2.log "Processed #{file_processed} of #{file_list.length}."
140
- RServiceBus2.log "Allow system tick #{self.class.name}"
142
+ RServiceBus2.log "Processed #{file_processed} of #{file_list.length}.\nAllow system tick #{self.class.name}"
143
+
141
144
  break if file_processed >= max_files_processed
142
145
  end
143
146
  end
@@ -14,21 +14,19 @@ module RServiceBus2
14
14
  begin
15
15
  open_folder uri.path
16
16
  unless File.writable?(uri.path)
17
- puts "***** Directory is not writable, #{uri.path}."
18
- puts "***** Make the directory, #{uri.path}, writable and try again."
17
+ puts "***** Directory is not writable, #{uri.path}.\n" \
18
+ "***** Make the directory, #{uri.path}, writable and try again."
19
19
  abort
20
20
  end
21
21
  rescue Errno::ENOENT
22
- puts "***** Directory does not exist, #{uri.path}."
23
- puts "***** Create the directory, #{uri.path}, and try again."
24
- puts "***** eg, mkdir #{uri.path}"
22
+ puts "***** Directory does not exist, #{uri.path}.\n" \
23
+ "***** Create the directory, #{uri.path}, and try again.\n" \
24
+ "***** eg, mkdir #{uri.path}"
25
25
  abort
26
26
  rescue Errno::ENOTDIR
27
- puts "***** The specified path does not point to a directory,
28
- #{uri.path}."
29
- puts "***** Either repoint path to a directory, or remove, #{uri.path},
30
- and create it as a directory."
31
- puts "***** eg, rm #{uri.path} && mkdir #{uri.path}"
27
+ puts "***** The specified path does not point to a directory, #{uri.path}." \
28
+ "***** Either repoint path to a directory, or remove, #{uri.path}, and create it as a directory." \
29
+ "***** eg, rm #{uri.path} && mkdir #{uri.path}"
32
30
  abort
33
31
  end
34
32
 
@@ -55,19 +53,14 @@ module RServiceBus2
55
53
  abort
56
54
  end
57
55
  rescue Errno::ENOENT
58
- puts "***** Processing Directory does not exist,
59
- #{processing_uri.path}."
60
- puts "***** Create the directory, #{processing_uri.path}, and try
61
- again."
62
- puts "***** eg, mkdir #{processing_uri.path}"
56
+ puts "***** Processing Directory does not exist, #{processing_uri.path}." \
57
+ "***** Create the directory, #{processing_uri.path}, and try again." \
58
+ "***** eg, mkdir #{processing_uri.path}"
63
59
  abort
64
60
  rescue Errno::ENOTDIR
65
- puts "***** Processing Directory does not point to a directory,
66
- #{processing_uri.path}."
67
- puts "***** Either repoint path to a directory, or remove,
68
- #{processing_uri.path}, and create it as a directory."
69
- puts "***** eg, rm #{processing_uri.path} && mkdir
70
- #{processing_uri.path}"
61
+ puts "***** Processing Directory does not point to a directory, #{processing_uri.path}." \
62
+ "***** Either repoint path to a directory, or remove, #{processing_uri.path}, and create it as a directory.\n" \
63
+ "***** eg, rm #{processing_uri.path} && mkdir #{processing_uri.path}"
71
64
  abort
72
65
  end
73
66
 
@@ -80,7 +73,7 @@ module RServiceBus2
80
73
  end
81
74
 
82
75
  def look
83
- file_list = get_files
76
+ file_list = files
84
77
  file_list.each do |file_path|
85
78
  new_path = move_file(file_path, @processing_folder)
86
79
  send(nil, URI.parse("file://#{new_path}"))
@@ -97,8 +90,8 @@ module RServiceBus2
97
90
  Pathname.new(dest).join(filename)
98
91
  end
99
92
 
100
- def get_files
101
- Dir.glob(Pathname.new("#{@Path}").join(@Filter) ).select { |f| File.file?(f) }
93
+ def files
94
+ Dir.glob(Pathname.new(@path).join(@filter)).select { |f| File.file?(f) }
102
95
  end
103
96
  end
104
97
  end
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.2.15
4
+ version: 0.2.17
5
5
  platform: ruby
6
6
  authors:
7
7
  - Guy Irvine
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-05-14 00:00:00.000000000 Z
11
+ date: 2021-05-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: beanstalk-client