Class: Proletariat::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/proletariat/configuration.rb

Overview

Public: Global configuration object. Provides sensible defaults.

Defined Under Namespace

Classes: ConfigurationDSL

Constant Summary collapse

DEFAULT_EXCHANGE_NAME =

Public: The default name used for the RabbitMQ topic exchange.

'proletariat'
DEFAULT_MAX_RETRY_DELAY =

Public: The default maximum seconds to delay a failed job requeue.

(ENV['MAX_RETRY_DELAY'] || 60).to_i
DEFAULT_PUBLISHER_THREADS =

Public: The default number of threads to use for publishers.

(ENV['PUBLISHER_THREADS'] || 2).to_i
DEFAULT_WORKER_THREADS =

Public: The default number of threads to use for each worker class.

(ENV['WORKER_THREADS'] || 3).to_i

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#connectionObject

Public: Returns the set connection or defaults to a new, open

Bunny::Session

Returns a Bunny::Session.



53
54
55
56
57
58
59
60
# File 'lib/proletariat/configuration.rb', line 53

def connection
  @connection ||= begin
    new_connection = Bunny.new
    new_connection.start

    new_connection
  end
end

#exchange_nameObject

Public: Returns the set name of the exchange or a default.

Returns a String.



65
66
67
# File 'lib/proletariat/configuration.rb', line 65

def exchange_name
  @exchange_name ||= DEFAULT_EXCHANGE_NAME
end

#loggerObject

Public: Returns the set logger or a default standard output logger.

Returns a logger.



72
73
74
# File 'lib/proletariat/configuration.rb', line 72

def logger
  @logger ||= Logger.new(STDOUT)
end

#max_retry_delayObject

Public: Returns the set max delay seconds or a default.

Returns a Fixnum.



79
80
81
# File 'lib/proletariat/configuration.rb', line 79

def max_retry_delay
  @max_retry_delay ||= DEFAULT_MAX_RETRY_DELAY
end

#publisher_threadsObject

Public: Returns the set number of publisher threads or a default.

Returns a Fixnum.



86
87
88
# File 'lib/proletariat/configuration.rb', line 86

def publisher_threads
  @publisher_threads ||= DEFAULT_PUBLISHER_THREADS
end

#worker_classesObject

Public: Returns the set worker classes or a default pulled from the

WORKERS env variable.

Returns an array of Worker classes.



109
110
111
112
113
114
115
116
117
# File 'lib/proletariat/configuration.rb', line 109

def worker_classes
  @worker_classes ||= begin
    if ENV['WORKERS']
      WorkerDescriptionParser.parse ENV['WORKERS']
    else
      []
    end
  end
end

#worker_threadsObject

Public: Returns the set number of worker threads or a default.

Returns a Fixnum.



122
123
124
# File 'lib/proletariat/configuration.rb', line 122

def worker_threads
  @worker_threads ||= DEFAULT_WORKER_THREADS
end

Instance Method Details

#configure_with_block(&block) ⇒ Object

Public: Allows setting of the config attributes via a block.

block - Block which modifies attributes by accessing them via #config.

Returns nil.



43
44
45
46
47
# File 'lib/proletariat/configuration.rb', line 43

def configure_with_block(&block)
  ConfigurationDSL.new(self, &block).set_config

  nil
end

#test_mode!Object

Public: Enables test mode. Queues will auto-delete after use.

Returns nil.



93
94
95
# File 'lib/proletariat/configuration.rb', line 93

def test_mode!
  @test_mode = true
end

#test_mode?Boolean

Public: Returns whether test mode is enabled or not.

Returns true if test mode enabled. Returns false if test mode disabled.

Returns:

  • (Boolean)


101
102
103
# File 'lib/proletariat/configuration.rb', line 101

def test_mode?
  !!@test_mode
end