abstract struct Conveyor::Job
- Conveyor::Job
- Struct
- Value
- Object
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
- JSON::Serializable
Direct Known Subclasses
Defined in:
job.crConstructors
Class Method Summary
-
.dequeue(id : String, *, configuration config : Configuration = CONFIG) : Nil
Remove this job from all queues.
- .max_attempts(max_attempts : Int32)
- .max_attempts : Int32
-
.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.
Macro Summary
-
queue(name)
Define the queue your job will enqueue on by default
Instance Method Summary
-
#call
Override this method to provide this job's functionality.
-
#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.
-
#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.
-
#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.
Constructor Detail
Class Method Detail
Remove this job from all queues. This method will not unschedule the job.
If this job was scheduled via one of the #schedule
methods, this method will remove it from the schedule.
Macro Detail
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
Instance Method Detail
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
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
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