Interface StepDescriptor

How a workflow describes one of its steps to the executor: its name, its retries, its step policies, and how to build it for an attempt. The executor reads it and never anything else about the step.

Only itinera makes one, for each step a workflow lists with @withStep or its builder: an object written by hand, with the same members, is not a step descriptor and does not compile where one is expected.

import assert from "node:assert/strict";
import { type Provided, provider, service, serviceType } from "itinera/service";
import {
type Outcome,
Step,
step,
type StepName,
stepName,
} from "itinera/step";
import {
inputAdapter,
key,
type Supplied,
withStep,
Workflow,
workflow,
} from "itinera/workflow";

const RECEIPTS = serviceType<string[]>("Receipts");

@step()
class Charge extends Step {
override run(@service("receipts", RECEIPTS) receipts: string[]): Outcome {
receipts.push("charged");
return this.succeed();
}
}

@workflow({ name: "payments" })
@withStep(Charge, {
name: "charge",
retryBudget: 2,
noRetryOnAbnormalTermination: true,
})
class Payments extends Workflow {
@inputAdapter({ steps: ["charge"] })
price(@key() key: string): Supplied {
return this.supply(key.length);
}

@provider(RECEIPTS, { perAttempt: true })
receipts(@stepName() step: StepName): Provided<string[]> {
return this.provide([`receipts of ${step}`]);
}
}

const { descriptor, workflow: payments } = Payments.build().instance();
const [charge] = descriptor.steps();
assert.ok(charge);

assert.equal(descriptor.name, "payments");
assert.equal(charge.name, "charge");
assert.equal(charge.retryBudget, 2);
assert.equal(charge.retryOnAbnormalTermination, false);
assert.ok(charge.build() instanceof Charge);
assert.deepEqual(descriptor.reporters(), []);
assert.deepEqual(descriptor.adapt(payments, charge.name, ["amount"]), {
kind: "supplied",
value: 6,
});
assert.deepEqual(
descriptor.provide(payments, charge.name, "receipts", [charge.name]),
{ instance: ["receipts of charge"] },
);
interface StepDescriptor {
    name: StepName;
    retryBudget: number;
    retryOnAbnormalTermination: boolean;
    build(needs?: readonly unknown[]): Step;
    policies(): readonly PolicyDescriptor[];
}

Index

name: StepName

The step's name, unique in its workflow.

retryBudget: number

How many times the step may be retried after its first attempt: 0 when the workflow says nothing.

retryOnAbnormalTermination: boolean

Whether an attempt that ends in an abnormal termination is retried while the retry budget lasts: true when the workflow says nothing.

  • Builds the step for one attempt, as a new object, giving its constructor needs, what its constructor's requests were answered with, in order.

    Parameters

    • needs: readonly unknown[] = []

    Returns Step

    Whatever the step's constructor throws.