GoodJob.Job (good_job v1.0.0)

Copy Markdown View Source

Ecto schema for good_jobs table.

Represents a job in the queue.

Summary

Functions

Builds a job for enqueueing.

Creates a changeset for a job.

Deletes a job from the database.

Deletes multiple jobs in two queries (fetch by id, then delete all matching rows).

Enqueues a job.

Retries a discarded job by clearing its finished_at and error fields.

Retries multiple jobs in one UPDATE, matching retry/1 field changes.

Types

t()

@type t() :: %GoodJob.Job{
  __meta__: term(),
  active_job_id: term(),
  batch_callback_id: term(),
  batch_id: term(),
  concurrency_key: term(),
  cron_at: term(),
  cron_key: term(),
  error: term(),
  error_event: term(),
  executions_count: term(),
  finished_at: term(),
  id: term(),
  inserted_at: term(),
  is_discrete: term(),
  job_class: term(),
  labels: term(),
  lock_type: term(),
  locked_at: term(),
  locked_by_id: term(),
  performed_at: term(),
  priority: term(),
  queue_name: term(),
  retried_good_job_id: term(),
  scheduled_at: term(),
  serialized_params: term(),
  updated_at: term()
}

Functions

advisory_locked(query \\ __MODULE__)

advisory_unlocked(query \\ __MODULE__)

build_for_enqueue(attrs)

Builds a job for enqueueing.

calculate_state(job)

See GoodJob.Job.State.calculate/1.

changeset(job, attrs)

Creates a changeset for a job.

created_after(query \\ __MODULE__, datetime)

created_before(query \\ __MODULE__, datetime)

delete(job)

Deletes a job from the database.

delete_many(ids)

@spec delete_many([Ecto.UUID.t() | String.t()]) ::
  {:ok, non_neg_integer()} | {:error, term()}

Deletes multiple jobs in two queries (fetch by id, then delete all matching rows).

Emits the same PubSub and telemetry events per job as delete/1. ids may be a list of t:Ecto.UUID strings (as returned from the database or UI).

dequeueing_ordered(query \\ __MODULE__)

discarded(query \\ __MODULE__)

@spec discarded(Ecto.Query.t() | module()) :: Ecto.Query.t()

enqueue(attrs, opts \\ [])

Enqueues a job.

This inserts the row only; it does not run GoodJob.Concurrency checks. Use GoodJob.enqueue/3 when you need per-key enqueue limits enforced before insert.

Options

  • :listen_notify - When false, skips pg_notify (PubSub and telemetry still run). Used by GoodJob.Bulk to send a single notification after a batch insert.

exclude_paused(query \\ __MODULE__)

find_by_active_job_id(active_job_id)

find_by_id(id)

finished(query \\ __MODULE__)

finished_before(query \\ __MODULE__, datetime)

in_batch(query \\ __MODULE__, batch_id)

in_queue(query \\ __MODULE__, queue_name)

joins_advisory_locks(query \\ __MODULE__)

locked(query \\ __MODULE__)

only_scheduled(query \\ __MODULE__)

order_by_created_asc(query \\ __MODULE__)

order_by_created_desc(query \\ __MODULE__)

order_by_finished_desc(query \\ __MODULE__)

order_by_scheduled_asc(query \\ __MODULE__)

order_for_candidate_lookup(query \\ __MODULE__, parsed_queues \\ %{})

queue_ordered(query \\ __MODULE__, queues)

queued(query \\ __MODULE__)

retry(job)

Retries a discarded job by clearing its finished_at and error fields.

retry_many(ids)

@spec retry_many([Ecto.UUID.t() | String.t()]) ::
  {:ok, non_neg_integer()} | {:error, term()}

Retries multiple jobs in one UPDATE, matching retry/1 field changes.

Emits the same PubSub and telemetry events per job as retry/1 (using structs loaded before the update).

running(query \\ __MODULE__)

scheduled(query \\ __MODULE__)

scheduled_before(query \\ __MODULE__, datetime)

succeeded(query \\ __MODULE__)

@spec succeeded(Ecto.Query.t() | module()) :: Ecto.Query.t()

unfinished(query \\ __MODULE__)

unlocked(query \\ __MODULE__)

with_all_labels(query \\ __MODULE__, labels)

with_any_label(query \\ __MODULE__, labels)

with_batch_id(query \\ __MODULE__, batch_id)

with_concurrency_key(query \\ __MODULE__, key)

with_cron_key(query \\ __MODULE__, cron_key)

with_errors(query \\ __MODULE__)

with_job_class(query \\ __MODULE__, job_class)

with_label(query \\ __MODULE__, label)

with_labels(query \\ __MODULE__, labels)

with_max_priority(query \\ __MODULE__, max_priority)

with_min_priority(query \\ __MODULE__, min_priority)

with_priority(query \\ __MODULE__, priority)

without_errors(query \\ __MODULE__)