Skip to content

Starting workflows

IPgWorkflowClient is how your application code talks to PgWorkflows: start a run and await its result, or fire-and-track with a handle.

When you want the result inline:

var result = await workflows.ExecuteAsync<GreetingWorkflow, GreetingInput, string>(
new GreetingInput("Postgres", 42)
);

When the workflow is long-running, start it and keep a handle:

var handle = await workflows.StartAsync<TrialOnboardingWorkflow, SignupInput, string>(
new SignupInput("Acme", "[email protected]")
);
Console.WriteLine(handle.WorkflowRunId);
var result = await handle.GetResultAsync();

Pass an idempotency key so a retried producer doesn’t start the same workflow twice:

var handle = await workflows.StartAsync<TrialOnboardingWorkflow, SignupInput, string>(
new SignupInput("Acme", "[email protected]"),
idempotencyKey: $"signup:{signupId}"
);