Adds error classes

This commit is contained in:
Brusk Awat 2022-12-01 22:04:45 +03:00
parent 1385400566
commit b9528c66bf
Signed by: broosk1993
GPG Key ID: 5D20F7E02649F74E
3 changed files with 16 additions and 4 deletions

View File

@ -8,5 +8,17 @@ require 'rabbit_carrots/railtie' if defined?(Rails)
module RabbitCarrots
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

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}"
handler_class.handle!(channel, delivery_info, properties, payload)
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}"
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}"
channel.nack(delivery_info.delivery_tag, false, true)
rescue StandardError => e

View File

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