Class: ActiveJob::Base

Inherits:
Object show all
Defined in:
runtime/active_job/base.rb,
runtime/active_job/base.rbs

Overview

The job class contract — the members every dispatch path reads: recurring calls job_name to key the registration, the adapter's handler catalog is keyed by the same name, and the body runs as job_class.perform(data) — a class method; this runtime never instantiates a job. data is the decoded payload (nil when none). The base implements job_name (the class name); the bodies stay raising specs (the Sqlx::Base pattern) — a job that forgot a body fails loud with the contract named, wherever it was driven from.

Class Method Summary collapse

  • .job_name ⇒ String

    the key the job registers and is dispatched under: the recurring beat's name, the adapter's handler catalog entry, and the name a store-backed drain resolves back to the class all use it.

  • .perform(data) ⇒ void

    the job body, a class method: every runtime-driven path calls it with one argument — data is the decoded payload, nil for a payload-less job — so one call shape covers both (recurring's beat, enqueue, a store-backed drain); a job that takes no arguments still declares the parameter and ignores it.

Class Method Details

.job_name ⇒ String

the key the job registers and is dispatched under: the recurring beat's name, the adapter's handler catalog entry, and the name a store-backed drain resolves back to the class all use it. The base derives it from the class name (name); a job overrides this method when the key must differ — for cross-process dispatch the key must stay a constant path (Object.const_get resolves it on the store-backed drain).

Examples:

derived — the class name is the key, nothing to declare

class CleanupJob < ActiveJob::Base
end

override — the key differs from the class name

def self.job_name = "nightly-cleanup"

Returns:

  • (String) —

    the job's name — the class name by default; not input, and not validated: a name no constant carries surfaces as the runner's own loud miss at dispatch



238
# File 'runtime/active_job/base.rb', line 238

def self.job_name: () -> String

.perform(data) ⇒ void

the job body, a class method: every runtime-driven path calls it with one argument — data is the decoded payload, nil for a payload-less job — so one call shape covers both (recurring's beat, enqueue, a store-backed drain); a job that takes no arguments still declares the parameter and ignores it. The runtime never instantiates a job. The base raises so a job that forgot the body fails loud with the contract named instead of a bare NoMethodError at its first fire.

Examples:

def self.perform(data)
  Cleanup.run_once
end

Parameters:

  • data (Object, nil) —

    the decoded payload, nil for a payload-less job

Raises:

  • (NotImplementedError) —

    on the base — the subclass has not overridden it



258
# File 'runtime/active_job/base.rb', line 258

def self.perform: (untyped? data) -> void