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
Check if workflow exist
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.
Returns an %Ecto.Changeset{}
for tracking workflow changes.
Examples
iex> change_workflow(workflow)
%Ecto.Changeset{data: %Workflow{}}
Creates an edge
Gets an Edge
by its associated Trigger
.
Parameters
%Trigger{id: trigger_id}
: ATrigger
struct from which the associatedEdge
is to be found.
Returns
- Returns an
Edge
struct preloaded with itssource_trigger
andtarget_job
if found. - Returns
nil
if noEdge
is associated with the givenTrigger
.
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
@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.
Gets a single Trigger
by its custom_path
or id
.
Parameters
path
: A binary string representing thecustom_path
orid
of the trigger.
Returns
- Returns a
Trigger
struct if a trigger is found. - Returns
nil
if no trigger is found for the givenpath
.
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
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)
@spec get_workflows_for(Lightning.Projects.Project.t()) :: [ Lightning.Workflows.Workflow.t() ]
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.
Examples
iex> list_workflows()
[%Workflow{}, ...]
Returns an %Ecto.Changeset{}
for changing the workflow request_deletion.
Examples
iex> change_request_deletion(workflow)
%Ecto.Changeset{data: %Workflow{}}
@spec publish_kafka_trigger_events(Ecto.Changeset.t(Lightning.Workflows.Workflow.t())) :: :ok
@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
.
@spec to_project_space([Lightning.Workflows.Workflow.t()]) :: %{}
Updates a trigger
Check if workflow exist