Module: Leveret

Defined in:
lib/leveret.rb,
lib/leveret/cli.rb,
lib/leveret/job.rb,
lib/leveret/queue.rb,
lib/leveret/worker.rb,
lib/leveret/message.rb,
lib/leveret/version.rb,
lib/leveret/parameters.rb,
lib/leveret/delay_queue.rb,
lib/leveret/configuration.rb,
lib/leveret/log_formatter.rb,
lib/leveret/result_handler.rb

Overview

Top level module, contains things that are required globally by Leveret, such as configuration, the RabbitMQ channel and the logger.

Defined Under Namespace

Modules: Job Classes: CLI, Configuration, DelayQueue, LogFormatter, Message, Parameters, Queue, ResultHandler, Worker

Constant Summary collapse

VERSION =
"0.1.6".freeze

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.configurationConfiguration

Returns The current configuration of Leveret.

Returns:



25
26
27
# File 'lib/leveret.rb', line 25

def configuration
  @configuration ||= Configuration.new
end

Class Method Details

.channelBunny::Channel

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.

Returns:

  • (Bunny::Channel)

    RabbitMQ chanel

See Also:



52
53
54
55
56
57
58
# File 'lib/leveret.rb', line 52

def channel
  @channel ||= begin
    chan = mq_connection.create_channel
    chan.prefetch(configuration.concurrent_fork_count)
    chan
  end
end

.configure {|config| ... } ⇒ Object

Allows leveret to be configured via a block

Yields:

  • (config)

    The current configuration object

See Also:



33
34
35
# File 'lib/leveret.rb', line 33

def configure
  yield(configuration) if block_given?
end

.delay_queueObject



60
61
62
# File 'lib/leveret.rb', line 60

def delay_queue
  @delay_queue ||= Leveret::DelayQueue.new
end

.exchangeBunny::Exchange

Connect to the RabbitMQ exchange that Leveret uses, used by the Queue for publishing and subscribing, not recommended for general use.

Returns:

  • (Bunny::Exchange)

    RabbitMQ exchange

See Also:



42
43
44
45
# File 'lib/leveret.rb', line 42

def exchange
  @exchange ||= channel.exchange(Leveret.configuration.exchange_name, type: :direct, durable: true,
    auto_delete: false)
end

.logLogger

Logger used throughout Leveret, see Configuration for config options.

Returns:

  • (Logger)

    Standard ruby logger



73
74
75
76
77
78
79
# 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

.reset_connection!Object



64
65
66
67
68
# File 'lib/leveret.rb', line 64

def reset_connection!
  @mq_connection = nil
  @channel = nil
  @delay_queue = nil
end