rservicebus2 0.2.4 → 0.2.9

Sign up to get free protection for your applications and to get access to all the features.
@@ -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,10 +23,10 @@ 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
- monitor.instance_variable_set("@#{k}", v.get_resource)
29
+ monitor.instance_variable_set("@#{k}", v.resource)
30
30
  @resource_list[monitor.class.name] = [] if
31
31
  @resource_list[monitor.class.name].nil?
32
32
  @resource_list[monitor.class.name] << v
@@ -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: " +
@@ -76,7 +76,7 @@ module RServiceBus2
76
76
  return if @resource_list_by_saga_name[saga.class.name].nil?
77
77
 
78
78
  @resource_list_by_saga_name[saga.class.name].each do |k, v|
79
- saga.instance_variable_set("@#{k}", @resource_manager.get(k).get_resource)
79
+ saga.instance_variable_set("@#{k}", @resource_manager.get(k).resource)
80
80
  RServiceBus2.rlog "App resource attribute, #{k}, set for: " + saga.class.name
81
81
  end
82
82
  end
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.4
4
+ version: 0.2.9
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-27 00:00:00.000000000 Z
11
+ date: 2021-05-11 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:
@@ -105,6 +105,8 @@ files:
105
105
  - lib/rservicebus2/agent.rb
106
106
  - lib/rservicebus2/appresource.rb
107
107
  - lib/rservicebus2/appresource/awsdynamodb.rb
108
+ - lib/rservicebus2/appresource/awss3.rb
109
+ - lib/rservicebus2/appresource/awssqs.rb
108
110
  - lib/rservicebus2/appresource/dir.rb
109
111
  - lib/rservicebus2/appresource/file.rb
110
112
  - lib/rservicebus2/appresource/fluiddb.rb
@@ -125,6 +127,8 @@ files:
125
127
  - lib/rservicebus2/message/subscription.rb
126
128
  - lib/rservicebus2/message/verboseoutput.rb
127
129
  - lib/rservicebus2/monitor.rb
130
+ - lib/rservicebus2/monitor/awss3.rb
131
+ - lib/rservicebus2/monitor/awssqs.rb
128
132
  - lib/rservicebus2/monitor/dir.rb
129
133
  - lib/rservicebus2/monitor/dirnotifier.rb
130
134
  - lib/rservicebus2/monitor/message.rb