bug_bunny 0.2.4 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/bug_bunny/adapter.rb +9 -9
- data/lib/bug_bunny/config.rb +11 -0
- data/lib/bug_bunny/exception.rb +9 -1
- data/lib/bug_bunny/rabbit.rb +13 -16
- data/lib/bug_bunny/version.rb +1 -1
- data/lib/bug_bunny.rb +13 -0
- metadata +4 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 31500216aa7e9c86af5f6ec88557ee0aa2f242bffd4d94ab09d9ebf80fcb8e68
|
4
|
+
data.tar.gz: bab1c226bcad2e1e4b890cdf48ee88f10a9d801ccf1e39a1473881b91f5de57f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1df32f70805935baf2f3029955701b65d83caf330ee4f12f02f95267c880337d4dadcdfe086fe1990fb9de0e917a1bc8fd86feb4c48bcf8d194f8aee0f92bf2e
|
7
|
+
data.tar.gz: 1b926db41aad313ae52542933c5932d2237451eeac398d5841315419b061afb16c37035687d1fb373817fece679b74ccb1d38601a0307d5fb63c087e24b10f6a
|
data/lib/bug_bunny/adapter.rb
CHANGED
@@ -21,7 +21,7 @@ module BugBunny
|
|
21
21
|
|
22
22
|
def initialize(attrs = {})
|
23
23
|
@logger = Logger.new('./log/bug_bunny.log', 'monthly')
|
24
|
-
@communication_response = ::BugBunny::
|
24
|
+
@communication_response = ::BugBunny::Response.new status: false
|
25
25
|
@time_to_wait = 2
|
26
26
|
create_adapter_with_rabbit
|
27
27
|
end
|
@@ -29,7 +29,7 @@ module BugBunny
|
|
29
29
|
def publish!(message, publish_queue, opts = {})
|
30
30
|
Timeout::timeout(TIMEOUT) do
|
31
31
|
if opts[:check_consumers_count] && publish_queue.check_consumers.zero?
|
32
|
-
self.communication_response = ::BugBunny::
|
32
|
+
self.communication_response = ::BugBunny::Response.new(status: false, response: CONSUMER_COUNT_ZERO)
|
33
33
|
return
|
34
34
|
end
|
35
35
|
|
@@ -51,16 +51,16 @@ module BugBunny
|
|
51
51
|
rabbit.exchange.publish(message.to_json, publish_opts)
|
52
52
|
rabbit.channel.wait_for_confirms if rabbit.confirm_select
|
53
53
|
|
54
|
-
self.communication_response = ::BugBunny::
|
54
|
+
self.communication_response = ::BugBunny::Response.new(status: true)
|
55
55
|
end
|
56
56
|
rescue Timeout::Error => e
|
57
57
|
logger.error(e)
|
58
58
|
close_connection!
|
59
|
-
self.communication_response = ::BugBunny::
|
59
|
+
self.communication_response = ::BugBunny::Response.new(status: false, response: PUBLISH_TIMEOUT, exception: e)
|
60
60
|
rescue StandardError => e
|
61
61
|
logger.error(e)
|
62
62
|
close_connection!
|
63
|
-
self.communication_response = ::BugBunny::
|
63
|
+
self.communication_response = ::BugBunny::Response.new(status: false, response: BOMBA, exception: e)
|
64
64
|
end
|
65
65
|
|
66
66
|
def consume!(queue, thread: false, manual_ack: true, exclusive: false, block: true, opts: {})
|
@@ -124,7 +124,7 @@ module BugBunny
|
|
124
124
|
end
|
125
125
|
|
126
126
|
self.service_message = message
|
127
|
-
self.communication_response = ::BugBunny::
|
127
|
+
self.communication_response = ::BugBunny::Response.new(status: true)
|
128
128
|
rescue ::SystemExit => e # Ensure exit code
|
129
129
|
raise e
|
130
130
|
rescue => e
|
@@ -134,7 +134,7 @@ module BugBunny
|
|
134
134
|
close_connection!
|
135
135
|
|
136
136
|
# Session.clean!
|
137
|
-
self.communication_response = ::BugBunny::
|
137
|
+
self.communication_response = ::BugBunny::Response.new(status: false, response: BOMBA, exception: e)
|
138
138
|
end
|
139
139
|
|
140
140
|
if thread # sync consumer flag :D
|
@@ -190,12 +190,12 @@ module BugBunny
|
|
190
190
|
logger.debug("Rabbit Identifier: #{rabbit.try(:identifier)}")
|
191
191
|
logger.error(e)
|
192
192
|
close_connection!
|
193
|
-
::BugBunny::
|
193
|
+
::BugBunny::Response.new(status: false, response: CONSUMER_TIMEOUT, exception: e)
|
194
194
|
rescue StandardError => e
|
195
195
|
logger.debug("Rabbit Identifier: #{rabbit.try(:identifier)}")
|
196
196
|
logger.error(e)
|
197
197
|
close_connection!
|
198
|
-
::BugBunny::
|
198
|
+
::BugBunny::Response.new(status: false, response: BOMBA, exception: e)
|
199
199
|
end
|
200
200
|
|
201
201
|
def publish_and_consume!(publish_message, sync_queue, opts={})
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module BugBunny
|
2
|
+
class Config
|
3
|
+
# getter y setter para cada propiedad.
|
4
|
+
attr_accessor :user, :pass, :host, :virtual_host, :logger, :log_level
|
5
|
+
|
6
|
+
# Método para generar la URL de conexión
|
7
|
+
def url
|
8
|
+
"amqp://#{user}:#{pass}@#{host}/#{virtual_host}"
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
data/lib/bug_bunny/exception.rb
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
module BugBunny
|
2
2
|
class Exception
|
3
|
-
|
4
3
|
class ServiceError < StandardError
|
5
4
|
def to_s
|
6
5
|
:service_error
|
@@ -37,6 +36,15 @@ module BugBunny
|
|
37
36
|
end
|
38
37
|
end
|
39
38
|
|
39
|
+
class WithOutConsumer < StandardError
|
40
|
+
attr_accessor :backtrace
|
41
|
+
|
42
|
+
def initialize(msg, backtrace)
|
43
|
+
@backtrace = backtrace
|
44
|
+
super(msg)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
40
48
|
class RetryWithoutError < StandardError
|
41
49
|
def to_s
|
42
50
|
"retry_sidekiq_without_error"
|
data/lib/bug_bunny/rabbit.rb
CHANGED
@@ -68,8 +68,6 @@ module BugBunny
|
|
68
68
|
# status = :open, :connected, :connecting,
|
69
69
|
# :closing, :disconnected, :not_connected, :closed
|
70
70
|
def create_connection
|
71
|
-
options = {}
|
72
|
-
|
73
71
|
# if WisproUtils::Config.defaults.use_tls
|
74
72
|
# path = (Rails.root.join('private', 'certs') rescue './private/certs')
|
75
73
|
# options.merge!(tls: true,
|
@@ -80,28 +78,27 @@ module BugBunny
|
|
80
78
|
# tls_key: "#{path}/key.pem",
|
81
79
|
# tls_ca_certificates: ["#{path}/ca.pem"])
|
82
80
|
# end
|
81
|
+
options = {}
|
83
82
|
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
"/#{ENV['RABBIT_VIRTUAL_HOST']}")
|
83
|
+
raise "Need user" if BugBunny.configuration.user.blank?
|
84
|
+
raise "Need pass" if BugBunny.configuration.pass.blank?
|
85
|
+
raise "Need host" if BugBunny.configuration.host.blank?
|
88
86
|
|
87
|
+
bunny_logger = BugBunny.configuration.logger || ::Logger.new('./log/bunny.log', 7, 10485760)
|
88
|
+
bunny_logger.level = BugBunny.configuration.log_level || ::Logger::INFO
|
89
89
|
|
90
|
-
bunny_logger = ::Logger.new('./log/bunny.log', 7, 10485760)
|
91
|
-
bunny_logger.level = ::Logger::DEBUG
|
92
90
|
options.merge!(
|
93
|
-
heartbeat_interval: 20,
|
91
|
+
heartbeat_interval: 20, # 20.seconds per connection
|
94
92
|
logger: bunny_logger,
|
95
93
|
# Override bunny client_propierties
|
96
|
-
client_properties: { product: identifier, platform: ''}
|
94
|
+
client_properties: { product: identifier, platform: '' }
|
97
95
|
)
|
98
96
|
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
rabbit_conn.start
|
97
|
+
logger&.debug('Stablish new connection to rabbit')
|
98
|
+
logger&.debug(BugBunny.configuration.url)
|
99
|
+
|
100
|
+
Bunny.new(BugBunny.configuration.url, options).start
|
101
|
+
|
105
102
|
logger&.debug("New status connection: #{rabbit_conn.status}")
|
106
103
|
|
107
104
|
self.connection = rabbit_conn
|
data/lib/bug_bunny/version.rb
CHANGED
data/lib/bug_bunny.rb
CHANGED
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
require 'bunny'
|
4
4
|
require_relative "bug_bunny/version"
|
5
|
+
require_relative "bug_bunny/config"
|
5
6
|
require_relative "bug_bunny/adapter"
|
6
7
|
require_relative "bug_bunny/controller"
|
7
8
|
require_relative "bug_bunny/exception"
|
@@ -18,4 +19,16 @@ if defined? ::Rails::Railtie
|
|
18
19
|
end
|
19
20
|
|
20
21
|
module BugBunny
|
22
|
+
class << self
|
23
|
+
# Aquí guardaremos la instancia de la configuración
|
24
|
+
def configuration
|
25
|
+
@configuration ||= BugBunny::Config.new
|
26
|
+
end
|
27
|
+
|
28
|
+
# Este es el método que usaremos para configurar.
|
29
|
+
# Recibe un bloque de código y le pasa el objeto de configuración.
|
30
|
+
def configure
|
31
|
+
yield(configuration) if block_given?
|
32
|
+
end
|
33
|
+
end
|
21
34
|
end
|
metadata
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bug_bunny
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- gabix
|
8
|
-
autorequire:
|
9
8
|
bindir: exe
|
10
9
|
cert_chain: []
|
11
|
-
date:
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
12
11
|
dependencies:
|
13
12
|
- !ruby/object:Gem::Dependency
|
14
13
|
name: bunny
|
@@ -51,6 +50,7 @@ files:
|
|
51
50
|
- Rakefile
|
52
51
|
- lib/bug_bunny.rb
|
53
52
|
- lib/bug_bunny/adapter.rb
|
53
|
+
- lib/bug_bunny/config.rb
|
54
54
|
- lib/bug_bunny/controller.rb
|
55
55
|
- lib/bug_bunny/exception.rb
|
56
56
|
- lib/bug_bunny/helpers.rb
|
@@ -68,7 +68,6 @@ metadata:
|
|
68
68
|
homepage_uri: https://github.com/gedera/bug_bunny
|
69
69
|
source_code_uri: https://github.com/gedera/bug_bunny
|
70
70
|
changelog_uri: https://github.com/gedera/bug_bunny/blob/main/CHANGELOG.md
|
71
|
-
post_install_message:
|
72
71
|
rdoc_options: []
|
73
72
|
require_paths:
|
74
73
|
- lib
|
@@ -83,8 +82,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
83
82
|
- !ruby/object:Gem::Version
|
84
83
|
version: '0'
|
85
84
|
requirements: []
|
86
|
-
rubygems_version: 3.
|
87
|
-
signing_key:
|
85
|
+
rubygems_version: 3.6.9
|
88
86
|
specification_version: 4
|
89
87
|
summary: Gem for sync and async comunication via rabbit bunny.
|
90
88
|
test_files: []
|