Osy#betaRun it on Osyrin: osyrin.com

Reference / Workflow

Version — which version of a workflow is running, and which file declares it

<Wf>.Version -> int // <Wf>.Graph.SourceFile -> string?

`<Wf>.Version` is the number of the app version the code runs in — the same number a migration header names (`migration OrderFlow v6 -> v7`) and the version a new run pins. `<Wf>.Graph.SourceFile` is the file that declares the workflow. Together they let a page say "OrderFlow v7, declared in workflows/order-flow.osy".

preview1 example compiled by CIworkflowqueries

Summary#

<Wf>.Version answers "which version of this process is running?" with an int: the app version the code is running in. It is the number a workflow migration names — migration OrderFlow v6 -> v7 moves runs from the sixth version of the app to the seventh — and the version every run started now is pinned to.

int v = OrderFlow.Version;               // 7
string? file = OrderFlow.Graph.SourceFile; // "workflows/order-flow.osy"

Signature#

<Wf>.Version -> int                 // the app version the code runs in; 1 for an app on its first version
<Wf>.Graph.SourceFile -> string?    // the file that declares the workflow, its path from the app root

Description#

Why the app's version, and not the workflow's own#

A workflow has no version of its own that moves: every app version is compiled fresh, so the workflow's revision row says 1 in every version. The platform's one idiom for "which version of a workflow" is therefore the app version — the number migrations are written against (Migrating runs that are still in flight). Two workflows in the same app answer the same number; the number changes when the app is published, whether or not that workflow changed.

It is a server read#

The version is a fact about where the code runs, not about the declaration, so <Wf>.Version is answered on the server (it costs no database statement). Read it in a function, or in a live var, like any other server value. The workflow name is checked at compile time: NoSuchFlow.Version is an error, not a zero.

Code running a run that was started on an earlier version still executes in that version, and reads that version's number.

SourceFile#

<Wf>.Graph.SourceFile is set when the compiler builds the graph, like the rest of Graph — every state and every transition of a workflow, so it names the file of the version that is running and costs nothing. It is the path from the app root (workflows/order-flow.osy), not just the file name — see Graph — every state and every transition of a workflow. It is null for a workflow that has no file.

Examples#

using Osysharp.Workflow;

enum JobStatus { Working, Done }

entity Job {
  [Required, MaxLength(80)] string Title;
  JobStatus Status = JobStatus.Working;
}

workflow JobFlow {
  Tracks    = Job.Status;
  Autostart = false;
  Initial   = Working;
  event Finish();
  state Working { on Finish { goto Done; } }
  terminal success Done { }
}

[Test]
void a_new_app_is_on_its_first_version_and_the_workflow_names_its_file() {
  Assert.Equal(1, JobFlow.Version);
  Assert.True(JobFlow.Graph.SourceFile != null);
}

See also#

Related

Graph — every state and every transition of a workflow

The whole shape of a workflow — every state (with its label, and whether it starts or ends a run) and every transition…

Migrating runs that are still in flight

A deploy that renames or removes a workflow state leaves runs parked in it with nowhere to stand. A workflow migration…

Workflow.Current (which run is this code in?)

`Workflow.Current` is the workflow run this code is executing in — one value saying its id, the workflow's declared…

Workflows (the run that outlives the request)

A `workflow` is a run that survives the process it started in — it parks, waits days for a person or a timer, and…