struct

Conveyor::Job

Inherits JSON::Serializable < Struct < Value < Object

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.

Constructors

new(*, __pull_for_json_serializable pull : JSON::PullParser)
Source

Class methods

dequeue(id : String, *, configuration config : Configuration = CONFIG) : Nil

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

Source
max_attempts(max_attempts : Int32)
Source
max_attempts
Source
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.

Source

Instance methods

call

Override this method to provide this job's functionality.

Source
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
Source
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
Source
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
Source

Macros

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
Source

Nested types