Get started
Get a durable workflow running in about five minutes, using nothing but your app and a Postgres connection string.
Prerequisites
Section titled “Prerequisites”Install
Section titled “Install”dotnet add package PgWorkflowsRegister PgWorkflows
Section titled “Register PgWorkflows”Point the builder at your Postgres connection string and register your workflows and activities. The hosted worker is configured for you.
builder.Services.AddPgWorkflows(pg => pg.UsePostgres(connectionString) .AddWorkflow<GreetingWorkflow>() .AddActivities<HelloActivities>());Define a workflow and its activities
Section titled “Define a workflow and its activities”A workflow is an ordinary C# class; activities hold the side effects.
[Workflow("greeting")]public sealed class GreetingWorkflow{ [WorkflowRun] public async ValueTask<string> RunAsync( IWorkflowContext ctx, string name, CancellationToken cancellationToken ) { return await ctx.Activity( (HelloActivities a) => a.Hello(name), cancellationToken ); }}
public sealed class HelloActivities{ [Activity("hello")] public string Hello(string name) => $"Hello, {name}!";}Start it
Section titled “Start it”var workflows = app.Services.GetRequiredService<IPgWorkflowClient>();var result = await workflows.ExecuteAsync<GreetingWorkflow, string, string>("Postgres");Next steps
Section titled “Next steps”- Understand the mental model in how PgWorkflows works.
- Explore fan-in fan-out, sleep, and signals.