# Schedule workflows

A **workflow schedule** starts a [workflow](https://docs.diagrid.io/concepts/workflows) repeatedly on a cron schedule, for example every night at 02:00 or every 15 minutes. Each time the schedule matches, Diagrid starts a new, independent execution of the workflow: a **run**. The schedule keeps track of when it runs next, how many runs it has started and how the last run went, so you no longer need a job handler that starts the workflow, or a workflow that sleeps in a loop, to run something on a timer.

You create, inspect, trigger and delete schedules from your app with the workflow client of its SDK, with the `diagrid workflow schedule` commands, or in the Diagrid Console. This page covers the SDK and the CLI; for the console, see [Operate workflow schedules](https://docs.diagrid.io/operate/project-operations/workflow-schedules).

:::note
The workflow client methods on this page ship in the next release of each Dapr SDK. Until then, create and manage schedules with the Diagrid CLI or in the Diagrid Console. The runs they start are ordinary workflow executions, which your current SDK already handles.
:::

## How a schedule runs

Each schedule is run by Diagrid itself, as a small internal workflow that belongs to your App ID. It waits on a durable timer until the next time the schedule matches, then starts your workflow as a new execution. Because it is built on the same durable timers and state as any other workflow, a schedule survives restarts and redeployments of your app, and needs no extra component.

**Diagram: A schedule and its runs.** The schedule waits in Diagrid until its next time, then starts a run. The run executes on your workflow worker like any other execution.

- **Diagrid**: App ID (reports), Schedule (nightly-report), Run (nightly-report_8bfcbd_20261130T020000Z)
- Client (console, CLI or SDK), Workflow worker (your app)

- Client (console, CLI or SDK) → App ID (reports)
- App ID (reports) → Schedule (nightly-report)
- Schedule (nightly-report) → Run (nightly-report_8bfcbd_20261130T020000Z) (starts)
- Run (nightly-report_8bfcbd_20261130T020000Z) → Workflow worker (your app) (runs on)

- **Runs are ordinary workflow executions.** Each run has the instance ID `<schedule name>_<owner>_<time>`. The owner is a tag of the App ID that owns the schedule: the first 6 hex characters of the SHA-256 of `<namespace>/<App ID>`. It keeps apart the runs of same-named schedules in two apps that target one app. The time is when the run was due, in UTC, formatted as `20060102T150405Z`. A run started by [triggering](#list-trigger-and-delete) the schedule has the ID `<schedule name>_<owner>_<time>_manual`, where the time has milliseconds.
- **Runs are independent of the schedule.** A run that fails does not stop the schedule, and deleting a schedule does not touch the runs it already started. Manage runs as you would any other execution, in the console or with [`diagrid workflow`](https://docs.diagrid.io/references/diagrid/cli-reference/workflow).
- **Runs are not child workflows.** The schedule's own workflow continues as new after every run, so it could not receive a child's result, and terminating it would reach only the runs of its latest generation. Instead, the schedule's status carries the last run's status, output and failure, and the `<schedule name>_` prefix of the instance IDs ties every run to its schedule.
- **The schedule needs a connected worker.** As when starting any workflow, creating a schedule needs your app's workflow worker to be connected. While no worker is connected, the schedule waits.
- **A schedule never misses a time.** After downtime, every time the schedule missed starts its own run, unless you set the skip missed option. See [When the app is down](https://docs.diagrid.io/operate/project-operations/workflow-schedules#when-the-app-is-down).
- **The schedule lives with your App ID.** Its runs start on the same App ID unless you set a target App ID. A target app that has a [workflow access policy](https://docs.diagrid.io/operate/project-operations/policies/workflows) must grant the owning app `schedule` on the workflow, and `get` for the schedule to read the last run's status. A run the policy refuses never starts, but still counts as a run, and the schedule carries on.

## Create a schedule

The following examples create a schedule named `nightly-report` that starts the `GenerateReport` workflow at 02:00 UTC every day, then read back when it runs next and how its last run went.

**Python**

```python
from dapr.ext.workflow import DaprWorkflowClient

client = DaprWorkflowClient()

client.create_workflow_schedule(
    "nightly-report",
    generate_report,
    "0 0 2 * * *",
    input={"region": "eu"},
)

schedule = client.get_workflow_schedule("nightly-report")
print("next run:", schedule.status.next_run_time)
if schedule.status.last_run:
    print("last run:", schedule.status.last_run.instance_id, schedule.status.last_run.runtime_status)
```

**.NET**

```csharp
using Dapr.Workflow;
using Dapr.Workflow.Client;

await daprWorkflowClient.CreateWorkflowScheduleAsync(
    "nightly-report",
    nameof(GenerateReportWorkflow),
    "0 0 2 * * *",
    new WorkflowScheduleOptions { Input = new ReportRequest("eu") });

var schedule = await daprWorkflowClient.GetWorkflowScheduleAsync("nightly-report");
Console.WriteLine($"next run: {schedule?.Status?.NextRunTime}");
if (schedule?.Status?.LastRun is { } lastRun)
{
    Console.WriteLine($"last run: {lastRun.InstanceId} {lastRun.RuntimeStatus}");
}
```

**Java**

```java
import io.dapr.workflows.client.DaprWorkflowClient;
import io.dapr.workflows.client.WorkflowSchedule;
import io.dapr.workflows.client.WorkflowScheduleOptions;
import io.dapr.workflows.client.WorkflowScheduleRun;

DaprWorkflowClient client = new DaprWorkflowClient();

client.createWorkflowSchedule("nightly-report", GenerateReportWorkflow.class, "0 0 2 * * *",
    new WorkflowScheduleOptions().setInput(new ReportRequest("eu")));

WorkflowSchedule schedule = client.getWorkflowSchedule("nightly-report");
System.out.println("next run: " + schedule.getStatus().getNextRunTime());
WorkflowScheduleRun lastRun = schedule.getStatus().getLastRun();
if (lastRun != null) {
  System.out.println("last run: " + lastRun.getInstanceId() + " " + lastRun.getRuntimeStatus());
}
```

**JavaScript**

```javascript
import { DaprWorkflowClient } from "@dapr/dapr";

const client = new DaprWorkflowClient();

await client.createWorkflowSchedule("nightly-report", generateReport, "0 0 2 * * *", {
  input: { region: "eu" },
});

const schedule = await client.getWorkflowSchedule("nightly-report");
console.log("next run:", schedule.status?.nextRunTime);
const lastRun = schedule.status?.lastRun;
if (lastRun) {
  console.log("last run:", lastRun.instanceId, lastRun.runtimeStatus);
}
```

**Go**

```go
wfClient, err := client.NewWorkflowClient()
if err != nil {
	log.Fatal(err)
}

_, err = wfClient.CreateWorkflowSchedule(ctx, "nightly-report", "GenerateReport", "0 0 2 * * *",
	workflow.WithScheduleInput(ReportRequest{Region: "eu"}),
)
if err != nil {
	log.Fatal(err)
}

resp, err := wfClient.GetWorkflowSchedule(ctx, "nightly-report")
if err != nil {
	log.Fatal(err)
}
status := resp.GetSchedule().GetStatus()
fmt.Println("next run:", status.GetNextRunTime().AsTime())
if run := status.GetLastRun(); run != nil {
	fmt.Println("last run:", run.GetInstanceId(), run.GetRuntimeStatus())
}
```

The same schedule from the Diagrid CLI, on the `reports` App ID:

```bash
diagrid workflow schedule create nightly-report --id reports \
  --workflow GenerateReport --schedule "0 0 2 * * *" --data '{"region":"eu"}'

diagrid workflow schedule get nightly-report --id reports
```

## Schedule format

The schedule uses the same format as Dapr jobs:

| Format | Example | Meaning |
| --- | --- | --- |
| Cron expression with seconds | `0 30 9 * * MON-FRI` | 09:30:00 on weekdays |
| `@every <duration>` | `@every 15m` | Every 15 minutes. The minimum is 1 second. |
| `@yearly`, `@monthly`, `@weekly`, `@daily`, `@hourly` | `@daily` | Once a year, month, week, day or hour |

The six fields of a cron expression are seconds, minutes, hours, day of month, month and day of week. Cron expressions use UTC unless they start with a time zone, for example `CRON_TZ=Europe/London 0 0 9 * * *`.

## Options

| Option | CLI flag | Description |
| --- | --- | --- |
| Name | argument | Identifies the schedule within the App ID. 1 to 30 letters, digits or `-`, not starting with `dapr-internal-schedule-`. |
| Workflow | `--workflow` | The name of the workflow each run starts. |
| Schedule | `--schedule` | When runs start. See [Schedule format](#schedule-format). |
| Input | `--data` | The input every run is given, as JSON. Text that is not JSON is passed as a JSON string. |
| Due time | `--due-time` | The time of the first run, in RFC 3339 format. Without it, the first run is at the first time the schedule matches. |
| Expiration time | `--expiration-time` | No run starts after this time. The schedule then completes. |
| Repeats | `--repeats` | The number of runs, scheduled or triggered, after which the schedule completes. |
| Target App ID and namespace | `--target-id`, `--target-namespace` | The App ID that hosts the workflow each run starts, when it is not the App ID that owns the schedule. SDK and CLI only; the console creates schedules on the owning App ID. |
| Overwrite | `--overwrite` | Replace an existing schedule of the same name. Without it, creating a schedule whose name is taken fails. |
| Skip missed | `--skip-missed` | Start one run for the times the schedule missed while the app was down, rather than one run for each, and carry on from the next time after now. Off by default. |

## Status

Getting or listing schedules returns each schedule with its status:

| Field | Description |
| --- | --- |
| State | `active` while runs are left, `completed` once repeats or the expiration time are reached, and `failed` if the schedule itself failed, with a failure message. |
| Next run time | When the next run starts, unless the schedule is triggered sooner. Absent once the schedule is no longer active. |
| Last run time | The time the last run was started for, scheduled or triggered. |
| Run count | How many runs the schedule has started. |
| Created at | When the schedule was created. |
| Last run | The last run's instance ID, runtime status, created and last updated times, and its output or failure message. Only the instance ID is set when the run's execution can no longer be read, for example because it was purged. |

## List, trigger and delete

Listing returns the App ID's schedules with their status. Triggering a schedule starts a run at once, without changing when the next scheduled run starts, and returns the run's instance ID. A triggered run counts towards the schedule's repeats, and a schedule that has completed or failed cannot be triggered. Deleting a schedule stops it; runs it already started carry on, and keep their instance IDs and history.

```bash
diagrid workflow schedule list --id reports
diagrid workflow schedule trigger nightly-report --id reports
diagrid workflow schedule delete nightly-report --id reports
```

`list` shows every schedule in the project unless you pass `--id`, with when each runs next, when it last ran, how that run went and the start of its output or failure. Pass `-o json` or `-o yaml` for the full status.

In code, the workflow client offers the same operations:

| Operation | Python | .NET | Java and JavaScript | Go |
| --- | --- | --- | --- | --- |
| List | `list_workflow_schedules` | `ListWorkflowSchedulesAsync` | `listWorkflowSchedules` | `ListWorkflowSchedules` |
| Trigger | `trigger_workflow_schedule` | `TriggerWorkflowScheduleAsync` | `triggerWorkflowSchedule` | `TriggerWorkflowSchedule` |
| Delete | `delete_workflow_schedule` | `DeleteWorkflowScheduleAsync` | `deleteWorkflowSchedule` | `DeleteWorkflowSchedule` |

Listing from an SDK returns a page at a time. A page can hold fewer schedules than the page size while more remain, so keep listing while a continuation token is returned.

To change a schedule, create it again with the overwrite option. That replaces the schedule and resets its run count; runs it already started are not affected.

## Find a schedule's runs

Every run's instance ID starts with the schedule name and `_`, so list the workflow executions with that prefix:

```python
for instance_id in client.iter_workflow_instance_ids(instance_id_prefix="nightly-report_"):
    print(instance_id)
```

The other SDKs offer the same prefix filter on their instance ID listing. In the Diagrid Console, **View runs** on a schedule opens the executions list filtered to its runs. From the CLI, [`diagrid workflow list`](https://docs.diagrid.io/references/diagrid/cli-reference/workflow/list) has no prefix filter. `diagrid workflow list --id reports --name GenerateReport -o json` returns the App ID's executions of that workflow, with the instance ID in each entry. It stops at 250 executions unless you pass a higher `--limit`, so raise it on a busy App ID before concluding that a run never started.

A schedule with a target App ID starts its runs on the target, so look for them there. Other apps can own a schedule of the same name that targets the same app, so add the owning app's tag to the prefix. For `nightly-report`, owned by `reports` in the `default` namespace:

```bash
printf 'default/reports' | sha256sum | cut -c1-6
# 8bfcbd
```

The prefix is then `nightly-report_8bfcbd_`.

## Errors

| Problem | SDK status code | CLI and console |
| --- | --- | --- |
| The name, workflow name, schedule, repeats, expiration time or target namespace is not valid. | `INVALID_ARGUMENT` | `400 Bad Request` |
| Creating a schedule whose name is taken, without overwrite. | `ALREADY_EXISTS` | `409 Conflict` |
| Getting, triggering or deleting a schedule that does not exist. In .NET, `GetWorkflowScheduleAsync` returns `null` instead. | `NOT_FOUND` | `404 Not Found` |
| Triggering a completed or failed schedule, or no workflow worker is connected for the App ID. | `FAILED_PRECONDITION` | `409 Conflict`, with the message `App ID <app-id> has no connected workflow worker. Start the app and retry.` when the worker is missing. |
| The App ID's runtime does not support workflow schedules yet. | `UNIMPLEMENTED` | `501 Not Implemented`. The CLI reports that the selected region is running an older version. |

## Next steps

- [Operate workflow schedules](https://docs.diagrid.io/operate/project-operations/workflow-schedules) — Create, trigger and delete schedules in the Diagrid Console, and see what happens to a schedule while its app is down.
- [Workflow access policies](https://docs.diagrid.io/operate/project-operations/policies/workflows) — Grant the owning app the schedule and get operations when a schedule targets another app.
- [Workflow patterns](https://docs.diagrid.io/develop/workflows/patterns) — Task chaining, fan-out/fan-in and the other patterns your scheduled workflow can use.
