Lightning.Workflows.Snapshot (Lightning v2.20.1)

Copy Markdown View Source

Ecto model for Workflow Snapshots.

Snapshots are a way to store the state of a workflow at a given point in time.

Summary

Functions

The id of the snapshot holding the workflow's current content.

Gets snapshots by id, scoped to a project via each snapshot's workflow.

Get the latest snapshot for a workflow, based on the lock_version.

Turns a snapshot into attributes to write back as a workflow's content.

Types

t()

@type t() :: %Lightning.Workflows.Snapshot{
  __meta__: Ecto.Schema.Metadata.t(),
  edges: [
    %Lightning.Workflows.Snapshot.Edge{
      condition_expression: term(),
      condition_label: term(),
      condition_type: term(),
      enabled: term(),
      id: term(),
      inserted_at: term(),
      source_job_id: term(),
      source_trigger_id: term(),
      target_job_id: term(),
      updated_at: term()
    }
  ],
  id: Ecto.UUID.t() | nil,
  inserted_at: term(),
  jobs: [
    %Lightning.Workflows.Snapshot.Job{
      adaptor: term(),
      body: term(),
      credential: term(),
      id: term(),
      inserted_at: term(),
      keychain_credential: term(),
      keychain_credential_id: term(),
      name: term(),
      project_credential: term(),
      project_credential_id: term(),
      updated_at: term()
    }
  ],
  lock_version: term(),
  name: String.t() | nil,
  positions: map() | nil,
  triggers: [
    %Lightning.Workflows.Snapshot.Trigger{
      comment: term(),
      cron_cursor_job_id: term(),
      cron_expression: term(),
      custom_path: term(),
      enabled: term(),
      has_auth_method: term(),
      id: term(),
      inserted_at: term(),
      type: term(),
      updated_at: term(),
      webhook_auth_methods: term(),
      webhook_reply: term(),
      webhook_response_config: term()
    }
  ],
  workflow:
    nil | Lightning.Workflows.Workflow.t() | Ecto.Association.NotLoaded.t(),
  workflow_id: term()
}

Functions

build(workflow)

create(workflow)

@spec create(Lightning.Workflows.Workflow.t()) ::
  {:ok, t()} | {:error, Ecto.Changeset.t()}

current_id_for(workflow_id)

@spec current_id_for(Ecto.UUID.t()) :: Ecto.UUID.t() | nil

The id of the snapshot holding the workflow's current content.

Callers asking "is this the content that is live right now?" need identity. A lock version is a near-enough proxy until it isn't: nothing enforces one snapshot per (workflow_id, lock_version), and a client comparing numbers cannot tell two snapshots apart.

get_all_by_ids(ids, project_id)

@spec get_all_by_ids([Ecto.UUID.t()], Ecto.UUID.t()) :: [t()]

Gets snapshots by id, scoped to a project via each snapshot's workflow.

Only snapshots whose workflow belongs to project_id are returned, so this can't be used to read another project's snapshots.

get_all_for(workflow)

@spec get_all_for(Lightning.Workflows.Workflow.t()) :: [t()]

get_by_version(workflow_id, version)

get_current_for(workflow)

@spec get_current_for(Lightning.Workflows.Workflow.t()) :: t() | nil

Get the latest snapshot for a workflow, based on the lock_version.

It returns the latest snapshot regardless of the lock_version of the workflow passed in.

include_latest_snapshot(multi, name \\ :snapshot, workflow)

@spec include_latest_snapshot(
  Ecto.Multi.t(),
  binary() | :snapshot,
  Lightning.Workflows.Workflow.t()
) ::
  Ecto.Multi.t()

new(workflow)

to_workflow_attrs(snapshot)

@spec to_workflow_attrs(t()) :: map()

Turns a snapshot into attributes to write back as a workflow's content.

on_replace deletes anything the snapshot does not hold, which is what makes a restore a revert rather than a merge.

Trigger enabled is left out: a restore publishes into a live workflow, and an old enabled flag would take production offline mid-rollback. A re-created trigger arrives off, because a snapshot does not record its webhook auth methods. positions is written only when the snapshot holds them, so an older snapshot cannot wipe a hand-arranged canvas.