Class: Falqon::Strategies::Linear

Inherits:
Falqon::Strategy
  • Object
show all
Defined in:
lib/falqon/strategies/linear.rb

Overview

Retry strategy that retries a fixed number of times

When a message fails to process, it is moved to the scheduled queue, and retried after a fixed delay (configured by Queue#retry_delay). If a messages fails to process after the maximum number of retries (configured by Queue#max_retries), it is marked as dead, and moved to the dead subqueue.

When using the linear strategy and the retry delay is set to a non-zero value, a scheduled needs to be started to retry the messages after the configured delay.

queue = Falqon::Queue.new("my_queue")

# Start the watcher in a separate thread
Thread.new { loop { queue.schedule; sleep 1 } }

# Or start the watcher in a separate fiber
Fiber
  .new { loop { queue.schedule; sleep 1 } }
  .resume

Examples:

queue = Falqon::Queue.new("my_queue", retry_strategy: :linear, retry_delay: 60, max_retries: 3)
queue.push("Hello, World!")
queue.pop { raise Falqon::Error }
queue.inspect # => #<Falqon::Queue name="my_queue" pending=0 processing=0 scheduled=1 dead=0>
sleep 60
queue.pop # => "Hello, World!"