Class: Falqon::Configuration

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/falqon/configuration.rb

Overview

Falqon configuration

Falqon can be configured before use, by leveraging the Falqon.configure method. It’s recommended to configure Falqon in an initializer file, such as config/initializers/falqon.rb. In a Rails application, the generator can be used to create the initializer file:

rails generate falqon:install

Otherwise, the file can be created manually:

Falqon.configure do |config|
  # Configure global queue name prefix
  # config.prefix = ENV.fetch("FALQON_PREFIX", "falqon")

  # Retry strategy (none or linear)
  # config.retry_strategy = :linear

  # Maximum number of retries before a message is discarded (-1 for infinite retries)
  # config.max_retries = 3

  # Retry delay (in seconds) for linear retry strategy (defaults to 0)
  # config.retry_delay = 60

  # Configure the Redis client options
  # config.redis_options = { url: ENV.fetch("REDIS_URL", "redis://localhost:6379/0") }

  # Or, configure the Redis client directly
  # config.redis = ConnectionPool.new(size: 5, timeout: 5) { Redis.new(url: ENV.fetch("REDIS_URL", "redis://localhost:6379/0")) }

  # Configure logger
  # config.logger = Logger.new(STDOUT)
end

The values above are the default values.

In addition, it is recommended to configure Redis to be persistent in production environments, in order not to lose data. Refer to the Redis documentation for more information.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#loggerLogger

Logger instance

Returns:

  • (Logger)


137
138
139
# File 'lib/falqon/configuration.rb', line 137

def logger
  @logger ||= Logger.new(File::NULL)
end

#max_retriesInteger

Maximum number of retries before a message is discarded

Only applicable when using the :linear retry strategy

Returns:

  • (Integer)

See Also:



106
107
108
# File 'lib/falqon/configuration.rb', line 106

def max_retries
  @max_retries ||= 3
end

#prefixString

Queue name prefix, defaults to “falqon”

Returns:

  • (String)


78
79
80
# File 'lib/falqon/configuration.rb', line 78

def prefix
  @prefix ||= "falqon"
end

#redisConnectionPool

Redis connection pool

Returns:

  • (ConnectionPool)


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

def redis
  @redis ||= ConnectionPool.new(size: 5, timeout: 5) { Redis.new(**redis_options) }
end

#redis_optionsHash

Redis connection options passed to Redis.new

Returns:

  • (Hash)


128
129
130
131
132
133
# File 'lib/falqon/configuration.rb', line 128

def redis_options
  @redis_options ||= {
    url: ENV.fetch("REDIS_URL", "redis://localhost:6379/0"),
    middlewares: [Middlewares::Logger],
  }
end

#retry_delayInteger

Delay between retries (in seconds)

Only applicable when using the :linear retry strategy

Returns:

  • (Integer)

See Also:



116
117
118
# File 'lib/falqon/configuration.rb', line 116

def retry_delay
  @retry_delay ||= 0
end

Instance Method Details

#retry_strategySymbol

Failed message retry strategy

Returns:

  • (Symbol)

See Also:



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

def retry_strategy
  @retry_strategy ||= :linear
end

#retry_strategy=(retry_strategy) ⇒ Symbol

Failed message retry strategy

Parameters:

  • retry_strategy (Symbol)

Returns:

  • (Symbol)

Raises:

  • (ArgumentError)

See Also:



94
95
96
97
98
# File 'lib/falqon/configuration.rb', line 94

def retry_strategy=(retry_strategy)
  raise ArgumentError, "Invalid retry strategy #{retry_strategy.inspect}" unless [:none, :linear].include? retry_strategy

  @retry_strategy = retry_strategy
end