class Mosquito::Queue

Overview

A named Queue.

Named Queues exist in Redis and have 4 ordered lists: waiting, pending, scheduled, and dead.

A task is represented in a queue by its id.

A task flows through the queues in this manner:

 Time=0: Task does not exist yet, lists are empty

   Waiting  Pending  Scheduled    Dead

 ---------------------------------
 Time=1: Task is enqueued

   Waiting  Pending  Scheduled    Dead
    Task#1

 ---------------------------------
 Time=2: Task begins running. Task is moved to pending and executed

   Waiting  Pending  Scheduled    Dead
             Task#1

 ---------------------------------
 Time=3: Tasks are Enqueued.

   Waiting  Pending  Scheduled    Dead
    Task#2   Task#1
    Task#3

 ---------------------------------
 Time=4: Task succeeds, next task begins.

   Waiting  Pending  Scheduled    Dead
    Task#3   Task#2

 ---------------------------------
 Time=5: Task fails and is scheduled for later, next task begins.

   Waiting  Pending  Scheduled     Dead
             Task#3  t=7:Task#2

 ---------------------------------
 Time=6: Task succeeds. Nothing is executing.

   Waiting  Pending  Scheduled     Dead
                     t=7:Task#2

 ---------------------------------
 Time=7: Scheduled task is due and is moved to waiting. Nothing is executing.

   Waiting  Pending  Scheduled     Dead
    Task#2

 ---------------------------------
 Time=8: Task begins executing (for the second time).

   Waiting  Pending  Scheduled     Dead
             Task#2

 ---------------------------------
 Time=9: Task finished successfully. No more tasks present.

   Waiting  Pending  Scheduled     Dead

Defined in:

mosquito/queue.cr

Constant Summary

ID_PREFIX = {"mosquito"}
QUEUES = ["waiting", "scheduled", "pending", "dead", "config"] of ::String

Constructors

Class Method Summary

Instance Method Summary

Constructor Detail

def self.new(name : String) #

[View source]

Class Method Detail

def self.list_queues : Array(String) #

[View source]
def self.redis_key(*parts) #

[View source]

Instance Method Detail

def ==(other : self) : Bool #
Description copied from class Reference

Returns true if this reference is the same as other. Invokes same?.


[View source]
def banish(task : Task) #

[View source]
def config_q #

[View source]
def dead_q #

[View source]
def dequeue : Task | Nil #

[View source]
def dequeue_scheduled : Array(Task) #

[View source]
def empty? : Bool #

[View source]
def enqueue(task : Task, in interval : Time::Span) #

[View source]
def enqueue(task : Task, at execute_time : Time) #

[View source]
def enqueue(task : Task) #

[View source]
def flush #

[View source]
def forget(task : Task) #

[View source]
def length : Int32 #

TODO does this make sense?


[View source]
def name : String #

[View source]
def pending_q #

[View source]
def rate_limited? : Bool #

Determines if a task needs to be throttled and not dequeued


[View source]
def redis_key(*parts) #

[View source]
def reschedule(task : Task, execution_time) #

[View source]
def scheduled_q #

[View source]
def waiting_q #

[View source]