Lightning.Jobs (Lightning v2.19.0-pre)

View Source

The Jobs context.

Summary

Functions

Returns an %Ecto.Changeset{} for tracking job changes.

Returns the list of downstream jobs for a given job, optionally matching a specific trigger type. When downstream_jobs_for is called without a trigger that means its between jobs when it called with a trigger that means we are starting from outside the pipeline

Gets a single job.

Gets a single job.

Gets the name of a job in a project.

Gets a job by id, scoped to a workflow, with its credential preloaded.

Returns the list of jobs excluding the one given.

Returns true when the job belongs to the given project (via its workflow).

Returns the list of jobs.

Updates a job.

Functions

change_job(job, attrs \\ %{})

Returns an %Ecto.Changeset{} for tracking job changes.

Examples

iex> change_job(job)
%Ecto.Changeset{data: %Job{}}

create_job(attrs \\ %{}, actor)

Creates a job.

Examples

iex> create_job(%{field: value})
{:ok, %Job{}}

iex> create_job(%{field: bad_value})
{:error, %Ecto.Changeset{}}

get_downstream_jobs_for(job, edge_condition \\ nil)

Returns the list of downstream jobs for a given job, optionally matching a specific trigger type. When downstream_jobs_for is called without a trigger that means its between jobs when it called with a trigger that means we are starting from outside the pipeline

get_job(id, opts \\ [])

Gets a single job.

Returns {:ok, job} if found, {:error, :not_found} otherwise.

Options

  • :include - list of associations to preload (default: [])

get_job!(id)

Gets a single job.

Raises Ecto.NoResultsError if the Job does not exist.

Examples

iex> get_job!(123)
%Job{}

iex> get_job!(456)
** (Ecto.NoResultsError)

get_job_name(project_id, job_id)

Gets the name of a job in a project.

Returns nil when the id names no job in that project — including when it is not a UUID at all, since it reaches here from a query string.

get_job_with_credential(id, workflow_id)

Gets a job by id, scoped to a workflow, with its credential preloaded.

Returns nil when the job does not exist or belongs to another workflow, so a caller cannot read a job (and resolve its credential) outside the workflow it supplies.

get_upstream_jobs_for(map)

@spec get_upstream_jobs_for(Lightning.Workflows.Job.t()) :: [
  Lightning.Workflows.Job.t()
]

Returns the list of jobs excluding the one given.

job_in_project?(job_id, project)

@spec job_in_project?(Ecto.UUID.t(), Lightning.Projects.Project.t()) :: boolean()

Returns true when the job belongs to the given project (via its workflow).

A non-UUID job_id returns false rather than raising, so malformed, missing and cross-project ids are all handled uniformly.

jobs_for_project(project)

@spec jobs_for_project(Lightning.Projects.Project.t()) :: [
  Lightning.Workflows.Job.t()
]

jobs_for_project_query(project)

@spec jobs_for_project_query(Lightning.Projects.Project.t()) :: Ecto.Queryable.t()

list_active_cron_jobs()

list_jobs()

Returns the list of jobs.

list_jobs_for_workflow(workflow)

@spec list_jobs_for_workflow(Lightning.Workflows.Workflow.t()) ::
  [Lightning.Workflows.Job.t(), ...] | []

update_job(job, attrs)

Updates a job.

Examples

iex> update_job(job, %{field: new_value})
{:ok, %Job{}}

iex> update_job(job, %{field: bad_value})
{:error, %Ecto.Changeset{}}