class Amber::Jobs::Scheduler

Overview

Handles periodic promotion of scheduled and delayed jobs.

The Scheduler runs in a background fiber and periodically checks the queue adapter for scheduled jobs that are ready to execute. This is primarily useful for adapters that separate scheduled jobs from the immediate queue (like the MemoryQueueAdapter).

In the MemoryQueueAdapter, scheduled job promotion happens during dequeue, so the scheduler serves as an additional check to ensure jobs are promoted even when no dequeue calls are happening.

Usage

scheduler = Amber::Jobs::Scheduler.new(
  adapter: adapter,
  interval: 5.seconds
)
scheduler.start

Defined in:

amber/jobs/scheduler.cr

Constant Summary

Log = ::Log.for(self)

Constructors

Instance Method Summary

Constructor Detail

def self.new(adapter : QueueAdapter, interval : Time::Span = 5.seconds) #

[View source]

Instance Method Detail

def adapter : QueueAdapter #

[View source]
def interval : Time::Span #

[View source]
def is_running? : Bool #

[View source]
def start : Nil #

Starts the scheduler in a background fiber.

The scheduler will periodically trigger dequeue on all configured queues to promote scheduled jobs. This is a no-op if the scheduler is already running.


[View source]
def stop : Nil #

Stops the scheduler.

The scheduler will finish its current sleep cycle and then stop.


[View source]
def tick : Nil #

Performs a single scheduler tick.

This is exposed as a public method primarily for testing purposes, allowing specs to trigger scheduler behavior without running in a fiber.


[View source]