module Leveret
Top level module, contains things that are required globally by Leveret
, such as configuration, the RabbitMQ channel and the logger.
Constants
- VERSION
Attributes
@!attribute [w] configuration
@return [Configuration] Set a totally new configuration object
Public Class Methods
Connect to the RabbitMQ channel that {Queue} and {Worker} both use. This channel is not thread safe, so should be reinitialized if necessary. Not recommended for general use.
@see reference.rubybunny.info/Bunny/Channel.html Bunny documentation @return [Bunny::Channel] RabbitMQ chanel
# File lib/leveret.rb, line 52 def channel @channel ||= begin chan = mq_connection.create_channel chan.prefetch(configuration.concurrent_fork_count) chan end end
@return [Configuration] The current configuration of Leveret
# File lib/leveret.rb, line 25 def configuration @configuration ||= Configuration.new end
Allows leveret to be configured via a block
@see Configuration
Attributes that can be configured @yield [config] The current configuration object
# File lib/leveret.rb, line 33 def configure yield(configuration) if block_given? end
# File lib/leveret.rb, line 60 def delay_queue @delay_queue ||= Leveret::DelayQueue.new end
Connect to the RabbitMQ exchange that Leveret
uses, used by the {Queue} for publishing and subscribing, not recommended for general use.
@see reference.rubybunny.info/Bunny/Exchange.html Bunny documentation @return [Bunny::Exchange] RabbitMQ exchange
# File lib/leveret.rb, line 42 def exchange @exchange ||= channel.exchange(Leveret.configuration.exchange_name, type: :direct, durable: true, auto_delete: false) end
Logger used throughout Leveret
, see {Configuration} for config options.
@return [Logger] Standard ruby logger
# File lib/leveret.rb, line 73 def log @log ||= Logger.new(configuration.log_file).tap do |log| log.level = configuration.log_level log.progname = 'Leveret' log.formatter = Leveret::LogFormatter.new end end
# File lib/leveret.rb, line 64 def reset_connection! @mq_connection = nil @channel = nil @delay_queue = nil end
Private Class Methods
# File lib/leveret.rb, line 83 def mq_connection @mq_connection ||= begin conn = Bunny.new(configuration.amqp) conn.start conn end end