rabbit_carrots 1.0.0 → 1.0.2

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: 5041ccacc59130b82ec1059d5b1f2803e3ef6f7a0ac3e09cbe8120a52c6071ee
4
- data.tar.gz: 25fa5dbb545b6217a6c9a74c1ca6aaa75e86e2ba189cded3eeb1bcd93cfd1418
3
+ metadata.gz: 512be53850324ba32bfdf38f6069561fb4cff9cd3e21c7acd3f431ade7533603
4
+ data.tar.gz: 297df24712a1eed2dd55902845ade84a1d44b714f69c75a1ac97be98baf15de8
5
5
  SHA512:
6
- metadata.gz: 75eb397c461cc2acf4a0d8f1ba9673f49d84dd9344681218cc2a5e800eaa979e46f24ec0ecb3fbfe6dc73d25a5c3ad72e79e4256a15fe356a2fa04366402db69
7
- data.tar.gz: a2a900c8d6663e5ed2d3a022e36fd1baa4ee7fbf7c7b531bde2ae1d0efa4c023cc7d5b1b007e8bbb9c82c20edaff9dd7f1c08f499a4e03d342d1915adf26836e
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.0)
4
+ rabbit_carrots (1.0.2)
5
5
  bunny (>= 2.22)
6
6
  connection_pool (~> 2.4)
7
7
 
@@ -1,6 +1,7 @@
1
1
  # rabbit_carrots.rb
2
2
 
3
3
  require 'puma/plugin'
4
+ require 'rabbit_carrots'
4
5
 
5
6
  Puma::Plugin.create do
6
7
  attr_reader :puma_pid, :rabbit_carrots_pid, :log_writer, :core_service
@@ -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.0'
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.0
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