rabbit_carrots 1.0.2 → 1.0.4

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: 512be53850324ba32bfdf38f6069561fb4cff9cd3e21c7acd3f431ade7533603
4
- data.tar.gz: 297df24712a1eed2dd55902845ade84a1d44b714f69c75a1ac97be98baf15de8
3
+ metadata.gz: ec4b3695681118c34b7b2eacc5c7ecc5aaca26867399abee1f1816cc27a09a7c
4
+ data.tar.gz: 2838ceb0a0d2e71508b4597aa5843b9b7249a95d6e27a16cb98a90dfcceba316
5
5
  SHA512:
6
- metadata.gz: 260c156c6794fc7b3c92ccd1f946c47e3ad004c01ec15f0bdd1875812d030a4d3983b67ed6106041370e97840db22da65afac2fe17d682cc97267ac926a17c2c
7
- data.tar.gz: 7ddc79c2c86c6db3fda8f3ec20cd9cac7750b054c01a0a96837ff9a02af5290e774718c6bb7b54d520fd3fd972a9e1bba5c614fa530c0cbb98f5f06542aa3ed8
6
+ metadata.gz: 8c8f7a24eef911ba35a99b07684f31113923c5e9506033c2a16364f3b1a73f90599e32e278f5879075674dcde8b2c5065243f60ca4c20a6129eae9da97710bfd
7
+ data.tar.gz: f13f29baafbf9a6afbe08f07d17ab17de6e6261e42370981e424bb337888c9eb8e9710d0dd22ac3a1ea088981f5d6e777d49b9f371e0fc0baec61d56d13b9727
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rabbit_carrots (1.0.2)
4
+ rabbit_carrots (1.0.4)
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.2)
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.22.0)
26
- amq-protocol (~> 2.3, >= 2.3.1)
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.0)
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' }
@@ -1,5 +1,4 @@
1
1
  # rabbit_carrots.rb
2
-
3
2
  require 'puma/plugin'
4
3
  require 'rabbit_carrots'
5
4
 
@@ -43,6 +42,7 @@ Puma::Plugin.create do
43
42
  Process.kill('TERM', rabbit_carrots_pid)
44
43
  Process.wait(rabbit_carrots_pid)
45
44
  rescue Errno::ECHILD, Errno::ESRCH
45
+ log 'Rabbit Carrots already stopped'
46
46
  end
47
47
 
48
48
  def monitor_puma
@@ -18,8 +18,8 @@ module RabbitCarrots
18
18
  :rabbitmq_exchange_name,
19
19
  :automatically_recover,
20
20
  :network_recovery_interval,
21
- :recovery_attempts,
22
- :orm
21
+ :recovery_attempts
22
+
23
23
  def orm
24
24
  @orm ||= :activerecord
25
25
  end
@@ -11,7 +11,7 @@ module RabbitCarrots
11
11
  end
12
12
 
13
13
  def initialize(logger: nil)
14
- @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))
15
15
  @threads = []
16
16
  @running = true
17
17
  @shutdown_requested = false
@@ -61,7 +61,7 @@ module RabbitCarrots
61
61
  def request_shutdown
62
62
  # Workaround to a known issue with Signal Traps and logs
63
63
  Thread.start do
64
- logger.log 'Shutting down Rabbit Carrots service...'
64
+ logger.error 'Shutting down Rabbit Carrots service...'
65
65
  end
66
66
  @shutdown_requested = true
67
67
  @threads.each(&:kill)
@@ -71,7 +71,7 @@ module RabbitCarrots
71
71
  def stop
72
72
  # Workaround to a known issue with Signal Traps and logs
73
73
  Thread.start do
74
- logger.log 'Stoppig the Rabbit Carrots service...'
74
+ logger.error 'Stoppig the Rabbit Carrots service...'
75
75
  end
76
76
  @running = false
77
77
  end
@@ -80,7 +80,7 @@ module RabbitCarrots
80
80
  RabbitCarrots::Connection.instance.channel.with do |channel|
81
81
  exchange = channel.topic(RabbitCarrots.configuration.rabbitmq_exchange_name, durable: true)
82
82
 
83
- logger.log "Listening on QUEUE: #{queue_name} for ROUTING KEYS: #{routing_keys}"
83
+ logger.info "Listening on QUEUE: #{queue_name} for ROUTING KEYS: #{routing_keys}"
84
84
  queue = channel.queue(queue_name, durable: true, arguments: queue_arguments)
85
85
 
86
86
  routing_keys.map(&:strip).each { |k| queue.bind(exchange, routing_key: k) }
@@ -88,24 +88,24 @@ module RabbitCarrots
88
88
  queue.subscribe(block: false, manual_ack: true, prefetch: 10) do |delivery_info, properties, payload|
89
89
  break if @shutdown_requested
90
90
 
91
- logger.log "Received from queue: #{queue_name}, Routing Keys: #{routing_keys}"
91
+ logger.info "Received from queue: #{queue_name}, Routing Keys: #{routing_keys}"
92
92
  handler_class.handle!(channel, delivery_info, properties, payload)
93
93
  channel.ack(delivery_info.delivery_tag, false)
94
94
  rescue RabbitCarrots::EventHandlers::Errors::NackMessage, JSON::ParserError => _e
95
- logger.log "Nacked message: #{payload}"
95
+ logger.warn "Nacked message: #{payload}"
96
96
  channel.nack(delivery_info.delivery_tag, false, false)
97
97
  rescue RabbitCarrots::EventHandlers::Errors::NackAndRequeueMessage => _e
98
- logger.log "Nacked and Requeued message: #{payload}"
98
+ logger.warn "Nacked and Requeued message: #{payload}"
99
99
  channel.nack(delivery_info.delivery_tag, false, true)
100
100
  rescue self.class.database_agnostic_not_null_violation, self.class.database_agnostic_record_invalid => e
101
- logger.log "Null constraint or Invalid violation: #{payload}. Error: #{e.message}"
101
+ logger.warn "Null constraint or Invalid violation: #{payload}. Error: #{e.message}"
102
102
  channel.ack(delivery_info.delivery_tag, false)
103
103
  rescue self.class.database_agnostic_connection_not_established => e
104
- logger.log "Error connection not established to the database: #{payload}. Error: #{e.message}"
104
+ logger.warn "Error connection not established to the database: #{payload}. Error: #{e.message}"
105
105
  sleep 3
106
106
  channel.nack(delivery_info.delivery_tag, false, true)
107
107
  rescue StandardError => e
108
- logger.log "Error handling message: #{payload}. Error: #{e.message}"
108
+ logger.error "Error handling message: #{payload}. Error: #{e.message}"
109
109
  sleep 3
110
110
  channel.nack(delivery_info.delivery_tag, false, true)
111
111
  Process.kill('SIGTERM', Process.pid) if kill_to_restart_on_standard_error
@@ -115,5 +115,27 @@ module RabbitCarrots
115
115
  logger.error "Bunny session error: #{e.message}"
116
116
  request_shutdown
117
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
+
129
+ def adapter.error(msg)
130
+ @logger.write("[ERROR] #{msg}\n")
131
+ end
132
+
133
+ def adapter.warn(msg)
134
+ @logger.write("[WARN] #{msg}\n")
135
+ end
136
+
137
+ adapter.instance_variable_set(:@logger, logger)
138
+ adapter
139
+ end
118
140
  end
119
141
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RabbitCarrots
4
- VERSION = '1.0.2'
4
+ VERSION = '1.0.4'
5
5
  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: 1.0.2
4
+ version: 1.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brusk Awat
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-08-05 00:00:00.000000000 Z
11
+ date: 2025-05-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bunny
@@ -73,7 +73,7 @@ metadata:
73
73
  source_code_uri: https://github.com/ditkrg/rabbit_carrots
74
74
  changelog_uri: https://github.com/ditkrg/rabbit_carrots
75
75
  rubygems_mfa_required: 'true'
76
- post_install_message:
76
+ post_install_message:
77
77
  rdoc_options: []
78
78
  require_paths:
79
79
  - lib
@@ -88,8 +88,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
88
88
  - !ruby/object:Gem::Version
89
89
  version: '0'
90
90
  requirements: []
91
- rubygems_version: 3.5.9
92
- signing_key:
91
+ rubygems_version: 3.5.22
92
+ signing_key:
93
93
  specification_version: 4
94
94
  summary: A simple RabbitMQ consumer task
95
95
  test_files: []