• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

umbrellio / rabbit_messaging / 13244068807

10 Feb 2025 03:13PM UTC coverage: 92.793%. First build
13244068807

push

github

tycooon
rm rails

41 of 56 branches covered (73.21%)

Branch coverage included in aggregate %.

19 of 25 new or added lines in 4 files covered. (76.0%)

371 of 388 relevant lines covered (95.62%)

5.65 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

84.44
/lib/rabbit.rb
1
# frozen_string_literal: true
2

3
require "tainbox"
1✔
4

5
require "rabbit/version"
1✔
6
require "rabbit/daemon"
1✔
7
require "rabbit/publishing"
1✔
8
require "rabbit/event_handler"
1✔
9

10
require "rabbit/extensions/bunny/channel"
1✔
11

12
module Rabbit
1✔
13
  InvalidConfig = Class.new(StandardError)
1✔
14
  MessageNotDelivered = Class.new(StandardError)
1✔
15

16
  class Config
1✔
17
    include Tainbox
1✔
18

19
    attribute :group_id, :Symbol
1✔
20
    attribute :project_id, :Symbol
1✔
21
    attribute :queue_suffix, :String
1✔
22
    attribute :hooks, default: {}
1✔
23
    attribute :environment, :Symbol, default: :production
1✔
24
    attribute :queue_name_conversion
1✔
25
    attribute :receiving_job_class_callable
1✔
26
    attribute :handler_resolver_callable
1✔
27
    attribute :exception_notifier
1✔
28
    attribute :before_receiving_hooks, default: []
1✔
29
    attribute :after_receiving_hooks, default: []
1✔
30
    attribute :skip_publishing_in, default: %i[test development]
1✔
31
    attribute :use_backoff_handler, :Boolean, default: false
1✔
32
    attribute :backoff_handler_max_retries, Integer, default: 6
1✔
33

34
    attribute :receive_logger, default: lambda {
1✔
35
      Logger.new(Rabbit.root.join("log", "incoming_rabbit_messages.log"))
15✔
36
    }
37

38
    attribute :publish_logger, default: lambda {
1✔
NEW
39
      Logger.new(Rabbit.root.join("log", "rabbit.log"))
×
40
    }
41

42
    attribute :malformed_logger, default: lambda {
1✔
43
      Logger.new(Rabbit.root.join("log", "malformed_messages.log"))
1✔
44
    }
45

46
    def validate!
1✔
47
      raise InvalidConfig, "missing project_id" unless project_id
8!
48
      raise InvalidConfig, "missing group_id" unless group_id
8!
49
      raise InvalidConfig, "missing exception_notifier" unless exception_notifier
8!
50

51
      unless %i[test development production].include?(environment)
8!
52
        raise "environment should be one of (test, development, production)"
×
53
      end
54
    end
55

56
    def skip_publish?
1✔
57
      skip_publishing_in.include?(environment)
2✔
58
    end
59

60
    def app_name
1✔
61
      [group_id, project_id].join(".")
14✔
62
    end
63

64
    def read_queue
1✔
65
      [app_name, queue_suffix].reject { |x| x.nil? || x.empty? }.join(".")
24✔
66
    end
67
  end
68

69
  extend self
1✔
70

71
  def config
1✔
72
    @config ||= Config.new
245✔
73
    yield(@config) if block_given?
245!
74
    @config
245✔
75
  end
76

77
  def root
1✔
78
    if defined?(Rails)
16!
NEW
79
      Rails.root
×
80
    else
16✔
81
      Pathname.new(Dir.pwd)
16✔
82
    end
83
  end
84

85
  def sneakers_config
1✔
86
    if defined?(Rails)
2!
NEW
87
      Rails.application.config_for(name)
×
88
    else
2✔
89
      config = YAML.load_file("config/sneakers.yml") rescue {}
2✔
90
      config[Rabbit.config.environment].to_h.symbolize_keys
2✔
91
    end
92
  end
93

94
  def configure
1✔
95
    yield(config)
×
96
    config.validate!
×
97
  end
98

99
  def publish(message_options)
1✔
100
    message = Publishing::Message.new(message_options)
2✔
101

102
    if message.realtime?
2✔
103
      Publishing.publish(message)
1✔
104
    else
1✔
105
      Publishing::Job.set(queue: default_queue_name).perform_later(message.to_hash)
1✔
106
    end
107
  end
108

109
  def queue_name(queue, ignore_conversion: false)
1✔
110
    return queue if ignore_conversion
13✔
111
    config.queue_name_conversion ? config.queue_name_conversion.call(queue) : queue
11!
112
  end
113

114
  def default_queue_name(ignore_conversion: false)
1✔
115
    queue_name(:default, ignore_conversion: ignore_conversion)
3✔
116
  end
117
end
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc