rabbit_carrots 0.1.14 → 0.1.16
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 +6 -4
- data/Gemfile.lock +19 -2
- data/README.md +22 -0
- data/Rakefile +3 -3
- data/lib/rabbit_carrots/connection.rb +3 -3
- data/lib/rabbit_carrots/railtie.rb +1 -1
- data/lib/rabbit_carrots/tasks/rmq.rake +15 -1
- data/lib/rabbit_carrots/version.rb +1 -1
- data/lib/rabbit_carrots.rb +4 -5
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c8da9ad2d662b3217200cf1746b14244f8d2fe3c272fbee89eb7a6b8e7d47516
|
4
|
+
data.tar.gz: 9b5288fe33e7231bd75fe85112ed6ce1414b268f034f2fb6c3031abc03b14c56
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 353444e8b88fe16bfb4666eb3551873caaba9b5b78f6d70973e0f62bd856a063e0e9483b46204e23bdc92d14b744f10f6920db176c86893b00e14c686a8c5684
|
7
|
+
data.tar.gz: 1d003c714f6d26a9c68cacc740bc57e044d80f9dfb47bf1e4f40416f2989f65e1ed4f2be6b9690159f4ddb8366f9e253cfa31aa5b98cce95decda71215087c3d
|
data/Gemfile
CHANGED
@@ -1,12 +1,14 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
source
|
3
|
+
source 'https://rubygems.org'
|
4
4
|
|
5
5
|
# Specify your gem's dependencies in rabbit_carrots.gemspec
|
6
6
|
gemspec
|
7
7
|
|
8
|
-
gem
|
8
|
+
gem 'rake', '~> 13.0'
|
9
9
|
|
10
|
-
gem
|
10
|
+
gem 'rspec', '~> 3.0'
|
11
11
|
|
12
|
-
gem
|
12
|
+
gem 'rubocop', '~> 1.21'
|
13
|
+
|
14
|
+
gem 'rubocop-rails', '~> 2.17'
|
data/Gemfile.lock
CHANGED
@@ -1,24 +1,34 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
rabbit_carrots (0.1.
|
4
|
+
rabbit_carrots (0.1.15)
|
5
5
|
bunny (>= 2.19.0)
|
6
6
|
connection_pool (~> 2.3.0)
|
7
7
|
|
8
8
|
GEM
|
9
9
|
remote: https://rubygems.org/
|
10
10
|
specs:
|
11
|
+
activesupport (7.0.4)
|
12
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
13
|
+
i18n (>= 1.6, < 2)
|
14
|
+
minitest (>= 5.1)
|
15
|
+
tzinfo (~> 2.0)
|
11
16
|
amq-protocol (2.3.2)
|
12
17
|
ast (2.4.2)
|
13
18
|
bunny (2.19.0)
|
14
19
|
amq-protocol (~> 2.3, >= 2.3.1)
|
15
20
|
sorted_set (~> 1, >= 1.0.2)
|
21
|
+
concurrent-ruby (1.1.10)
|
16
22
|
connection_pool (2.3.0)
|
17
23
|
diff-lcs (1.5.0)
|
24
|
+
i18n (1.12.0)
|
25
|
+
concurrent-ruby (~> 1.0)
|
18
26
|
json (2.6.2)
|
27
|
+
minitest (5.16.3)
|
19
28
|
parallel (1.22.1)
|
20
29
|
parser (3.1.2.1)
|
21
30
|
ast (~> 2.4.1)
|
31
|
+
rack (3.0.1)
|
22
32
|
rainbow (3.1.1)
|
23
33
|
rake (13.0.6)
|
24
34
|
rbtree (0.4.5)
|
@@ -49,11 +59,17 @@ GEM
|
|
49
59
|
unicode-display_width (>= 1.4.0, < 3.0)
|
50
60
|
rubocop-ast (1.23.0)
|
51
61
|
parser (>= 3.1.1.0)
|
62
|
+
rubocop-rails (2.17.3)
|
63
|
+
activesupport (>= 4.2.0)
|
64
|
+
rack (>= 1.1)
|
65
|
+
rubocop (>= 1.33.0, < 2.0)
|
52
66
|
ruby-progressbar (1.11.0)
|
53
67
|
set (1.0.3)
|
54
68
|
sorted_set (1.0.3)
|
55
69
|
rbtree
|
56
70
|
set (~> 1.0)
|
71
|
+
tzinfo (2.0.5)
|
72
|
+
concurrent-ruby (~> 1.0)
|
57
73
|
unicode-display_width (2.3.0)
|
58
74
|
|
59
75
|
PLATFORMS
|
@@ -64,6 +80,7 @@ DEPENDENCIES
|
|
64
80
|
rake (~> 13.0)
|
65
81
|
rspec (~> 3.0)
|
66
82
|
rubocop (~> 1.21)
|
83
|
+
rubocop-rails (~> 2.17)
|
67
84
|
|
68
85
|
BUNDLED WITH
|
69
|
-
2.3.
|
86
|
+
2.3.26
|
data/README.md
CHANGED
@@ -43,6 +43,28 @@ end
|
|
43
43
|
|
44
44
|
|
45
45
|
|
46
|
+
Note that handler is a class that must implement a method named ```handle!``` that takes 4 parameters as follow:
|
47
|
+
|
48
|
+
```ruby
|
49
|
+
class DummyEventHandler
|
50
|
+
def self.handle!(channel, delivery_info, properties, payload)
|
51
|
+
# Handle the received message from the queue
|
52
|
+
end
|
53
|
+
end
|
54
|
+
```
|
55
|
+
|
56
|
+
|
57
|
+
|
58
|
+
Inside the handle message, you can NACK the message without re-queuing by raising ```RabbitCarrots::EventHandlers::Errors::NackMessage``` exception.
|
59
|
+
|
60
|
+
To NACK and re-queue, raise ```RabbitCarrots::EventHandlers::Errors::NackAndRequeueMessage``` exception.
|
61
|
+
|
62
|
+
If no errors are thrown, the message will be acknowledged soon after the ```handle!``` method returns.
|
63
|
+
|
64
|
+
Note: Any other unrescued exception raised inside ```handle!``` the that is a subclass of ```StandardError``` will trigger a NACK and re-queue.
|
65
|
+
|
66
|
+
### Running
|
67
|
+
|
46
68
|
Then run ```bundle exec rake rabbit_carrots:eat```.
|
47
69
|
|
48
70
|
## Development
|
data/Rakefile
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
3
|
+
require 'bundler/gem_tasks'
|
4
|
+
require 'rspec/core/rake_task'
|
5
5
|
|
6
6
|
RSpec::Core::RakeTask.new(:spec)
|
7
7
|
|
8
|
-
require
|
8
|
+
require 'rubocop/rake_task'
|
9
9
|
|
10
10
|
RuboCop::RakeTask.new
|
11
11
|
|
@@ -4,7 +4,7 @@ module RabbitCarrots
|
|
4
4
|
class Connection
|
5
5
|
include ::Singleton
|
6
6
|
attr_reader :connection
|
7
|
-
|
7
|
+
|
8
8
|
def initialize
|
9
9
|
@connection = Bunny.new(
|
10
10
|
host: RabbitCarrots.configuration.rabbitmq_host,
|
@@ -16,11 +16,11 @@ module RabbitCarrots
|
|
16
16
|
|
17
17
|
@connection.start
|
18
18
|
end
|
19
|
-
|
19
|
+
|
20
20
|
def channel
|
21
21
|
@channel ||= ConnectionPool.new do
|
22
22
|
connection.create_channel
|
23
23
|
end
|
24
24
|
end
|
25
|
-
end
|
25
|
+
end
|
26
26
|
end
|
@@ -10,7 +10,7 @@ namespace :rabbit_carrots do
|
|
10
10
|
{ **mapping, handler: mapping[:handler].constantize }
|
11
11
|
end
|
12
12
|
|
13
|
-
Rails.logger = Logger.new($stdout)
|
13
|
+
Rails.logger = Logger.new(Rails.env.production? ? '/proc/self/fd/1' : $stdout)
|
14
14
|
|
15
15
|
# Run RMQ Subscriber for each channel
|
16
16
|
channels.each do |channel|
|
@@ -47,9 +47,23 @@ def run_task(queue_name:, handler_class:, routing_keys:)
|
|
47
47
|
rescue RabbitCarrots::EventHandlers::Errors::NackAndRequeueMessage => _e
|
48
48
|
Rails.logger.info "Nacked and Requeued message: #{payload}"
|
49
49
|
channel.nack(delivery_info.delivery_tag, false, true)
|
50
|
+
rescue ActiveRecord::NotNullViolation, ActiveRecord::RecordInvalid => e
|
51
|
+
# on null constraint violation, we want to ack the message
|
52
|
+
Rails.logger.error "Null constraint or Invalid violation: #{payload}. Error: #{e.message}"
|
53
|
+
channel.ack(delivery_info.delivery_tag, false)
|
54
|
+
rescue ActiveRecord::ConnectionNotEstablished => e
|
55
|
+
# on connection not established, we want to requeue the message and sleep for 3 seconds
|
56
|
+
Rails.logger.error "Error connection not established to the database: #{payload}. Error: #{e.message}"
|
57
|
+
# delay for 3 seconds before requeuing
|
58
|
+
sleep 3
|
59
|
+
channel.nack(delivery_info.delivery_tag, false, true)
|
50
60
|
rescue StandardError => e
|
51
61
|
Rails.logger.error "Error handling message: #{payload}. Error: #{e.message}"
|
62
|
+
# requeue the message then kill the container
|
63
|
+
sleep 3
|
52
64
|
channel.nack(delivery_info.delivery_tag, false, true)
|
65
|
+
# kill the container with sigterm
|
66
|
+
Process.kill('SIGTERM', Process.pid)
|
53
67
|
end
|
54
68
|
|
55
69
|
Rails.logger.info 'RUN TASK ENDED'
|
data/lib/rabbit_carrots.rb
CHANGED
@@ -1,24 +1,23 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative
|
3
|
+
require_relative 'rabbit_carrots/version'
|
4
4
|
require 'rabbit_carrots/connection'
|
5
5
|
require 'rabbit_carrots/configuration'
|
6
6
|
require 'rabbit_carrots/railtie' if defined?(Rails)
|
7
7
|
|
8
|
-
|
9
8
|
module RabbitCarrots
|
10
9
|
class Error < StandardError; end
|
10
|
+
|
11
11
|
module EventHandlers
|
12
12
|
module Errors
|
13
13
|
class IrrelevantMessage < StandardError
|
14
14
|
end
|
15
|
-
|
15
|
+
|
16
16
|
class NackMessage < StandardError
|
17
17
|
end
|
18
|
-
|
18
|
+
|
19
19
|
class NackAndRequeueMessage < StandardError
|
20
20
|
end
|
21
21
|
end
|
22
22
|
end
|
23
|
-
|
24
23
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rabbit_carrots
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.16
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brusk Awat
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-02-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bunny
|
@@ -69,6 +69,7 @@ metadata:
|
|
69
69
|
homepage_uri: https://github.com/ditkrg
|
70
70
|
source_code_uri: https://github.com/ditkrg/rabbit_carrots
|
71
71
|
changelog_uri: https://github.com/ditkrg/rabbit_carrots
|
72
|
+
rubygems_mfa_required: 'true'
|
72
73
|
post_install_message:
|
73
74
|
rdoc_options: []
|
74
75
|
require_paths:
|