11# frozen_string_literal: true
22
3- require "tainbox"
4-
53require "rabbit/version"
64require "rabbit/daemon"
75require "rabbit/publishing"
@@ -14,38 +12,74 @@ module Rabbit
1412 MessageNotDelivered = Class . new ( StandardError )
1513
1614 class Config
17- include Tainbox
18-
19- attribute :group_id , :Symbol
20- attribute :project_id , :Symbol
21- attribute :queue_suffix , :String
22- attribute :hooks , default : { }
23- attribute :environment , :Symbol , default : :production
24- attribute :queue_name_conversion
25- attribute :receiving_job_class_callable
26- attribute :handler_resolver_callable
27- attribute :exception_notifier
28- attribute :before_receiving_hooks , default : [ ]
29- attribute :after_receiving_hooks , default : [ ]
30- attribute :skip_publishing_in , default : %i[ test development ]
31- attribute :use_backoff_handler , :Boolean , default : false
32- attribute :backoff_handler_max_retries , Integer , default : 6
33- attribute :connection_reset_max_retries , Integer , default : 10
34- attribute :connection_reset_timeout , Float , default : 0.2
35- attribute :connection_reset_exceptions , Array , default : [ Bunny ::ConnectionClosedError ]
36- attribute :logger_message_size_limit , Integer , default : 9_500
37-
38- attribute :receive_logger , default : lambda {
39- Logger . new ( Rabbit . root . join ( "log" , "incoming_rabbit_messages.log" ) )
40- }
41-
42- attribute :publish_logger , default : lambda {
43- Logger . new ( Rabbit . root . join ( "log" , "rabbit.log" ) )
44- }
45-
46- attribute :malformed_logger , default : lambda {
47- Logger . new ( Rabbit . root . join ( "log" , "malformed_messages.log" ) )
48- }
15+ attr_accessor :group_id ,
16+ :project_id ,
17+ :queue_suffix ,
18+ :hooks ,
19+ :environment ,
20+ :queue_name_conversion ,
21+ :receiving_job_class_callable ,
22+ :handler_resolver_callable ,
23+ :exception_notifier ,
24+ :before_receiving_hooks ,
25+ :after_receiving_hooks ,
26+ :skip_publishing_in ,
27+ :use_backoff_handler ,
28+ :backoff_handler_max_retries ,
29+ :connection_reset_max_retries ,
30+ :connection_reset_timeout ,
31+ :connection_reset_exceptions ,
32+ :logger_message_size_limit ,
33+ :receive_logger ,
34+ :publish_logger ,
35+ :malformed_logger
36+
37+ def initialize ( # rubocop:disable Metrics/MethodLength
38+ group_id : nil ,
39+ project_id : nil ,
40+ queue_suffix : nil ,
41+ hooks : { } ,
42+ environment : :production ,
43+ queue_name_conversion : nil ,
44+ receiving_job_class_callable : nil ,
45+ handler_resolver_callable : nil ,
46+ exception_notifier : nil ,
47+ before_receiving_hooks : [ ] ,
48+ after_receiving_hooks : [ ] ,
49+ skip_publishing_in : %i[ test development ] ,
50+ use_backoff_handler : false ,
51+ backoff_handler_max_retries : 6 ,
52+ connection_reset_max_retries : 10 ,
53+ connection_reset_timeout : 0.2 ,
54+ connection_reset_exceptions : [ Bunny ::ConnectionClosedError ] ,
55+ logger_message_size_limit : 9_500 ,
56+ receive_logger : nil ,
57+ publish_logger : nil ,
58+ malformed_logger : nil
59+ )
60+ self . group_id = group_id
61+ self . project_id = project_id
62+ self . queue_suffix = queue_suffix
63+ self . hooks = hooks
64+ self . environment = environment
65+ self . queue_name_conversion = queue_name_conversion
66+ self . receiving_job_class_callable = receiving_job_class_callable
67+ self . handler_resolver_callable = handler_resolver_callable
68+ self . exception_notifier = exception_notifier
69+ self . before_receiving_hooks = before_receiving_hooks
70+ self . after_receiving_hooks = after_receiving_hooks
71+ self . skip_publishing_in = skip_publishing_in
72+ self . use_backoff_handler = use_backoff_handler
73+ self . backoff_handler_max_retries = backoff_handler_max_retries
74+ self . connection_reset_max_retries = connection_reset_max_retries
75+ self . connection_reset_timeout = connection_reset_timeout
76+ self . connection_reset_exceptions = connection_reset_exceptions
77+ self . logger_message_size_limit = logger_message_size_limit
78+
79+ self . receive_logger = receive_logger || default_receive_logger
80+ self . publish_logger = publish_logger || default_publish_logger
81+ self . malformed_logger = malformed_logger || default_malformed_logger
82+ end
4983
5084 def validate!
5185 raise InvalidConfig , "missing project_id" unless project_id
@@ -68,6 +102,20 @@ def app_name
68102 def read_queue
69103 [ app_name , queue_suffix ] . reject { |x | x . nil? || x . empty? } . join ( "." )
70104 end
105+
106+ private
107+
108+ def default_receive_logger
109+ Logger . new ( Rabbit . root . join ( "log" , "incoming_rabbit_messages.log" ) )
110+ end
111+
112+ def default_publish_logger
113+ Logger . new ( Rabbit . root . join ( "log" , "rabbit.log" ) )
114+ end
115+
116+ def default_malformed_logger
117+ Logger . new ( Rabbit . root . join ( "log" , "malformed_messages.log" ) )
118+ end
71119 end
72120
73121 extend self
0 commit comments