Adds error classes

This commit is contained in:
2022-12-01 22:04:45 +03:00
parent 1385400566
commit b9528c66bf
3 changed files with 16 additions and 4 deletions

View File

@@ -8,5 +8,17 @@ require 'rabbit_carrots/railtie' if defined?(Rails)
module RabbitCarrots module RabbitCarrots
class Error < StandardError; end class Error < StandardError; end
# Your code goes here... module EventHandlers
module Errors
class IrrelevantMessage < StandardError
end
class NackMessage < StandardError
end
class NackAndRequeueMessage < StandardError
end
end
end
end end

View File

@@ -41,10 +41,10 @@ def run_task(queue_name:, handler_class:, routing_keys:)
Rails.logger.info "Received from queue: #{queue_name}, Routing Keys: #{routing_keys}" Rails.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 EventHandlers::Errors::NackMessage, JSON::ParserError => _e rescue RabbitCarrots::EventHandlers::Errors::NackMessage, JSON::ParserError => _e
Rails.logger.info "Nacked message: #{payload}" Rails.logger.info "Nacked message: #{payload}"
channel.nack(delivery_info.delivery_tag, false, false) channel.nack(delivery_info.delivery_tag, false, false)
rescue EventHandlers::Errors::NackAndRequeueMessage => _e rescue RabbitCarrots::EventHandlers::Errors::NackAndRequeueMessage => _e
Rails.logger.info "Nacked and Requeued message: #{payload}" Rails.logger.info "Nacked and Requeued message: #{payload}"
channel.nack(delivery_info.delivery_tag, false, true) channel.nack(delivery_info.delivery_tag, false, true)
rescue StandardError => e rescue StandardError => e

View File

@@ -1,5 +1,5 @@
# frozen_string_literal: true # frozen_string_literal: true
module RabbitCarrots module RabbitCarrots
VERSION = "0.1.13" VERSION = "0.1.14"
end end