From b9528c66bf1377c5057f4ee7e0b33b8f1a533c8b Mon Sep 17 00:00:00 2001 From: Brusk Awat Date: Thu, 1 Dec 2022 22:04:45 +0300 Subject: [PATCH] Adds error classes --- lib/rabbit_carrots.rb | 14 +++++++++++++- lib/rabbit_carrots/tasks/rmq.rake | 4 ++-- lib/rabbit_carrots/version.rb | 2 +- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/lib/rabbit_carrots.rb b/lib/rabbit_carrots.rb index 9cced03..2655e4e 100644 --- a/lib/rabbit_carrots.rb +++ b/lib/rabbit_carrots.rb @@ -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 diff --git a/lib/rabbit_carrots/tasks/rmq.rake b/lib/rabbit_carrots/tasks/rmq.rake index 8abc14d..05c7e84 100644 --- a/lib/rabbit_carrots/tasks/rmq.rake +++ b/lib/rabbit_carrots/tasks/rmq.rake @@ -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 diff --git a/lib/rabbit_carrots/version.rb b/lib/rabbit_carrots/version.rb index 752f294..143cbac 100644 --- a/lib/rabbit_carrots/version.rb +++ b/lib/rabbit_carrots/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module RabbitCarrots - VERSION = "0.1.13" + VERSION = "0.1.14" end