Skip to content

Commit

Permalink
Workflow example review
Browse files Browse the repository at this point in the history
  • Loading branch information
ToriLindsay committed Jan 3, 2025
1 parent 30e3718 commit 478f9e0
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/content/docs/workflows/examples/backup-d1.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ description: Send invoice when shopping cart is checked out and paid for

import { TabItem, Tabs } from "~/components"

In this example, we implement a Workflow periodically triggered by a [Cron Trigger](/workers/configuration/cron-triggers) to start a backup for a D1 database using the REST API and finally store the SQL dump in an [R2](/r2) bucket.
In this example, we implement a Workflow periodically triggered by a [Cron Trigger](/workers/configuration/cron-triggers). That Workflow initiates a backup for a D1 database using the REST API, and then stores the SQL dump in an [R2](/r2) bucket.

Once a Workflow instance is triggered, fetches the REST API to start an export job for a specific database. Then, it fetches the same endpoint to check if the backup job is ready and the SQL dump is available to download.
When the Workflow is triggered, it fetches the REST API to initiate an export job for a specific database. Then it fetches the same endpoint to check if the backup job is ready and the SQL dump is available to download.

As you can see, Workflows handles the responses and failures. It will retry the API calls until we get a successful response, retry fetching the backup from the URL provided, and retry saving the file to [R2](/r2). The developer doesn't have to care about any of that logic. The workflow can run until the backup file is ready, handling all the possible conditions until it is completed.
As shown in this example, Workflows handles both the responses and failures, so the developer does not have to. Workflows retries the API calls until it gets a successful response, retries fetching the backup from the URL provided, and then retries saving the file to [R2](/r2). The workflow can run until the backup file is ready, handling all of the possible conditions until it is completed.

This is a simplified example of backing up a [D1](/d1) database. For every step, we use the [default](/workflows/build/sleeping-and-retrying) sleeping and retrying configuration. In a real-life scenario, we would assume more steps and additional logic, but this example gives you a good idea of what you can do with Workflows.
This example provides simplified steps for backing up a [D1](/d1) database to help you understand the possibilities of Workflows. In every step, it uses the [default](/workflows/build/sleeping-and-retrying) sleeping and retrying configuration. In a real-world scenario, more steps and additional logic would likely be needed.

```ts
import {
Expand Down Expand Up @@ -103,7 +103,7 @@ export default {
};
```

Here's a minimal package.json:
Here is a minimal package.json:

```json
{
Expand All @@ -114,7 +114,7 @@ Here's a minimal package.json:
}
```

And finally wrangler.toml:
Here is a wrangler.toml:

import { WranglerConfig } from "~/components";

Expand Down

0 comments on commit 478f9e0

Please sign in to comment.