rabbit_carrots 1.0.1 → 1.0.2

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: a55e06c9742638b1eb1a44d65d98031f5c366adddd3fcb196064075f0c32eb30
4
- data.tar.gz: 499acd59987bb9a6d4548c444e0829117ecc16289c719461e0b5e3be255df02c
3
+ metadata.gz: 512be53850324ba32bfdf38f6069561fb4cff9cd3e21c7acd3f431ade7533603
4
+ data.tar.gz: 297df24712a1eed2dd55902845ade84a1d44b714f69c75a1ac97be98baf15de8
5
5
  SHA512:
6
- metadata.gz: 99f30870c37f1d334673fd6b6d5083cd4b2d4af419384590c204db60cddf6f16993582eeecdcf924a97302b13f5713772bdb9554d2d86757625c9aa689cd3456
7
- data.tar.gz: 29586c246e82ab514b1fb8de9ffc4013865fa7e72ee07e6ddfec86fb7a4084c597272b1809b90708dab793325f5ff4c7129fcc79d301a743ae4238e2d60bad23
6
+ metadata.gz: 260c156c6794fc7b3c92ccd1f946c47e3ad004c01ec15f0bdd1875812d030a4d3983b67ed6106041370e97840db22da65afac2fe17d682cc97267ac926a17c2c
7
+ data.tar.gz: 7ddc79c2c86c6db3fda8f3ec20cd9cac7750b054c01a0a96837ff9a02af5290e774718c6bb7b54d520fd3fd972a9e1bba5c614fa530c0cbb98f5f06542aa3ed8
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rabbit_carrots (1.0.1)
4
+ rabbit_carrots (1.0.2)
5
5
  bunny (>= 2.22)
6
6
  connection_pool (~> 2.4)
7
7
 
@@ -18,6 +18,10 @@ module RabbitCarrots
18
18
  :rabbitmq_exchange_name,
19
19
  :automatically_recover,
20
20
  :network_recovery_interval,
21
- :recovery_attempts
21
+ :recovery_attempts,
22
+ :orm
23
+ def orm
24
+ @orm ||= :activerecord
25
+ end
22
26
  end
23
27
  end
@@ -2,9 +2,13 @@ module RabbitCarrots
2
2
  class Core
3
3
  attr_reader :logger
4
4
 
5
- DatabaseAgonsticNotNullViolation = defined?(ActiveRecord) ? ActiveRecord::NotNullViolation : RabbitCarrots::EventHandlers::Errors::PlaceholderError
6
- DatabaseAgonsticConnectionNotEstablished = defined?(ActiveRecord) ? ActiveRecord::ConnectionNotEstablished : Mongo::Error::SocketError
7
- DatabaseAgnosticRecordInvalid = defined?(ActiveRecord) ? ActiveRecord::RecordInvalid : Mongoid::Errors::Validations
5
+ @database_agnostic_not_null_violation = nil
6
+ @database_agnostic_connection_not_established = nil
7
+ @database_agnostic_record_invalid = nil
8
+
9
+ class << self
10
+ attr_accessor :database_agnostic_not_null_violation, :database_agnostic_connection_not_established, :database_agnostic_record_invalid
11
+ end
8
12
 
9
13
  def initialize(logger: nil)
10
14
  @logger = logger || Logger.new(Rails.env.production? ? '/proc/self/fd/1' : $stdout)
@@ -14,6 +18,10 @@ module RabbitCarrots
14
18
  end
15
19
 
16
20
  def start(kill_to_restart_on_standard_error: false)
21
+ self.class.database_agnostic_not_null_violation = RabbitCarrots.configuration.orm == :activerecord ? ActiveRecord::NotNullViolation : RabbitCarrots::EventHandlers::Errors::PlaceholderError
22
+ self.class.database_agnostic_connection_not_established = RabbitCarrots.configuration.orm == :activerecord ? ActiveRecord::ConnectionNotEstablished : ::Mongo::Error::SocketError
23
+ self.class.database_agnostic_record_invalid = RabbitCarrots.configuration.orm == :activerecord ? ActiveRecord::RecordInvalid : ::Mongoid::Errors::Validations
24
+
17
25
  channels = RabbitCarrots.configuration.routing_key_mappings.map do |mapping|
18
26
  { **mapping, handler: mapping[:handler].constantize }
19
27
  end
@@ -89,10 +97,10 @@ module RabbitCarrots
89
97
  rescue RabbitCarrots::EventHandlers::Errors::NackAndRequeueMessage => _e
90
98
  logger.log "Nacked and Requeued message: #{payload}"
91
99
  channel.nack(delivery_info.delivery_tag, false, true)
92
- rescue DatabaseAgonsticNotNullViolation, DatabaseAgnosticRecordInvalid => e
100
+ rescue self.class.database_agnostic_not_null_violation, self.class.database_agnostic_record_invalid => e
93
101
  logger.log "Null constraint or Invalid violation: #{payload}. Error: #{e.message}"
94
102
  channel.ack(delivery_info.delivery_tag, false)
95
- rescue DatabaseAgonsticConnectionNotEstablished => e
103
+ rescue self.class.database_agnostic_connection_not_established => e
96
104
  logger.log "Error connection not established to the database: #{payload}. Error: #{e.message}"
97
105
  sleep 3
98
106
  channel.nack(delivery_info.delivery_tag, false, true)
@@ -102,8 +110,6 @@ module RabbitCarrots
102
110
  channel.nack(delivery_info.delivery_tag, false, true)
103
111
  Process.kill('SIGTERM', Process.pid) if kill_to_restart_on_standard_error
104
112
  end
105
-
106
- logger.log "Ending task for queue: #{queue_name}"
107
113
  end
108
114
  rescue StandardError => e
109
115
  logger.error "Bunny session error: #{e.message}"
@@ -0,0 +1,18 @@
1
+ module RabbitCarrots
2
+ class Error < StandardError; end
3
+
4
+ module EventHandlers
5
+ module Errors
6
+ class IrrelevantMessage < StandardError
7
+ end
8
+
9
+ class NackMessage < StandardError
10
+ end
11
+
12
+ class NackAndRequeueMessage < StandardError
13
+ end
14
+
15
+ class PlaceholderError < Error; end
16
+ end
17
+ end
18
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RabbitCarrots
4
- VERSION = '1.0.1'
4
+ VERSION = '1.0.2'
5
5
  end
@@ -1,26 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative 'rabbit_carrots/version'
4
+ require 'rabbit_carrots/errors'
4
5
  require 'rabbit_carrots/connection'
5
- require 'rabbit_carrots/core'
6
6
  require 'rabbit_carrots/configuration'
7
7
  require 'rabbit_carrots/railtie' if defined?(Rails)
8
+ require 'rabbit_carrots/core'
8
9
 
9
10
  module RabbitCarrots
10
- class Error < StandardError; end
11
-
12
- module EventHandlers
13
- module Errors
14
- class IrrelevantMessage < StandardError
15
- end
16
-
17
- class NackMessage < StandardError
18
- end
19
-
20
- class NackAndRequeueMessage < StandardError
21
- end
22
-
23
- class PlaceholderError < Error; end
24
- end
25
- end
26
11
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rabbit_carrots
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brusk Awat
@@ -59,6 +59,7 @@ files:
59
59
  - lib/rabbit_carrots/configuration.rb
60
60
  - lib/rabbit_carrots/connection.rb
61
61
  - lib/rabbit_carrots/core.rb
62
+ - lib/rabbit_carrots/errors.rb
62
63
  - lib/rabbit_carrots/railtie.rb
63
64
  - lib/rabbit_carrots/tasks/rmq.rake
64
65
  - lib/rabbit_carrots/version.rb