class Mosquito::WeightedDequeueAdapter

Overview

A dequeue adapter that checks queues according to configured weights.

Higher-weight queues are given proportionally more chances to be dequeued from. On each call to #dequeue, the adapter picks a queue at random (weighted by its configured value). If that queue is empty, it is removed from consideration and another weighted pick is made, ensuring each queue is checked at most once per dequeue call.

The weight map is built fresh on each dequeue call from the current queue list, ensuring newly discovered queues are picked up immediately.

Queues not present in the weights table are assigned a default weight of 1.

Example

Mosquito.configure do |settings|
  settings.dequeue_adapter = Mosquito::WeightedDequeueAdapter.new({
    "critical" => 5,
    "default"  => 2,
    "bulk"     => 1,
  })
end

In this configuration the "critical" queue will be checked roughly 5x as often as "bulk" and 2.5x as often as "default".

Defined in:

mosquito/dequeue_adapters/weighted_dequeue_adapter.cr

Constructors

Instance Method Summary

Instance methods inherited from class Mosquito::DequeueAdapter

dequeue(queue_list : Runners::QueueList) : Tuple(JobRun, Queue) | Nil dequeue

Constructor Detail

def self.new(weights : Hash(String, Int32), default_weight : Int32 = 1) #

Instance Method Detail

def dequeue(queue_list : Runners::QueueList) : Tuple(JobRun, Queue) | Nil #
Description copied from class Mosquito::DequeueAdapter

Attempt to dequeue a job from one of the queues managed by queue_list.

Returns a tuple of {JobRun, Queue} when a job is available, or nil when all queues are empty.


def weights : Hash(String, Int32) #