rservicebus2 0.2.3 → 0.2.8

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: 3e12a4225a0bdda2fdc600e0f5f1134dacf481343d7e9e3e3837b820ca1f8509
4
- data.tar.gz: 02e285f84043c7f457db328a9fd74c1f7f62104531cae5b723ba301aca518a3f
3
+ metadata.gz: 5f94672750deba44e6495d728b6c45bbf0aba95efe35d18b6877359e27173da4
4
+ data.tar.gz: 27e94561da7ab338ee3ff5ac99f850f872900f2559bb56ce3dffd604c452173a
5
5
  SHA512:
6
- metadata.gz: a2aefd96d740b7020284d95f36256fead951f895fab13e8eeb1440b674ebdb28a580a11ad75c4cbb1dbb270b1aef0ed901af1b94d03459252cfe33947b85aac1
7
- data.tar.gz: 848e86f7d3c40f83cdb1f6d3459af1a5265f1e9272c7718da950c81457ff54983c0d00bc3997b0b0955df57798a53ff7be3650463458cdbe2b926c636053ddde
6
+ metadata.gz: ac819c545740eb82ecf1ae2b95286f837ae1189ba3eded36ddcc98680ce4b7dcc84b975d9c75ab48e62f99cef32a83d98fdf2ad195bab0012f2804392abb3289
7
+ data.tar.gz: c10528a4a06fc27f9e2c5541dd4d500a1ae2120cc0f89a4a66c165a09c6fb5eae014c04ab74735c29069c6b6f8ebfaf089c7f2f63d80cdc02fb7d4acf3f7cc7b
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'uri'
2
4
 
3
5
  module RServiceBus2
@@ -8,7 +10,7 @@ module RServiceBus2
8
10
 
9
11
  # The method which actually connects to the resource.
10
12
  def connect(_uri)
11
- fail 'Method, connect, needs to be implemented for resource'
13
+ raise 'Method, connect, needs to be implemented for resource'
12
14
  end
13
15
 
14
16
  def _connect
@@ -44,22 +46,19 @@ module RServiceBus2
44
46
  rescue StandardError => e
45
47
  puts '** AppResource. An error was raised while closing connection
46
48
  to, ' + @uri
47
- puts 'Message: ' + e.message
49
+ puts "Message: #{e.message}"
48
50
  puts e.backtrace
49
51
  end
50
52
  _connect
51
53
  end
52
54
 
53
55
  # Transaction Semantics
54
- def begin
55
- end
56
+ def begin; end
56
57
 
57
58
  # Transaction Semantics
58
- def commit
59
- end
59
+ def commit; end
60
60
 
61
61
  # Transaction Semantics
62
- def rollback
63
- end
62
+ def rollback; end
64
63
  end
65
64
  end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'aws-sdk-dynamodb'
4
+
5
+ module RServiceBus2
6
+ # AppResourceAWSDynamoDb
7
+ class AppResourceAWSDynamoDb < AppResource
8
+ def connect(uri)
9
+ region = uri.host
10
+
11
+ Aws::DynamoDB::Client.new(region: region)
12
+ end
13
+
14
+ def finished; end
15
+ end
16
+ end
@@ -0,0 +1,16 @@
1
+ require 'aws-sdk-s3'
2
+
3
+ module RServiceBus2
4
+ # AppResourceAWSDynamoDb
5
+ class AppResourceAWSS3 < AppResource
6
+ # rubocop:disable Metrics/AbcSize,Metrics/MethodLength
7
+ def connect(uri)
8
+ region = uri.host
9
+
10
+ Aws::S3::Client.new(region: region)
11
+ end
12
+
13
+ def finished
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,25 @@
1
+ require 'aws-sdk-sqs'
2
+ require 'aws-sdk-sts'
3
+
4
+ module RServiceBus2
5
+ # AppResourceAWSDynamoDb
6
+ class AppResourceAWSSQS < AppResource
7
+ def connect(uri)
8
+ queue_name = uri.path.sub('/', '')
9
+
10
+ region = uri.host
11
+
12
+ sts_client = Aws::STS::Client.new(region: region)
13
+ caller_identity_account = sts_client.get_caller_identity.account
14
+
15
+ queue_url = "https://sqs.#{region}.amazonaws.com/" \
16
+ "#{caller_identity_account}/#{queue_name}"
17
+ {
18
+ client: Aws::SQS::Client.new(region: region),
19
+ url: queue_url
20
+ }
21
+ end
22
+
23
+ def finished; end
24
+ end
25
+ end
@@ -31,6 +31,15 @@ module RServiceBus2
31
31
  when 'file'
32
32
  require 'rservicebus2/appresource/file'
33
33
  rm.add k.sub('RSB_', ''), AppResourceFile.new(host, uri)
34
+ when 'awsdynamodb'
35
+ require 'rservicebus2/appresource/awsdynamodb'
36
+ rm.add k.sub('RSB_', ''), AppResourceAWSDynamoDb.new(host, uri)
37
+ when 'awss3'
38
+ require 'rservicebus2/appresource/awss3'
39
+ rm.add k.sub('RSB_', ''), AppResourceAWSS3.new(host, uri)
40
+ when 'awssqs'
41
+ require 'rservicebus2/appresource/awssqs'
42
+ rm.add k.sub('RSB_', ''), AppResourceAWSSQS.new(host, uri)
34
43
  else
35
44
  abort("Scheme, #{uri.scheme}, not recognised when configuring
36
45
  app resource, #{k}=#{v}")
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module RServiceBus2
2
4
  class MessageArrivedWhileCricuitBroken < StandardError
3
5
  end
@@ -42,7 +44,7 @@ module RServiceBus2
42
44
  message_arrived
43
45
 
44
46
  ## logFirstFailure
45
- if @number_of_failures == 0
47
+ if @number_of_failures.zero?
46
48
  @number_of_failures = 1
47
49
  @time_of_first_failure = Time.now
48
50
  @time_to_break = @time_of_first_failure + @seconds_to_break
@@ -68,7 +70,7 @@ module RServiceBus2
68
70
  def message_arrived
69
71
  reset if !@time_to_break.nil? && Time.now > @time_to_break
70
72
 
71
- fail MessageArrivedWhileCricuitBroken if @broken == true
73
+ raise MessageArrivedWhileCricuitBroken if @broken == true
72
74
  end
73
75
 
74
76
  def break_circuit
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module RServiceBus2
2
4
  # Marshals configuration information for an rservicebus host
3
5
  class Config
@@ -19,7 +21,7 @@ module RServiceBus2
19
21
  end
20
22
 
21
23
  def get_value(name, default = nil)
22
- value = (ENV[name].nil? || ENV[name] == '') ? default : ENV[name]
24
+ value = ENV[name].nil? || ENV[name] == '' ? default : ENV[name]
23
25
  log "Env value: #{name}: #{value}"
24
26
  value
25
27
  end
@@ -131,21 +133,19 @@ module RServiceBus2
131
133
  # Note. trailing slashs will be stripped
132
134
  # Expected format: <path 1>;<path 2>
133
135
  def load_working_dir_list
134
- puts "Config.load_working_dir_list.1"
135
- puts "Config.load_working_dir_list.2 #{@contract_list}"
136
136
  path_list = get_value('WORKING_DIR', './')
137
137
  return self if path_list.nil?
138
138
 
139
139
  path_list.split(';').each do |path|
140
140
  path = path.strip.chomp('/')
141
- unless Dir.exist?("#{path}")
141
+ unless Dir.exist?(path.to_s)
142
142
  puts 'Error while processing working directory list'
143
143
  puts "*** path, #{path}, does not exist"
144
144
  abort
145
145
  end
146
146
  @handler_path_list << "#{path}/messagehandler" if Dir.exist?("#{path}/messagehandler")
147
147
  @saga_path_list << "#{path}/saga" if Dir.exist?("#{path}/saga")
148
- @contract_list << "#{path}/contract.rb" if File.exist?( "#{path}/contract.rb" )
148
+ @contract_list << "#{path}/contract.rb" if File.exist?("#{path}/contract.rb")
149
149
  @lib_list << "#{path}/lib" if File.exist?("#{path}/lib")
150
150
  end
151
151
  self
@@ -154,14 +154,11 @@ module RServiceBus2
154
154
 
155
155
  # Class
156
156
  class ConfigFromEnv < Config
157
- def initialize
158
- end
159
157
  end
160
158
 
161
159
  # Class
162
160
  class ConfigFromSetter < Config
163
- attr_writer :appName, :messageEndpointMappings, :handler_path_list, :errorQueueName, :maxRetries, :forward_received_messages_to, :beanstalkHost
164
- def initialize
165
- end
161
+ attr_writer :app_name, :message_endpoint_mappings, :handler_path_list, :error_queue_name, \
162
+ :max_retries, :forward_received_messages_to, :beanstalk_host
166
163
  end
167
164
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'parse-cron'
2
4
 
3
5
  module RServiceBus2
@@ -27,7 +29,8 @@ module RServiceBus2
27
29
  @msg_names.each do |n|
28
30
  list << n if Globber.new(name) =~ n
29
31
  end
30
- fail NoMatchingMsgForCron, name if list.length == 0
32
+ raise NoMatchingMsgForCron, name if list.empty?
33
+
31
34
  list
32
35
  end
33
36
 
@@ -44,6 +47,7 @@ module RServiceBus2
44
47
  end
45
48
  end
46
49
 
50
+ # rubocop:disable Metrics/MethodLength
47
51
  def initialize(host, msg_names = [])
48
52
  @bus = host
49
53
  @msg_names = msg_names
@@ -61,6 +65,7 @@ module RServiceBus2
61
65
  end
62
66
  end
63
67
  end
68
+ # rubocop:enable Metrics/MethodLength
64
69
 
65
70
  def run
66
71
  now = Time.now
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module RServiceBus2
2
4
  # Marshals data for message end points
3
5
  # Expected format: <msg mame 1>:<end point 1>;<msg mame 2>:<end point 2>
@@ -6,16 +8,18 @@ module RServiceBus2
6
8
  RServiceBus2.get_value(name)
7
9
  end
8
10
 
9
- def log(string, _ver = false)
11
+ def log(string, _ver: false)
10
12
  RServiceBus2.log(string)
11
13
  end
12
14
 
15
+ # rubocop:disable Metrics/AbcSize
16
+ # rubocop:disable Metrics/MethodLength
13
17
  def configure_mapping(mapping)
14
18
  match = mapping.match(/(.+):(.+)/)
15
19
  if match.nil?
16
- log 'Mapping string provided is invalid'
17
- log "The entire mapping string is: #{mapping}"
18
- log "*** Could not find ':' in mapping entry, #{line}"
20
+ log 'Mapping string provided is invalid\n' \
21
+ "The entire mapping string is: #{mapping}\n" \
22
+ "*** Could not find ':' in mapping entry, #{line}\n"
19
23
  exit
20
24
  end
21
25
 
@@ -23,16 +27,19 @@ module RServiceBus2
23
27
  @endpoints[match[1]] = match[2]
24
28
 
25
29
  @queue_name_list.each do |q|
26
- if q != match[2] && q.downcase == match[2].downcase
27
- log('*** Two queues specified with only case sensitive difference.')
28
- log("*** #{q} != #{match[2]}")
29
- log('*** If you meant these queues to be the same, please match case
30
- and restart the bus.')
31
- end
30
+ next unless q != match[2] && q.downcase == match[2].downcase
31
+
32
+ log('*** Two queues specified with only case sensitive difference.')
33
+ log("*** #{q} != #{match[2]}")
34
+ log('*** If you meant these queues to be the same, please match case
35
+ and restart the bus.')
32
36
  end
33
37
  @queue_name_list << match[2]
34
38
  end
39
+ # rubocop:enable Metrics/AbcSize
40
+ # rubocop:enable Metrics/MethodLength
35
41
 
42
+ # rubocop:disable Metrics/MethodLength
36
43
  def configure(local_queue_name = nil)
37
44
  log('EndpointMapping.Configure')
38
45
 
@@ -40,9 +47,9 @@ module RServiceBus2
40
47
  @queue_name_list << local_queue_name unless local_queue_name.nil?
41
48
 
42
49
  unless get_value('MESSAGE_ENDPOINT_MAPPING').nil?
43
- log('*** MESSAGE_ENDPOINT_MAPPING environment variable was detected')
44
- log("*** You may have intended MESSAGE_ENDPOINT_MAPPINGS, note the 'S'
45
- on the end")
50
+ log '*** MESSAGE_ENDPOINT_MAPPING environment variable was detected\n' \
51
+ "*** You may have intended MESSAGE_ENDPOINT_MAPPINGS, note the 'S'
52
+ on the end"
46
53
  end
47
54
 
48
55
  mappings = get_value('MESSAGE_ENDPOINT_MAPPINGS')
@@ -54,6 +61,7 @@ module RServiceBus2
54
61
 
55
62
  self
56
63
  end
64
+ # rubocop:enable Metrics/MethodLength
57
65
 
58
66
  def initialize
59
67
  @endpoints = {}
@@ -65,7 +73,7 @@ module RServiceBus2
65
73
  nil
66
74
  end
67
75
 
68
- def get_subscription_endpoints
76
+ def subscription_endpoints
69
77
  @endpoints.keys.select { |el| el.end_with?('Event') }
70
78
  end
71
79
  end
@@ -1,5 +1,6 @@
1
- module RServiceBus2
1
+ # frozen_string_literal: true
2
2
 
3
+ module RServiceBus2
3
4
  # Error Message
4
5
  class ErrorMessage
5
6
  attr_reader :occurredat, :source_queue, :error_msg
@@ -1,10 +1,12 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module RServiceBus2
2
4
  # Given a directory, this class is responsible for finding
3
5
  # msgnames,
4
6
  # handlernames, and
5
7
  # loading handlers
6
8
  class HandlerLoader
7
- attr_reader :handlerList
9
+ # attr_reader :handlerList - 8 May 2021
8
10
 
9
11
  # Constructor
10
12
  #
@@ -22,12 +24,11 @@ module RServiceBus2
22
24
  # Cleans the given path to ensure it can be used for as a parameter for the require statement.
23
25
  # @param [String] file_path the path to be cleaned
24
26
  def get_require_path(file_path)
25
- file_path = './' + file_path unless file_path.start_with?('/')
27
+ file_path = "./#{file_path}" unless file_path.start_with?('/')
26
28
 
27
29
  return file_path.sub('.rb', '') if File.exist?(file_path)
28
30
 
29
- abort('Filepath, ' + file_path + ", given for messagehandler require
30
- doesn't exist")
31
+ abort("Filepath, #{file_path}, given for messagehandler require doesn't exist")
31
32
  end
32
33
 
33
34
  # Instantiate the handler named in handlerName from the file name in
@@ -38,6 +39,7 @@ module RServiceBus2
38
39
  # @param [String] handler_name name of the handler to instantiate
39
40
  # @param [String] file_path the path to the file to be loaded
40
41
  # @return [RServiceBus2::Handler] the loader
42
+ # rubocop:disable Metrics/MethodLength
41
43
  def load_handler_from_file(handler_name, file_path)
42
44
  require_path = get_require_path(file_path)
43
45
 
@@ -45,22 +47,22 @@ module RServiceBus2
45
47
  begin
46
48
  handler = Object.const_get(handler_name).new
47
49
  rescue StandardError => e
48
- puts 'Expected class name: ' + handler_name + ', not found after
49
- require: ' + require_path
50
- puts '**** Check in ' + file_path + ' that the class is named : ' +
51
- handler_name
52
- puts '( In case its not that )'
50
+ puts "Expected class name: #{handler_name}, not found after require: #{require_path}\n" \
51
+ "**** Check in #{file_path} that the class is named: #{handler_name}\n" \
52
+ '( In case its not that )'
53
53
  raise e
54
54
  end
55
55
 
56
56
  handler
57
57
  end
58
+ # rubocop:enable Metrics/MethodLength
58
59
 
59
60
  # Wrapper function
60
61
  #
61
62
  # @param [String] file_path
62
63
  # @param [String] handler_name
63
64
  # @returns [RServiceBus2::Handler] handler
65
+ # rubocop:disable Metrics/MethodLength
64
66
  def load_handler(msg_name, file_path, handler_name)
65
67
  if @list_of_loaded_paths.key?(file_path)
66
68
  RServiceBus2.log "Not reloading, #{file_path}"
@@ -68,29 +70,30 @@ module RServiceBus2
68
70
  end
69
71
 
70
72
  begin
71
- RServiceBus2.rlog 'file_path: ' + file_path
72
- RServiceBus2.rlog 'handler_name: ' + handler_name
73
+ RServiceBus2.rlog "file_path: #{file_path}"
74
+ RServiceBus2.rlog "handler_name: #{handler_name}"
73
75
 
74
76
  handler = load_handler_from_file(handler_name, file_path)
75
- RServiceBus2.log 'Loaded Handler: ' + handler_name
77
+ RServiceBus2.log "Loaded Handler: #{handler_name}"
76
78
 
77
79
  @handler_manager.add_handler(msg_name, handler)
78
80
 
79
81
  @list_of_loaded_paths[file_path] = 1
80
82
  rescue StandardError => e
81
- puts 'Exception loading handler from file: ' + file_path
83
+ puts "Exception loading handler from file: #{file_path}"
82
84
  puts e.message
83
85
  puts e.backtrace[0]
84
86
  abort
85
87
  end
86
88
  end
89
+ # rubocop:enable Metrics/MethodLength
87
90
 
88
91
  # This method is overloaded for unit tests
89
92
  #
90
93
  # @param [String] path directory to check
91
94
  # @return [Array] a list of paths to files found in the given path
92
95
  def get_list_of_files_for_dir(path)
93
- list = Dir[path + '/*']
96
+ list = Dir["#{path}/*"]
94
97
  RServiceBus2.rlog "HandlerLoader.getListOfFilesForDir. path: #{path},
95
98
  list: #{list}"
96
99
  list
@@ -105,14 +108,14 @@ module RServiceBus2
105
108
  def load_handlers_from_second_level_path(msg_name, base_dir)
106
109
  get_list_of_files_for_dir(base_dir).each do |file_path|
107
110
  next if file_path.end_with?('.')
111
+ next unless !File.directory?(file_path) && File.extname(file_path) == '.rb'
108
112
 
109
- ext_name = File.extname(file_path)
110
- if !File.directory?(file_path) && ext_name == '.rb'
111
- file_name = File.basename(file_path).sub('.rb', '')
112
- handler_name = "message_handler_#{msg_name}_#{file_name}".gsub(/(?<=_|^)(\w)/){$1.upcase}.gsub(/(?:_)(\w)/,'\1') # Classify
113
+ file_name = File.basename(file_path).sub('.rb', '')
114
+ # Classify
115
+ handler_name = "message_handler_#{msg_name}_#{file_name}"
116
+ .gsub(/(?<=_|^)(\w)/) { Regexp.last_match(1).upcase }.gsub(/(?:_)(\w)/, '\1')
113
117
 
114
- load_handler(msg_name, file_path, handler_name)
115
- end
118
+ load_handler(msg_name, file_path, handler_name)
116
119
  end
117
120
 
118
121
  self
@@ -130,22 +133,26 @@ module RServiceBus2
130
133
  # Load top level handlers from the given directory
131
134
  #
132
135
  # @param [String] baseDir directory to check - should not have trailing slash
136
+ # rubocop:disable Metrics/MethodLength
133
137
  def load_handlers_from_top_level_path(base_dir)
134
138
  RServiceBus2.rlog "HandlerLoader.loadHandlersFromTopLevelPath. baseDir: #{base_dir}"
135
139
  get_list_of_files_for_dir(base_dir).each do |file_path|
136
- unless file_path.end_with?('.')
137
- msg_name = get_msg_name(file_path)
138
- if File.directory?(file_path)
139
- load_handlers_from_second_level_path(msg_name, file_path)
140
- else
141
- handler_name = "message_handler_#{msg_name}".gsub(/(?<=_|^)(\w)/){$1.upcase}.gsub(/(?:_)(\w)/,'\1') # Classify
142
- load_handler(msg_name, file_path, handler_name)
143
- end
140
+ next if file_path.end_with?('.')
141
+
142
+ msg_name = get_msg_name(file_path)
143
+ if File.directory?(file_path)
144
+ load_handlers_from_second_level_path(msg_name, file_path)
145
+ else
146
+ # Classify
147
+ handler_name = "message_handler_#{msg_name}"
148
+ .gsub(/(?<=_|^)(\w)/) { Regexp.last_match(1).upcase }.gsub(/(?:_)(\w)/, '\1')
149
+ load_handler(msg_name, file_path, handler_name)
144
150
  end
145
151
  end
146
152
 
147
153
  self
148
154
  end
155
+ # rubocop:enable Metrics/MethodLength
149
156
 
150
157
  # Entry point for loading handlers
151
158
  #
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module RServiceBus2
2
4
  # Given a directory, this class is responsible for finding
3
5
  # msgnames,
@@ -20,10 +22,10 @@ module RServiceBus2
20
22
  # setBusAttributeIfRequested
21
23
  #
22
24
  # @param [RServiceBus2::Handler] handler
23
- def set_bus_attribute_if_requested(handler)
25
+ def conditionally_set_bus_attribute(handler)
24
26
  if defined?(handler.bus)
25
27
  handler.bus = @host
26
- RServiceBus2.log 'Bus attribute set for: ' + handler.class.name
28
+ RServiceBus2.log "Bus attribute set for: #{handler.class.name}"
27
29
  end
28
30
 
29
31
  self
@@ -32,10 +34,10 @@ module RServiceBus2
32
34
  # setStateAttributeIfRequested
33
35
  #
34
36
  # @param [RServiceBus2::Handler] handler
35
- def set_state_attribute_if_requested(handler)
37
+ def conditionally_set_state_attribute(handler)
36
38
  if defined?(handler.state)
37
39
  handler.state = @state_manager.get(handler)
38
- RServiceBus2.log 'Bus attribute set for: ' + handler.class.name
40
+ RServiceBus2.log "Bus attribute set for: #{handler.class.name}"
39
41
  end
40
42
 
41
43
  self
@@ -50,29 +52,29 @@ module RServiceBus2
50
52
  self
51
53
  end
52
54
 
55
+ # rubocop:disable Metrics/AbcSize
53
56
  def interrogate_handler_for_app_resources(handler)
54
- RServiceBus2.rlog "Checking app resources for: #{handler.class.name}"
55
- RServiceBus2.rlog "If your attribute is not getting set, check that it is in the 'attr_accessor' list"
57
+ RServiceBus2.rlog "Checking app resources for: #{handler.class.name}\n" \
58
+ "If your attribute is not getting set, check that it is in the 'attr_accessor' list"
56
59
 
57
60
  @resource_list_by_handler_name[handler.class.name] = []
58
- @resource_manager.get_all.each do |k, v|
61
+ @resource_manager.all.each do |k, _v|
59
62
  next unless handler.class.method_defined?(k)
60
63
 
61
64
  @resource_list_by_handler_name[handler.class.name] << k
62
- RServiceBus2.log "Resource attribute, #{k}, found for: " +
63
- handler.class.name
65
+ RServiceBus2.log "Resource attribute, #{k}, found for: #{handler.class.name}"
64
66
  end
65
-
66
- self
67
67
  end
68
+ # rubocop:enable Metrics/AbcSize
68
69
 
69
70
  def add_handler(lc_msg_name, handler)
70
- msg_name = lc_msg_name.gsub(/(?<=_|^)(\w)/){$1.upcase}.gsub(/(?:_)(\w)/,'\1') # Turn snake_case string to CamelCase
71
+ # Turn snake_case string to CamelCase
72
+ msg_name = lc_msg_name.gsub(/(?<=_|^)(\w)/) { Regexp.last_match(1).upcase }.gsub(/(?:_)(\w)/, '\1')
71
73
  @handler_list[msg_name] = [] if @handler_list[msg_name].nil?
72
- return unless @handler_list[msg_name].index{ |x| x.class.name == handler.class.name }.nil?
74
+ return unless @handler_list[msg_name].index { |x| x.instance_of(handler) }.nil?
73
75
 
74
76
  @handler_list[msg_name] << handler
75
- set_bus_attribute_if_requested(handler)
77
+ conditionally_set_bus_attribute(handler)
76
78
  check_if_state_attribute_requested(handler)
77
79
  interrogate_handler_for_app_resources(handler)
78
80
  end
@@ -86,28 +88,32 @@ module RServiceBus2
86
88
 
87
89
  list = []
88
90
  @handler_list[msg_name].each do |handler|
89
- list = list + @resource_list_by_handler_name[handler.class.name] unless @resource_list_by_handler_name[handler.class.name].nil?
91
+ unless @resource_list_by_handler_name[handler.class.name].nil?
92
+ list += @resource_list_by_handler_name[handler.class.name]
93
+ end
90
94
  end
91
95
  list.uniq!
92
96
  end
93
97
 
94
- def set_resources_for_handlers_needed_to_process_msg(msg_name)
98
+ # rubocop:disable Metrics/AbcSize
99
+ def conditionally_set_resources_for_handlers(msg_name)
95
100
  @handler_list[msg_name].each do |handler|
96
- set_state_attribute_if_requested(handler)
97
-
101
+ conditionally_set_state_attribute(handler)
98
102
  next if @resource_list_by_handler_name[handler.class.name].nil?
103
+
99
104
  @resource_list_by_handler_name[handler.class.name].each do |k|
100
105
  handler.instance_variable_set("@#{k}", @resource_manager.get(k).get_resource)
101
- RServiceBus2.rlog "App resource attribute, #{k}, set for: " + handler.class.name
106
+ RServiceBus2.rlog "App resource attribute, #{k}, set for: #{handler.class.name}"
102
107
  end
103
108
  end
104
109
  end
110
+ # rubocop:enable Metrics/AbcSize
105
111
 
106
112
  def get_handler_list_for_msg(msg_name)
107
113
  return [] if @handler_list[msg_name].nil?
108
114
 
109
- list = get_list_of_resources_needed_to_process_msg(msg_name)
110
- set_resources_for_handlers_needed_to_process_msg(msg_name)
115
+ # list = get_list_of_resources_needed_to_process_msg(msg_name)
116
+ conditionally_set_resources_for_handlers(msg_name)
111
117
 
112
118
  @handler_list[msg_name]
113
119
  end
@@ -116,16 +122,16 @@ module RServiceBus2
116
122
  @handler_list.key?(msg_name)
117
123
  end
118
124
 
119
- def get_stats
125
+ def stats
120
126
  list = []
121
- @handler_list.each do |k, v|
127
+ @handler_list.each do |_k, v|
122
128
  list << v.inspect
123
129
  end
124
130
 
125
131
  list
126
132
  end
127
133
 
128
- def get_list_of_msg_names
134
+ def msg_names
129
135
  @handler_list.keys
130
136
  end
131
137
  end
@@ -74,7 +74,7 @@ module RServiceBus2
74
74
  def send_subscriptions
75
75
  log 'Send Subscriptions'
76
76
 
77
- @endpoint_mapping.get_subscription_endpoints.each do |event_name|
77
+ @endpoint_mapping.subscription_endpoints.each do |event_name|
78
78
  subscribe(event_name)
79
79
  end
80
80
 
@@ -109,7 +109,7 @@ module RServiceBus2
109
109
 
110
110
  # Thin veneer for Configuring Cron
111
111
  def configure_cron_manager
112
- @cron_manager = CronManager.new(self, @handler_manager.get_list_of_msg_names)
112
+ @cron_manager = CronManager.new(self, @handler_manager.msg_names)
113
113
  self
114
114
  end
115
115
 
@@ -0,0 +1,51 @@
1
+ require 'aws-sdk-s3'
2
+
3
+ module RServiceBus2
4
+ # Monitor S3 Bucket for objects
5
+ class MonitorAWSS3 < Monitor
6
+ def connect(uri)
7
+ @bucket_name = uri.path
8
+ @bucket_name[0] = ''
9
+
10
+ @region = uri.host
11
+
12
+ @s3_client = Aws::S3::Client.new(region: @region)
13
+ @input_filter = []
14
+ end
15
+
16
+ def process_content(content)
17
+ content
18
+ end
19
+
20
+ def process_path(object_key)
21
+ # content = read_content_from_object(object_key)
22
+ resp = @s3_client.get_object(bucket: @bucket_name, key: object_key)
23
+
24
+ # call #read or #string on the response body
25
+ content = resp.body.read
26
+ payload = process_content(content)
27
+
28
+ send(payload, URI.parse(CGI.escape("s3://#{@region}/#{@bucket_name}/#{object_key}")))
29
+
30
+ @s3_client.delete_object({ bucket: @bucket_name, key: object_key })
31
+
32
+ content
33
+ end
34
+
35
+ def look
36
+ file_processed = 0
37
+ max_files_processed = 2
38
+
39
+ objects = @s3_client.list_objects_v2( bucket: @bucket_name, max_keys: max_files_processed).contents
40
+
41
+ objects.each do |object|
42
+ RServiceBus2.log "Ready to process, #{object.key}"
43
+ process_path(object.key)
44
+
45
+ file_processed += 1
46
+ RServiceBus2.log "Processed #{file_processed} of #{objects.length}."
47
+ RServiceBus2.log "Allow system tick #{self.class.name}"
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,32 @@
1
+ require 'aws-sdk-sqs'
2
+ require 'aws-sdk-sts'
3
+
4
+ module RServiceBus2
5
+ # Monitor S3 Bucket for objects
6
+ class MonitorAWSSQS < Monitor
7
+ def connect(uri)
8
+ queue_name = uri.path.sub('/', '')
9
+
10
+ region = uri.host
11
+
12
+ sts_client = Aws::STS::Client.new(region: region)
13
+ caller_identity_account = sts_client.get_caller_identity.account
14
+
15
+ @queue_url = "https://sqs.#{region}.amazonaws.com/" +
16
+ "#{caller_identity_account}/#{queue_name}"
17
+ @sqs_client = Aws::SQS::Client.new(region: region)
18
+ end
19
+
20
+ def look
21
+ # TODO make max available as env variable
22
+ response = @sqs_client.receive_message(queue_url: @queue_url, max_number_of_messages: 1)
23
+ response.messages.each do |message|
24
+ send(message.body, URI.parse(CGI.escape(@queue_url)))
25
+ @sqs_client.delete_message({
26
+ queue_url: @queue_url,
27
+ receipt_handle: message.receipt_handle
28
+ })
29
+ end
30
+ end
31
+ end
32
+ end
@@ -23,7 +23,7 @@ module RServiceBus2
23
23
  RServiceBus2.rlog "Checking app resources for: #{monitor.class.name}"
24
24
  RServiceBus2.rlog "If your attribute is not getting set, check that it is
25
25
  in the 'attr_accessor' list"
26
- @resource_manager.get_all.each do |k, v|
26
+ @resource_manager.all.each do |k, v|
27
27
  next unless monitor.class.method_defined?(k)
28
28
 
29
29
  monitor.instance_variable_set("@#{k}", v.get_resource)
@@ -48,6 +48,12 @@ module RServiceBus2
48
48
  when 'dir'
49
49
  require 'rservicebus2/monitor/dir'
50
50
  monitor = MonitorDir.new(@host, name, uri)
51
+ when 'awss3'
52
+ require 'rservicebus2/monitor/awss3'
53
+ monitor = MonitorAWSS3.new(@host, name, uri)
54
+ when 'awssqs'
55
+ require 'rservicebus2/monitor/awssqs'
56
+ monitor = MonitorAWSSQS.new(@host, name, uri)
51
57
  when 'dirnotifier'
52
58
  require 'rservicebus2/monitor/dirnotifier'
53
59
  monitor = MonitorDirNotifier.new(@host, name, uri)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module RServiceBus2
2
4
  # Coordinate Transactions across resources, handlers, and Sagas
3
5
  class ResourceManager
@@ -13,7 +15,7 @@ module RServiceBus2
13
15
  @app_resources[name] = res
14
16
  end
15
17
 
16
- def get_all
18
+ def all
17
19
  @app_resources
18
20
  end
19
21
 
@@ -37,9 +39,8 @@ module RServiceBus2
37
39
  def commit(msg_name)
38
40
  @state_manager.commit
39
41
  @saga_storage.commit
40
- RServiceBus2.rlog "HandlerManager.commitResourcesUsedToProcessMsg,
41
- #{msg_name}"
42
- @current_resources.each do |k, v|
42
+ RServiceBus2.rlog "HandlerManager.commitResourcesUsedToProcessMsg, #{msg_name}"
43
+ @current_resources.each do |_k, v|
43
44
  RServiceBus2.rlog "Commit resource, #{v.class.name}"
44
45
  v.commit
45
46
  v.finished
@@ -48,21 +49,15 @@ module RServiceBus2
48
49
 
49
50
  def rollback(msg_name)
50
51
  @saga_storage.rollback
51
- RServiceBus2.rlog "HandlerManager.rollbackResourcesUsedToProcessMsg,
52
- #{msg_name}"
53
- @current_resources.each do |k, v|
54
- begin
55
- RServiceBus2.rlog "Rollback resource, #{v.class.name}"
56
- v.rollback
57
- v.finished
58
- rescue StandardError => e1
59
- puts "Caught nested exception rolling back, #{v.class.name}, for msg,
60
- #{msg_name}"
61
- puts '****'
62
- puts e1.message
63
- puts e1.backtrace
64
- puts '****'
65
- end
52
+ RServiceBus2.rlog "HandlerManager.rollbackResourcesUsedToProcessMsg, #{msg_name}"
53
+ @current_resources.each do |_k, v|
54
+ RServiceBus2.rlog "Rollback resource, #{v.class.name}"
55
+ v.rollback
56
+ v.finished
57
+ rescue StandardError => e
58
+ puts "Caught nested exception rolling back, #{v.class.name}, for msg,
59
+ #{msg_name}"
60
+ puts "****\n#{e.message}\n#{e.backtrace}\n'****"
66
61
  end
67
62
  end
68
63
  end
@@ -44,7 +44,7 @@ module RServiceBus2
44
44
  is in the 'attr_accessor' list"
45
45
 
46
46
  @resource_list_by_saga_name[saga.class.name] = []
47
- @resource_manager.get_all.each do |k, v|
47
+ @resource_manager.all.each do |k, v|
48
48
  if saga.class.method_defined?(k)
49
49
  @resource_list_by_saga_name[saga.class.name] << k
50
50
  RServiceBus2.log "Resource attribute, #{k}, found for: " +
metadata CHANGED
@@ -1,85 +1,85 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rservicebus2
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.2.8
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-04-25 00:00:00.000000000 Z
11
+ date: 2021-05-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: uuidtools
14
+ name: beanstalk-client
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 2.2.0
19
+ version: 1.1.1
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 2.2.0
26
+ version: 1.1.1
27
27
  - !ruby/object:Gem::Dependency
28
- name: json
28
+ name: fluiddb
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 2.5.1
33
+ version: 0.1.19
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 2.5.1
40
+ version: 0.1.19
41
41
  - !ruby/object:Gem::Dependency
42
- name: beanstalk-client
42
+ name: json
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: 1.1.1
47
+ version: 2.5.1
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: 1.1.1
54
+ version: 2.5.1
55
55
  - !ruby/object:Gem::Dependency
56
- name: fluiddb
56
+ name: parse-cron
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: 0.1.19
61
+ version: 0.1.4
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: 0.1.19
68
+ version: 0.1.4
69
69
  - !ruby/object:Gem::Dependency
70
- name: parse-cron
70
+ name: uuidtools
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: 0.1.4
75
+ version: 2.2.0
76
76
  type: :runtime
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: 0.1.4
82
+ version: 2.2.0
83
83
  description: A Ruby interpretation of NServiceBus
84
84
  email: guy@guyirvine.com
85
85
  executables:
@@ -104,6 +104,9 @@ files:
104
104
  - lib/rservicebus2.rb
105
105
  - lib/rservicebus2/agent.rb
106
106
  - lib/rservicebus2/appresource.rb
107
+ - lib/rservicebus2/appresource/awsdynamodb.rb
108
+ - lib/rservicebus2/appresource/awss3.rb
109
+ - lib/rservicebus2/appresource/awssqs.rb
107
110
  - lib/rservicebus2/appresource/dir.rb
108
111
  - lib/rservicebus2/appresource/file.rb
109
112
  - lib/rservicebus2/appresource/fluiddb.rb
@@ -124,6 +127,8 @@ files:
124
127
  - lib/rservicebus2/message/subscription.rb
125
128
  - lib/rservicebus2/message/verboseoutput.rb
126
129
  - lib/rservicebus2/monitor.rb
130
+ - lib/rservicebus2/monitor/awss3.rb
131
+ - lib/rservicebus2/monitor/awssqs.rb
127
132
  - lib/rservicebus2/monitor/dir.rb
128
133
  - lib/rservicebus2/monitor/dirnotifier.rb
129
134
  - lib/rservicebus2/monitor/message.rb