class Mosquito::JobRun

Overview

A JobRun is a unit of work which will be performed by a Job. JobRuns know how to:

JobRun data is called config and is persisted in the backend under the key mosquito:job_run:job_run_id.

Defined in:

mosquito/job_run.cr

Constant Summary

CONFIG_KEY_PREFIX = "job_run"

Constructors

Class Method Summary

Instance Method Summary

Constructor Detail

def self.new(type : String, enqueue_time : Time = Time.utc, id : String | Nil = nil, retry_count : Int32 = 0, started_at : Time | Nil = nil, finished_at : Time | Nil = nil) #

Class Method Detail

def self.config_key(*parts) #

The config key is the backend storage key for the metadata of this job_run.


def self.retrieve(id : String) #

Used to construct a job_run from the parameters stored in the backend.


Instance Method Detail

def ==(other : self) #
Description copied from class Reference

Returns true if this reference is the same as other. Invokes same?.


def build_job : Mosquito::Job #

Builds a Job instance from this job_run. Populates the job with config from the backend.


def claimed_by(overseer : Runners::Overseer) #

Marks this job run as claimed by the given overseer and persists the association to the backend. Used by the pending cleanup to determine whether the owning overseer is still alive.


def config_key #

The config key is the backend storage key for the metadata of this job_run.


def delete(in ttl : Int = 0) #

Deletes this job_run from the backend. Optionally, after a delay in seconds (handled by the backend).


def enqueue_time : Time #

def fail #

Fails this job run and make sure it's persisted as such. Clears the overseer_id since the job is no longer in-flight.


def finished_at : Time | Nil #

def id : String #

def job : Mosquito::Job | Nil #

def job! : Mosquito::Job #

def overseer_id : String | Nil #

def reload : Nil #

Updates this job_run config from the backend.


def reschedule_interval #

For the current retry count, how long should a runner wait before retry?


def rescheduleable? #

For the current retry count, is the job rescheduleable?


def retry_count : Int32 #

def retry_or_banish(queue : Queue) : Nil #

Treats this job run as a failure: increments the retry count and either reschedules with backoff or banishes to the dead queue.


def run #

Builds and runs the job with this job_run config.


def started_at : Time | Nil #

def store #

Stores this job run configuration and metadata in the backend. Nil-valued fields are deleted from the backend hash.


def to_s(io : IO) #
Description copied from class Reference

Appends a short String representation of this object which includes its class name and its object address.

class Person
  def initialize(@name : String, @age : Int32)
  end
end

Person.new("John", 32).to_s # => #<Person:0x10a199f20>

def type : String #