rabbit_carrots 1.0.1 → 1.0.3
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/Gemfile.lock +5 -5
- data/README.md +1 -0
- data/lib/puma/plugin/rabbit_carrots.rb +3 -2
- data/lib/rabbit_carrots/configuration.rb +4 -0
- data/lib/rabbit_carrots/core.rb +42 -17
- data/lib/rabbit_carrots/errors.rb +18 -0
- data/lib/rabbit_carrots/version.rb +1 -1
- data/lib/rabbit_carrots.rb +2 -17
- 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: 3bbe59dfd2a28bbe73bb736c70214e88dab67ec860673fb856fbef99e160618a
|
4
|
+
data.tar.gz: 4ceac6041889f8ef802504d5342f860c9908bdcdd2f88b16fea7872073da23e4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: af8a715a93424768b6fbe20aa5a442963ae643964b896f45604e27bb0c810259e1f7a9d5c8cd1fb4fa523b3ab10a2fb374200b2bb11bfce8fdd470a7f5228640
|
7
|
+
data.tar.gz: 7758e6422d668ae44dd9be62519afe5e863081f151f30a265f408e256cc701b20580fe8ce089e2d00233c5d4c1a3c1d8178d019ae95610ae752abec6f9c0d2d1
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
rabbit_carrots (1.0.
|
4
|
+
rabbit_carrots (1.0.3)
|
5
5
|
bunny (>= 2.22)
|
6
6
|
connection_pool (~> 2.4)
|
7
7
|
|
@@ -18,12 +18,12 @@ GEM
|
|
18
18
|
minitest (>= 5.1)
|
19
19
|
mutex_m
|
20
20
|
tzinfo (~> 2.0)
|
21
|
-
amq-protocol (2.3.
|
21
|
+
amq-protocol (2.3.4)
|
22
22
|
ast (2.4.2)
|
23
23
|
base64 (0.2.0)
|
24
24
|
bigdecimal (3.1.4)
|
25
|
-
bunny (2.
|
26
|
-
amq-protocol (~> 2.3
|
25
|
+
bunny (2.24.0)
|
26
|
+
amq-protocol (~> 2.3)
|
27
27
|
sorted_set (~> 1, >= 1.0.2)
|
28
28
|
concurrent-ruby (1.2.2)
|
29
29
|
connection_pool (2.4.1)
|
@@ -80,7 +80,7 @@ GEM
|
|
80
80
|
rubocop-ast (>= 1.30.0, < 2.0)
|
81
81
|
ruby-progressbar (1.13.0)
|
82
82
|
ruby2_keywords (0.0.5)
|
83
|
-
set (1.1.
|
83
|
+
set (1.1.2)
|
84
84
|
sorted_set (1.0.3)
|
85
85
|
rbtree
|
86
86
|
set (~> 1.0)
|
data/README.md
CHANGED
@@ -36,6 +36,7 @@ RabbitCarrots.configure do |c|
|
|
36
36
|
c.automatically_recover = true
|
37
37
|
c.network_recovery_interval = 5
|
38
38
|
c.recovery_attempts = 5
|
39
|
+
c.orm = :activerecord || :mongoid
|
39
40
|
c.routing_key_mappings = [
|
40
41
|
{ routing_keys: ['RK1', 'RK2'], queue: 'QUEUE_NAME', handler: 'CLASS HANDLER IN STRING' },
|
41
42
|
{ routing_keys: ['RK1', 'RK2'], queue: 'QUEUE_NAME', handler: 'CLASS HANDLER IN STRING' }
|
@@ -8,7 +8,7 @@ Puma::Plugin.create do
|
|
8
8
|
|
9
9
|
def start(launcher)
|
10
10
|
@log_writer = launcher.log_writer
|
11
|
-
@puma_pid =
|
11
|
+
@puma_pid = $PROCESS_ID
|
12
12
|
|
13
13
|
@core_service = RabbitCarrots::Core.new(logger: log_writer)
|
14
14
|
|
@@ -43,6 +43,7 @@ Puma::Plugin.create do
|
|
43
43
|
Process.kill('TERM', rabbit_carrots_pid)
|
44
44
|
Process.wait(rabbit_carrots_pid)
|
45
45
|
rescue Errno::ECHILD, Errno::ESRCH
|
46
|
+
log 'Rabbit Carrots already stopped'
|
46
47
|
end
|
47
48
|
|
48
49
|
def monitor_puma
|
@@ -57,7 +58,7 @@ Puma::Plugin.create do
|
|
57
58
|
loop do
|
58
59
|
if send(process_dead)
|
59
60
|
log message
|
60
|
-
Process.kill('TERM',
|
61
|
+
Process.kill('TERM', $PROCESS_ID)
|
61
62
|
break
|
62
63
|
end
|
63
64
|
sleep 2
|
data/lib/rabbit_carrots/core.rb
CHANGED
@@ -2,18 +2,26 @@ module RabbitCarrots
|
|
2
2
|
class Core
|
3
3
|
attr_reader :logger
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
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
|
-
@logger = logger || Logger.new(Rails.env.production? ? '/proc/self/fd/1' : $stdout)
|
14
|
+
@logger = create_logger_adapter(logger || Logger.new(Rails.env.production? ? '/proc/self/fd/1' : $stdout))
|
11
15
|
@threads = []
|
12
16
|
@running = true
|
13
17
|
@shutdown_requested = false
|
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
|
@@ -53,7 +61,7 @@ module RabbitCarrots
|
|
53
61
|
def request_shutdown
|
54
62
|
# Workaround to a known issue with Signal Traps and logs
|
55
63
|
Thread.start do
|
56
|
-
logger.
|
64
|
+
logger.error 'Shutting down Rabbit Carrots service...'
|
57
65
|
end
|
58
66
|
@shutdown_requested = true
|
59
67
|
@threads.each(&:kill)
|
@@ -63,7 +71,7 @@ module RabbitCarrots
|
|
63
71
|
def stop
|
64
72
|
# Workaround to a known issue with Signal Traps and logs
|
65
73
|
Thread.start do
|
66
|
-
logger.
|
74
|
+
logger.error 'Stoppig the Rabbit Carrots service...'
|
67
75
|
end
|
68
76
|
@running = false
|
69
77
|
end
|
@@ -72,7 +80,7 @@ module RabbitCarrots
|
|
72
80
|
RabbitCarrots::Connection.instance.channel.with do |channel|
|
73
81
|
exchange = channel.topic(RabbitCarrots.configuration.rabbitmq_exchange_name, durable: true)
|
74
82
|
|
75
|
-
logger.
|
83
|
+
logger.info "Listening on QUEUE: #{queue_name} for ROUTING KEYS: #{routing_keys}"
|
76
84
|
queue = channel.queue(queue_name, durable: true, arguments: queue_arguments)
|
77
85
|
|
78
86
|
routing_keys.map(&:strip).each { |k| queue.bind(exchange, routing_key: k) }
|
@@ -80,34 +88,51 @@ module RabbitCarrots
|
|
80
88
|
queue.subscribe(block: false, manual_ack: true, prefetch: 10) do |delivery_info, properties, payload|
|
81
89
|
break if @shutdown_requested
|
82
90
|
|
83
|
-
logger.
|
91
|
+
logger.info "Received from queue: #{queue_name}, Routing Keys: #{routing_keys}"
|
84
92
|
handler_class.handle!(channel, delivery_info, properties, payload)
|
85
93
|
channel.ack(delivery_info.delivery_tag, false)
|
86
94
|
rescue RabbitCarrots::EventHandlers::Errors::NackMessage, JSON::ParserError => _e
|
87
|
-
logger.
|
95
|
+
logger.warn "Nacked message: #{payload}"
|
88
96
|
channel.nack(delivery_info.delivery_tag, false, false)
|
89
97
|
rescue RabbitCarrots::EventHandlers::Errors::NackAndRequeueMessage => _e
|
90
|
-
logger.
|
98
|
+
logger.warn "Nacked and Requeued message: #{payload}"
|
91
99
|
channel.nack(delivery_info.delivery_tag, false, true)
|
92
|
-
rescue
|
93
|
-
logger.
|
100
|
+
rescue self.class.database_agnostic_not_null_violation, self.class.database_agnostic_record_invalid => e
|
101
|
+
logger.warn "Null constraint or Invalid violation: #{payload}. Error: #{e.message}"
|
94
102
|
channel.ack(delivery_info.delivery_tag, false)
|
95
|
-
rescue
|
96
|
-
logger.
|
103
|
+
rescue self.class.database_agnostic_connection_not_established => e
|
104
|
+
logger.warn "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)
|
99
107
|
rescue StandardError => e
|
100
|
-
logger.
|
108
|
+
logger.error "Error handling message: #{payload}. Error: #{e.message}"
|
101
109
|
sleep 3
|
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}"
|
110
116
|
request_shutdown
|
111
117
|
end
|
118
|
+
|
119
|
+
private
|
120
|
+
|
121
|
+
def create_logger_adapter(logger)
|
122
|
+
return logger if logger.respond_to?(:info) && logger.respond_to?(:error) && logger.respond_to?(:warn)
|
123
|
+
|
124
|
+
adapter = Object.new
|
125
|
+
def adapter.info(msg)
|
126
|
+
@logger.write("[INFO] #{msg}\n")
|
127
|
+
end
|
128
|
+
def adapter.error(msg)
|
129
|
+
@logger.write("[ERROR] #{msg}\n")
|
130
|
+
end
|
131
|
+
def adapter.warn(msg)
|
132
|
+
@logger.write("[WARN] #{msg}\n")
|
133
|
+
end
|
134
|
+
adapter.instance_variable_set(:@logger, logger)
|
135
|
+
adapter
|
136
|
+
end
|
112
137
|
end
|
113
138
|
end
|
@@ -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
|
data/lib/rabbit_carrots.rb
CHANGED
@@ -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,14 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rabbit_carrots
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brusk Awat
|
8
|
-
autorequire:
|
9
8
|
bindir: exe
|
10
9
|
cert_chain: []
|
11
|
-
date:
|
10
|
+
date: 2025-05-25 00:00:00.000000000 Z
|
12
11
|
dependencies:
|
13
12
|
- !ruby/object:Gem::Dependency
|
14
13
|
name: bunny
|
@@ -59,6 +58,7 @@ files:
|
|
59
58
|
- lib/rabbit_carrots/configuration.rb
|
60
59
|
- lib/rabbit_carrots/connection.rb
|
61
60
|
- lib/rabbit_carrots/core.rb
|
61
|
+
- lib/rabbit_carrots/errors.rb
|
62
62
|
- lib/rabbit_carrots/railtie.rb
|
63
63
|
- lib/rabbit_carrots/tasks/rmq.rake
|
64
64
|
- lib/rabbit_carrots/version.rb
|
@@ -72,7 +72,6 @@ metadata:
|
|
72
72
|
source_code_uri: https://github.com/ditkrg/rabbit_carrots
|
73
73
|
changelog_uri: https://github.com/ditkrg/rabbit_carrots
|
74
74
|
rubygems_mfa_required: 'true'
|
75
|
-
post_install_message:
|
76
75
|
rdoc_options: []
|
77
76
|
require_paths:
|
78
77
|
- lib
|
@@ -87,8 +86,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
87
86
|
- !ruby/object:Gem::Version
|
88
87
|
version: '0'
|
89
88
|
requirements: []
|
90
|
-
rubygems_version: 3.
|
91
|
-
signing_key:
|
89
|
+
rubygems_version: 3.6.2
|
92
90
|
specification_version: 4
|
93
91
|
summary: A simple RabbitMQ consumer task
|
94
92
|
test_files: []
|