Class: Falqon::Configuration
- Inherits:
-
Object
- Object
- Falqon::Configuration
- 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
-
#logger ⇒ Logger
Logger instance.
-
#max_retries ⇒ Integer
Maximum number of retries before a message is discarded.
-
#prefix ⇒ String
Queue name prefix, defaults to “falqon”.
-
#redis ⇒ ConnectionPool
Redis connection pool.
-
#redis_options ⇒ Hash
Redis connection options passed to
Redis.new
. -
#retry_delay ⇒ Integer
Delay between retries (in seconds).
Instance Method Summary collapse
-
#retry_strategy ⇒ Symbol
Failed message retry strategy.
-
#retry_strategy=(retry_strategy) ⇒ Symbol
Failed message retry strategy.
Instance Attribute Details
#logger ⇒ Logger
Logger instance
137 138 139 |
# File 'lib/falqon/configuration.rb', line 137 def logger @logger ||= Logger.new(File::NULL) end |
#max_retries ⇒ Integer
Maximum number of retries before a message is discarded
Only applicable when using the :linear
retry strategy
106 107 108 |
# File 'lib/falqon/configuration.rb', line 106 def max_retries @max_retries ||= 3 end |
#prefix ⇒ String
Queue name prefix, defaults to “falqon”
78 79 80 |
# File 'lib/falqon/configuration.rb', line 78 def prefix @prefix ||= "falqon" end |
#redis ⇒ ConnectionPool
Redis connection pool
122 123 124 |
# File 'lib/falqon/configuration.rb', line 122 def redis @redis ||= ConnectionPool.new(size: 5, timeout: 5) { Redis.new(**) } end |
#redis_options ⇒ Hash
Redis connection options passed to Redis.new
128 129 130 131 132 133 |
# File 'lib/falqon/configuration.rb', line 128 def @redis_options ||= { url: ENV.fetch("REDIS_URL", "redis://localhost:6379/0"), middlewares: [Middlewares::Logger], } end |
#retry_delay ⇒ Integer
Delay between retries (in seconds)
Only applicable when using the :linear
retry strategy
116 117 118 |
# File 'lib/falqon/configuration.rb', line 116 def retry_delay @retry_delay ||= 0 end |
Instance Method Details
#retry_strategy ⇒ Symbol
Failed message retry strategy
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
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 |