abstract struct Conveyor::Job

Overview

The Job is the unit of work in Conveyor. A representation of it is stored in Redis along with some metadata, and when it is time to execute that job, it is deserialized and its #call method is invoked.

Jobs are enqueued to be executed ASAP with the #enqueue method or scheduled with the #schedule method. Enqueuing a job runs it as soon as there is an available Conveyor::Belt.

Defining a job is a matter of defining a struct that inherits from Conveyor::Job (either directly or indirectly) and overriding the #call method to perform its work. The #call method is used as the calling convention used by Proc instances.

Included Modules

Direct Known Subclasses

Defined in:

job.cr

Constructors

Class Method Summary

Macro Summary

Instance Method Summary

Constructor Detail

def self.new(pull : JSON::PullParser) #

[View source]

Class Method Detail

def self.dequeue(id : String, *, configuration config : Configuration = CONFIG) : Nil #

Remove this job from all queues. This method will not unschedule the job.


[View source]
def self.max_attempts(max_attempts : Int32) #

[View source]
def self.max_attempts : Int32 #

[View source]
def self.unschedule(id : String, configuration config : Configuration = CONFIG) : Nil #

If this job was scheduled via one of the #schedule methods, this method will remove it from the schedule.


[View source]

Macro Detail

macro queue(name) #

Define the queue your job will enqueue on by default

struct SendEmail < Conveyor::Job
  # Emails get their own queue
  queue "email"

  def initialize(@email_address : String, @body : String)
  end

  def call
    # ...
  end
end

[View source]

Instance Method Detail

abstract def call #

Override this method to provide this job's functionality.


[View source]
def enqueue(*, queue : String = self.queue, configuration config : Configuration = CONFIG) : String #

Enqueues this job in the specified queue, or to the job's default queue if the queue isn't provided explicitly, to be executed immediately. You can also pass a Configuration instance to use different settings.

struct MyJob < Conveyor::Job
  def initialize(@arg : String)
  end

  def call
    # ...
  end
end

MyJob.new("asdf").enqueue

[View source]
def schedule(in delay : Time::Span, queue : String = self.queue, configuration config : Configuration = CONFIG) : String #

Enqueues this job in the specified queue, or to the job's default queue if the queue isn't provided, to be executed after the given amount of time. You can also pass a Configuration instance to use different settings.

struct MyJob < Conveyor::Job
  def initialize(@arg : String)
  end

  def call
    # ...
  end
end

MyJob.new("asdf").enqueue in: 1.minute

[View source]
def schedule(at time : Time, queue : String = self.queue, configuration config : Configuration = CONFIG) : String #

Enqueues this job in the specified queue, or to the job's default queue if the queue isn't provided explicitly, to be executed at the specified time. You can also pass a Configuration instance to use different settings.

struct MyJob < Conveyor::Job
  def initialize(@arg : String)
  end

  def call
    # ...
  end
end

MyJob.new("asdf").enqueue at: timestamp

[View source]