mirror of
https://github.com/ditkrg/rabbit_carrots.git
synced 2026-01-22 22:06:40 +00:00
Refines logging levels for shutdown, stop, and message handling in Rabbit Carrots service
This commit is contained in:
parent
59ad012e04
commit
f68ab83afc
@ -61,7 +61,7 @@ module RabbitCarrots
|
|||||||
def request_shutdown
|
def request_shutdown
|
||||||
# Workaround to a known issue with Signal Traps and logs
|
# Workaround to a known issue with Signal Traps and logs
|
||||||
Thread.start do
|
Thread.start do
|
||||||
logger.log 'Shutting down Rabbit Carrots service...'
|
logger.error 'Shutting down Rabbit Carrots service...'
|
||||||
end
|
end
|
||||||
@shutdown_requested = true
|
@shutdown_requested = true
|
||||||
@threads.each(&:kill)
|
@threads.each(&:kill)
|
||||||
@ -71,7 +71,7 @@ module RabbitCarrots
|
|||||||
def stop
|
def stop
|
||||||
# Workaround to a known issue with Signal Traps and logs
|
# Workaround to a known issue with Signal Traps and logs
|
||||||
Thread.start do
|
Thread.start do
|
||||||
logger.log 'Stoppig the Rabbit Carrots service...'
|
logger.error 'Stoppig the Rabbit Carrots service...'
|
||||||
end
|
end
|
||||||
@running = false
|
@running = false
|
||||||
end
|
end
|
||||||
@ -80,7 +80,7 @@ module RabbitCarrots
|
|||||||
RabbitCarrots::Connection.instance.channel.with do |channel|
|
RabbitCarrots::Connection.instance.channel.with do |channel|
|
||||||
exchange = channel.topic(RabbitCarrots.configuration.rabbitmq_exchange_name, durable: true)
|
exchange = channel.topic(RabbitCarrots.configuration.rabbitmq_exchange_name, durable: true)
|
||||||
|
|
||||||
logger.log "Listening on QUEUE: #{queue_name} for ROUTING KEYS: #{routing_keys}"
|
logger.info "Listening on QUEUE: #{queue_name} for ROUTING KEYS: #{routing_keys}"
|
||||||
queue = channel.queue(queue_name, durable: true, arguments: queue_arguments)
|
queue = channel.queue(queue_name, durable: true, arguments: queue_arguments)
|
||||||
|
|
||||||
routing_keys.map(&:strip).each { |k| queue.bind(exchange, routing_key: k) }
|
routing_keys.map(&:strip).each { |k| queue.bind(exchange, routing_key: k) }
|
||||||
@ -88,24 +88,24 @@ module RabbitCarrots
|
|||||||
queue.subscribe(block: false, manual_ack: true, prefetch: 10) do |delivery_info, properties, payload|
|
queue.subscribe(block: false, manual_ack: true, prefetch: 10) do |delivery_info, properties, payload|
|
||||||
break if @shutdown_requested
|
break if @shutdown_requested
|
||||||
|
|
||||||
logger.log "Received from queue: #{queue_name}, Routing Keys: #{routing_keys}"
|
logger.info "Received from queue: #{queue_name}, Routing Keys: #{routing_keys}"
|
||||||
handler_class.handle!(channel, delivery_info, properties, payload)
|
handler_class.handle!(channel, delivery_info, properties, payload)
|
||||||
channel.ack(delivery_info.delivery_tag, false)
|
channel.ack(delivery_info.delivery_tag, false)
|
||||||
rescue RabbitCarrots::EventHandlers::Errors::NackMessage, JSON::ParserError => _e
|
rescue RabbitCarrots::EventHandlers::Errors::NackMessage, JSON::ParserError => _e
|
||||||
logger.log "Nacked message: #{payload}"
|
logger.warn "Nacked message: #{payload}"
|
||||||
channel.nack(delivery_info.delivery_tag, false, false)
|
channel.nack(delivery_info.delivery_tag, false, false)
|
||||||
rescue RabbitCarrots::EventHandlers::Errors::NackAndRequeueMessage => _e
|
rescue RabbitCarrots::EventHandlers::Errors::NackAndRequeueMessage => _e
|
||||||
logger.log "Nacked and Requeued message: #{payload}"
|
logger.warn "Nacked and Requeued message: #{payload}"
|
||||||
channel.nack(delivery_info.delivery_tag, false, true)
|
channel.nack(delivery_info.delivery_tag, false, true)
|
||||||
rescue self.class.database_agnostic_not_null_violation, self.class.database_agnostic_record_invalid => e
|
rescue self.class.database_agnostic_not_null_violation, self.class.database_agnostic_record_invalid => e
|
||||||
logger.log "Null constraint or Invalid violation: #{payload}. Error: #{e.message}"
|
logger.warn "Null constraint or Invalid violation: #{payload}. Error: #{e.message}"
|
||||||
channel.ack(delivery_info.delivery_tag, false)
|
channel.ack(delivery_info.delivery_tag, false)
|
||||||
rescue self.class.database_agnostic_connection_not_established => e
|
rescue self.class.database_agnostic_connection_not_established => e
|
||||||
logger.log "Error connection not established to the database: #{payload}. Error: #{e.message}"
|
logger.warn "Error connection not established to the database: #{payload}. Error: #{e.message}"
|
||||||
sleep 3
|
sleep 3
|
||||||
channel.nack(delivery_info.delivery_tag, false, true)
|
channel.nack(delivery_info.delivery_tag, false, true)
|
||||||
rescue StandardError => e
|
rescue StandardError => e
|
||||||
logger.log "Error handling message: #{payload}. Error: #{e.message}"
|
logger.error "Error handling message: #{payload}. Error: #{e.message}"
|
||||||
sleep 3
|
sleep 3
|
||||||
channel.nack(delivery_info.delivery_tag, false, true)
|
channel.nack(delivery_info.delivery_tag, false, true)
|
||||||
Process.kill('SIGTERM', Process.pid) if kill_to_restart_on_standard_error
|
Process.kill('SIGTERM', Process.pid) if kill_to_restart_on_standard_error
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user