View Source Lightning.Workflows (Lightning v2.10.4)

The Workflows context.

Summary

Functions

Builds a Trigger

Creates a snapshot from a multi.

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

Creates an edge

Gets an Edge by its associated Trigger.

Returns a list of edges with jobs to execute, given a current timestamp in Unix. This is used by the scheduler, which calls this function once every minute.

Gets a single Trigger by its custom_path or id.

Gets a Single Edge by it's webhook trigger.

Gets a single workflow.

Retrieves a list of active Workflows with their jobs and triggers preloaded.

A way to ensure the consistency of nodes. This query orders jobs based on their inserted_at timestamps in ascending order

Returns the list of workflows.

Returns an %Ecto.Changeset{} for changing the workflow request_deletion.

See Lightning.Workflows.Events.subscribe/1.

Updates a trigger

Functions

Builds a Trigger

Creates a snapshot from a multi.

When the multi already has a :workflow change, it is assumed to be changed or inserted and will attempt to build and insert a new snapshot.

When there isn't a :workflow change, it tries to find a dependant model like a Job, Trigger or Edge and uses the workflow associated with that model.

In this case we assume that the workflow wasn't actually updated, Workflow.touch() is called to bump the updated_at and the lock_version of the workflow before a snapshot is captured.

Link to this function

change_workflow(workflow, attrs \\ %{})

View Source

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

Examples

iex> change_workflow(workflow)
%Ecto.Changeset{data: %Workflow{}}
Link to this function

create_edge(attrs, actor)

View Source

Creates an edge

Link to this function

get_edge_by_trigger(trigger)

View Source

Gets an Edge by its associated Trigger.

Parameters

  • %Trigger{id: trigger_id}: A Trigger struct from which the associated Edge is to be found.

Returns

  • Returns an Edge struct preloaded with its source_trigger and target_job if found.
  • Returns nil if no Edge is associated with the given Trigger.

Examples

trigger = %Trigger{id: 1, ...}
Lightning.Workflows.get_edge_by_trigger(trigger)
# => %Edge{source_trigger: %Trigger{}, target_job: %Job{}, ...}

non_existent_trigger = %Trigger{id: 999, ...}
Lightning.Workflows.get_edge_by_trigger(non_existent_trigger)
# => nil
Link to this function

get_edges_for_cron_execution(datetime)

View Source
@spec get_edges_for_cron_execution(DateTime.t()) :: [Lightning.Workflows.Edge.t()]

Returns a list of edges with jobs to execute, given a current timestamp in Unix. This is used by the scheduler, which calls this function once every minute.

Link to this function

get_trigger_by_webhook(path)

View Source

Gets a single Trigger by its custom_path or id.

Parameters

  • path: A binary string representing the custom_path or id of the trigger.

Returns

  • Returns a Trigger struct if a trigger is found.
  • Returns nil if no trigger is found for the given path.

Examples

Lightning.Workflows.get_trigger_by_webhook("some_path_or_id")
# => %Trigger{id: 1, custom_path: "some_path_or_id", ...}

Lightning.Workflows.get_trigger_by_webhook("non_existent_path_or_id")
# => nil
Link to this function

get_webhook_trigger(path, opts \\ [])

View Source

Gets a Single Edge by it's webhook trigger.

Gets a single workflow.

Raises Ecto.NoResultsError if the Workflow does not exist.

Examples

iex> get_workflow!(123)
%Workflow{}

iex> get_workflow!(456)
** (Ecto.NoResultsError)
Link to this function

get_workflows_for(project)

View Source
@spec get_workflows_for(Lightning.Projects.Project.t()) :: [
  Lightning.Workflows.Workflow.t()
]

Retrieves a list of active Workflows with their jobs and triggers preloaded.

Link to this function

has_newer_version?(workflow)

View Source

A way to ensure the consistency of nodes. This query orders jobs based on their inserted_at timestamps in ascending order

Returns the list of workflows.

Examples

iex> list_workflows()
[%Workflow{}, ...]
Link to this function

mark_for_deletion(workflow, attrs \\ %{})

View Source

Returns an %Ecto.Changeset{} for changing the workflow request_deletion.

Examples

iex> change_request_deletion(workflow)
%Ecto.Changeset{data: %Workflow{}}
Link to this function

publish_kafka_trigger_events(changeset)

View Source
@spec publish_kafka_trigger_events(Ecto.Changeset.t(Lightning.Workflows.Workflow.t())) ::
  :ok
Link to this function

save_workflow(changeset, actor)

View Source
@spec save_workflow(
  Ecto.Changeset.t(Lightning.Workflows.Workflow.t()) | map(),
  struct()
) ::
  {:ok, Lightning.Workflows.Workflow.t()}
  | {:error, Ecto.Changeset.t(Lightning.Workflows.Workflow.t())}
  | {:error, :workflow_deleted}

See Lightning.Workflows.Events.subscribe/1.

Link to this function

to_project_space(workflows)

View Source
@spec to_project_space([Lightning.Workflows.Workflow.t()]) :: %{}
Link to this function

update_trigger(trigger, attrs)

View Source

Updates a trigger

Link to this function

workflow_exists?(project_id, workflow_name)

View Source

Check if workflow exist