Sha256: 08c86836e0d955d8a1d3173a3bbd2c9450b001fb80827466e2dd8271014280f7

Contents?: true

Size: 1.22 KB

Versions: 6

Compression:

Stored size: 1.22 KB

Contents

# frozen_string_literal: true

require "sneakers"
require "lamian"
require "sneakers/runner"

require "rabbit/extensions/bunny/channel"
require "rabbit/receiving/worker"

module Rabbit
  module Daemon
    extend self

    def run(logger: Sneakers.logger)
      unless logger
        logger = Logger.new(Rails.root.join("log", "sneakers.log"))
        logger.level = Logger::DEBUG
        Lamian.extend_logger(logger)
      end

      Sneakers.configure(**sneakers_config(logger: logger))
      Sneakers.server = true

      Rabbit.config.validate!
      Receiving::Worker.from_queue(Rabbit.config.read_queue)
      Sneakers::Runner.new([Receiving::Worker]).run
    end

    def config
      Rails.application.config_for("sneakers").symbolize_keys
    end

    def connection
      bunny_config = config.delete(:bunny_options).to_h.symbolize_keys
      Bunny.new(bunny_config)
    end

    private

    def sneakers_config(logger:)
      {
        connection: connection,
        env: Rails.env,
        exchange_type: :direct,
        exchange: Rabbit.config.app_name,
        hooks: Rabbit.config.hooks,
        supervisor: true,
        daemonize: false,
        exit_on_detach: true,
        log: logger,
        **config,
      }
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
rabbit_messaging-1.1.0 lib/rabbit/daemon.rb
rabbit_messaging-1.0.0 lib/rabbit/daemon.rb
rabbit_messaging-0.15.0 lib/rabbit/daemon.rb
rabbit_messaging-0.13.0 lib/rabbit/daemon.rb
rabbit_messaging-0.12.1 lib/rabbit/daemon.rb
rabbit_messaging-0.12.0 lib/rabbit/daemon.rb