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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0f841d7999ff2bf99c3e9d019b5ccfdb7ba0d6263d48adea655175cdc3b39569
4
- data.tar.gz: 2729e4af16616823950a1aaf5e49206c77c95567049c3f5dd956b347ef90b7ab
3
+ metadata.gz: 31500216aa7e9c86af5f6ec88557ee0aa2f242bffd4d94ab09d9ebf80fcb8e68
4
+ data.tar.gz: bab1c226bcad2e1e4b890cdf48ee88f10a9d801ccf1e39a1473881b91f5de57f
5
5
  SHA512:
6
- metadata.gz: fe5a26882d6515bb1731cc3aa3f38446c7cdbc09698cb9091cc0a8b4125ec2939e41d05cd27b4293f74f00405c027a98a01fc3c7db8c9737b762fee97a4653c2
7
- data.tar.gz: 1653165f74ef1e4e22e0bb75500a6aa5d8f17cc2879e2d08945f43366072f552fb8babe579c28d393f0f94e9db774e7b65399178893fd86ce5d878fc35a0cace
6
+ metadata.gz: 1df32f70805935baf2f3029955701b65d83caf330ee4f12f02f95267c880337d4dadcdfe086fe1990fb9de0e917a1bc8fd86feb4c48bcf8d194f8aee0f92bf2e
7
+ data.tar.gz: 1b926db41aad313ae52542933c5932d2237451eeac398d5841315419b061afb16c37035687d1fb373817fece679b74ccb1d38601a0307d5fb63c087e24b10f6a
@@ -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::Message.new(status: :error)
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::Message.new(status: :error, body: CONSUMER_COUNT_ZERO)
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::Message.new(status: true)
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::Message.new(status: :error, body: PUBLISH_TIMEOUT, exception: e)
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::Message.new(status: :error, body: BOMBA, exception: e)
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::Message.new(status: :success)
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::Message.new(status: :error, body: BOMBA, exception: e)
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::Message.new(status: :error, body: CONSUMER_TIMEOUT, exception: e)
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::Message.new(status: :error, body: BOMBA, exception: e)
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
@@ -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"
@@ -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
- logger&.debug('Stablish new connection to rabbit')
85
- logger&.debug("amqp://#{ENV['RABBIT_USER']}:" \
86
- "#{ENV['RABBIT_PASS']}@#{ENV['RABBIT_HOST']}" \
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, # 20.seconds per connection
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
- rabbit_conn = Bunny.new("amqp://#{ENV['RABBIT_USER']}" \
100
- ":#{ENV['RABBIT_PASS']}@"\
101
- "#{ENV['RABBIT_HOST']}/"\
102
- "#{ENV['RABBIT_VIRTUAL_HOST']}",
103
- options)
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module BugBunny
4
- VERSION = "0.2.4"
4
+ VERSION = "1.0.0"
5
5
  end
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.2.4
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: 2024-09-30 00:00:00.000000000 Z
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.4.1
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: []