Schedules - .NET SDK
This page shows how to do the following:
- Schedule a Workflow
- Create a Scheduled Workflow
- Backfill a Scheduled Workflow
- Delete a Scheduled Workflow
- Describe a Scheduled Workflow
- List a Scheduled Workflow
- Pause a Scheduled Workflow
- Trigger a Scheduled Workflow
- Update a Scheduled Workflow
- Use Start Delay
Schedule a Workflow
How to Schedule a Workflow using the Temporal .NET SDK
Scheduling Workflows is a crucial aspect of any automation process, especially when dealing with time-sensitive tasks. By scheduling a Workflow, you can automate repetitive tasks, reduce the need for manual intervention, and ensure timely execution of your business processes
Use any of the following action to help Schedule a Workflow Execution and take control over your automation process.
Create a Scheduled Workflow
How to create a Scheduled Workflow using the Temporal .NET SDK
The create action enables you to create a new Schedule. When you create a new Schedule, a unique Schedule ID is generated, which you can use to reference the Schedule in other Schedule commands.
To create a Scheduled Workflow Execution in .NET, use the CreateScheduleAsync
method on the Client.
Then pass the Schedule ID and the Schedule object to the method to create a Scheduled Workflow Execution.
Set the Schedule's Action
property to an instance of ScheduleActionStartWorkflow
to schedule a Workflow Execution.
using Temporalio.Client;
using Temporalio.Client.Schedules;
var client = await TemporalClient.ConnectAsync(new("localhost:7233"));
var handle = await client.CreateScheduleAsync(
"my-schedule-id",
new(
Action: ScheduleActionStartWorkflow.Create(
(MyWorkflow wf) => wf.RunAsync(),
new(id: "my-workflow-id", taskQueue: "my-task-queue")),
Spec: new()
{
Intervals = new List<ScheduleIntervalSpec> { new(Every: TimeSpan.FromDays(5)) },
}));
Once a Schedule has completed creating all its Workflow Executions, the Temporal Service deletes it since it won’t fire again. The Temporal Service doesn't guarantee when this removal will happen.
Backfill a Scheduled Workflow
How to backfill a Scheduled Workflow using the Temporal .NET SDK
The backfill action executes Actions ahead of their specified time range. This command is useful when you need to execute a missed or delayed Action, or when you want to test the Workflow before its scheduled time.
To backfill a Scheduled Workflow Execution in .NET, use the BackfillAsync() method on the Schedule Handle.
using Temporalio.Client;
using Temporalio.Client.Schedules;
var client = await TemporalClient.ConnectAsync(new("localhost:7233"));
var handle = client.GetScheduleHandle("my-schedule-id");
var now = DateTime.Now;
await handle.BackfillAsync(new List<ScheduleBackfill>
{
new(
StartAt: now - TimeSpan.FromDays(30),
EndAt: now - TimeSpan.FromDays(20),
Overlap: ScheduleOverlapPolicy.AllowAll),
});
Delete a Scheduled Workflow
How to delete a Scheduled Workflow using the Temporal .NET SDK
The delete action enables you to delete a Schedule. When you delete a Schedule, it does not affect any Workflows that were started by the Schedule.
To delete a Scheduled Workflow Execution in .NET, use the DeleteAsync() method on the Schedule Handle.
using Temporalio.Client;
using Temporalio.Client.Schedules;
var client = await TemporalClient.ConnectAsync(new("localhost:7233"));
var handle = client.GetScheduleHandle("my-schedule-id");
await handle.DeleteAsync();
Describe a Scheduled Workflow
How to describe a Scheduled Workflow using the Temporal .NET SDK
The describe action shows the current Schedule configuration, including information about past, current, and future Workflow Runs. This command is helpful when you want to get a detailed view of the Schedule and its associated Workflow Runs.
To describe a Scheduled Workflow Execution in .NET, use the DescribeAsync() method on the Schedule Handle.
using Temporalio.Client;
using Temporalio.Client.Schedules;
var client = await TemporalClient.ConnectAsync(new("localhost:7233"));
var handle = client.GetScheduleHandle("my-schedule-id");
var desc = await handle.DescribeAsync();
Console.WriteLine("Schedule info: {0}", desc.Info);
List a Scheduled Workflow
How to list a Scheduled Workflow using the Temporal .NET SDK
The list action lists all the available Schedules. This command is useful when you want to view a list of all the Schedules and their respective Schedule IDs.
To list all schedules, use the ListSchedulesAsync() asynchronous method on the Client. This returns an async enumerable. If a schedule is added or deleted, it may not be available in the list immediately.
using Temporalio.Client;
using Temporalio.Client.Schedules;
var client = await TemporalClient.ConnectAsync(new("localhost:7233"));
await foreach (var desc in client.ListSchedulesAsync())
{
Console.WriteLine("Schedule info: {0}", desc.Info);
}