module Amber::Jobs

Defined in:

amber/jobs.cr
amber/jobs/configuration.cr
amber/jobs/job.cr
amber/jobs/job_envelope.cr
amber/jobs/memory_queue_adapter.cr
amber/jobs/queue_adapter.cr
amber/jobs/scheduler.cr
amber/jobs/worker.cr

Constant Summary

Log = ::Log.for(self)

Class Method Summary

Macro Summary

Class Method Detail

def self.adapter : QueueAdapter #

Returns the current queue adapter, creating a default MemoryQueueAdapter if none is set.


[View source]
def self.adapter=(adapter : QueueAdapter) #

Sets the queue adapter instance directly.


[View source]
def self.configuration : Configuration #

Returns the current configuration, creating a default if none exists.


[View source]
def self.configuration=(config : Configuration) #

Sets the configuration directly.


[View source]
def self.configure(&) #

Yields the configuration for modification.


[View source]
def self.deserialize(class_name : String, payload : String) : Job | Nil #

Deserializes a job from its class name and JSON payload. Returns nil if the job class is not registered.


[View source]
def self.register_job(class_name : String, &block : String -> Job) #

Registers a job class with a deserialization proc. This is the runtime method called by the register macro.


[View source]
def self.reset : Nil #

Resets the jobs system state. Primarily useful for testing.


[View source]
def self.start : Nil #

Starts the background jobs system.

Spawns the configured number of workers and starts the scheduler. This is typically called automatically when the Amber server starts if is_auto_start_enabled is true in the configuration.


[View source]
def self.stop : Nil #

Stops all workers and the scheduler.


[View source]

Macro Detail

macro register(job_class) #

Registers a job class for deserialization.

This must be called for each job class so the worker can reconstruct the job instance from its serialized JSON payload.

Usage

Amber::Jobs.register(MyJob)

[View source]