From 5b7470287f90b8940a34270bcc35a8b9fb710c1e Mon Sep 17 00:00:00 2001 From: zzstoatzz Date: Wed, 5 Feb 2025 16:57:07 -0600 Subject: [PATCH 01/11] init --- docs/v3/automate/add-schedules.mdx | 93 ++++++++++++++++++- .../deploy-via-python.mdx | 6 +- docs/v3/resources/upgrade-to-prefect-3.mdx | 4 +- 3 files changed, 95 insertions(+), 8 deletions(-) diff --git a/docs/v3/automate/add-schedules.mdx b/docs/v3/automate/add-schedules.mdx index 831db0978831..5599fa27e4b9 100644 --- a/docs/v3/automate/add-schedules.mdx +++ b/docs/v3/automate/add-schedules.mdx @@ -14,8 +14,8 @@ There are several ways to create a schedule for a deployment: - Through the Prefect UI - With the `cron`, `interval`, or `rrule` parameters if building your deployment with the -[`serve` method](/v3/develop/write-flows/#serving-a-flow) of the `Flow` object or -[the `serve` utility](/v3/develop/write-flows/#serving-multiple-flows-at-once) for managing multiple flows simultaneously +[`serve` method](/v3/deploy/run-flows-in-local-processes#serve-a-flow) of the `Flow` object or +[the `serve` utility](/v3/deploy/run-flows-in-local-processes#serve-multiple-flows-at-once) for managing multiple flows simultaneously - If using [worker-based deployments](/v3/deploy/infrastructure-concepts/workers/) - When you define a deployment with `flow.serve` or `flow.deploy` - Through the interactive `prefect deploy` command @@ -65,7 +65,26 @@ If using work pool-based deployments, the `deploy` method has the same schedule- When `my_flow` is served with this interval schedule, it will run every 10 minutes beginning at midnight on January, 1, 2026 in the `America/Chicago` timezone: -```python + +```python prefect >= 3.1.16 +from datetime import timedelta, datetime +from prefect.schedules import Interval + +from myproject.flows import my_flow + +my_flow.serve( + name="flowing", + schedules=[ + Interval( + interval=timedelta(minutes=10), + anchor_date=datetime(2026, 1, 1, 0, 0), + timezone="America/Chicago" + ) + ] +) +``` + +```python prefect < 3.1.16 from datetime import timedelta, datetime from prefect.client.schemas.schedules import IntervalSchedule @@ -83,6 +102,8 @@ my_flow.serve( ) ``` + + ### Create schedules in the terminal You can create a schedule through the interactive `prefect deploy` command. You will be prompted to choose which type of schedule to create. @@ -268,6 +289,72 @@ A 9 AM daily schedule with a DST-aware start date maintains a local 9 AM time th with a UTC start date maintains a 9 AM UTC time. +## Associating parameters with schedules +Using any of the above methods to create a schedule, you can bind parameters to your schedules. + +For example, say you have a flow that sends an email. Every day at 8:00 AM you want to send a message to one recipient, and at 8:05 AM you want to send a different message to another recipient. + +Instead of creating independent deployments with different default parameters and schedules, you can bind parameters to the schedules themselves: + +### Schedule parameters in Python + +Whether using `.serve` or `.deploy`, you can pass `parameters` to your deployment `schedules`: + +```python send_email_flow.py {13,17-20} +from prefect import flow, parameter +from prefect.schedules import Cron + +@flow +def send_email(to: str, message: str = "Stop goofing off!"): + print(f"Sending email to {to} with message: {message}") + +send_email.serve( + name="my-flow", + schedules=[ + Cron( + cron="0 8 * * *", + parameters={"to": "jim.halpert@dundermiflin.com"} + ), + Cron( + cron="5 8 * * *", + parameters={ + "to": "dwight.schrute@dundermiflin.com", + "message": "Stop goofing off! You're assistant _to_ the regional manager!" + } + ) + ] +) +``` +Note our flow has a default `message` parameter, but we've overridden it for the second schedule. + +This deployment will schedule runs that: + +- Send "Stop goofing off!" to Jim at 8:00 AM every day +- Send "Stop goofing off! You're assistant _to_ the regional manager!" to Dwight at 8:05 AM every day + + +Use the same pattern for any schedule type in `prefect.schedules`, e.g. `Interval` and `RRule`. + + +### Schedule parameters in `prefect.yaml` + +You can also provide parameters to schedules in your `prefect.yaml` file. + +```yaml prefect.yaml {4-11} +deployments: + name: send-email + entrypoint: send_email_flow.py:send_email + schedules: + - cron: "0 8 * * *" + parameters: + to: "jim.halpert@dundermiflin.com" + - cron: "5 8 * * *" + parameters: + to: "dwight.schrute@dundermiflin.com" + message: "Stop goofing off! You're assistant _to_ the regional manager!" +``` + + ## How scheduling works Prefect's `Scheduler` service evaluates each deployment's schedules and creates new runs appropriately. It starts diff --git a/docs/v3/deploy/infrastructure-concepts/deploy-via-python.mdx b/docs/v3/deploy/infrastructure-concepts/deploy-via-python.mdx index af1a410bb405..714dccb7bf75 100644 --- a/docs/v3/deploy/infrastructure-concepts/deploy-via-python.mdx +++ b/docs/v3/deploy/infrastructure-concepts/deploy-via-python.mdx @@ -227,7 +227,7 @@ To deploy a flow with a schedule, you can use one of the following options: ```python schedules.py from datetime import datetime, timedelta from prefect import flow - from prefect.client.schemas.schedules import IntervalSchedule + from prefect.schedules import Interval @flow(log_prints=True) @@ -244,8 +244,8 @@ To deploy a flow with a schedule, you can use one of the following options: # Run every 10 minutes starting from January 1, 2023 # at 00:00 Central Time schedules=[ - IntervalSchedule( - interval=timedelta(minutes=10), + Interval( + timedelta(minutes=10), anchor_date=datetime(2023, 1, 1, 0, 0), timezone="America/Chicago" ) diff --git a/docs/v3/resources/upgrade-to-prefect-3.mdx b/docs/v3/resources/upgrade-to-prefect-3.mdx index 6336d995d465..a9d6933cf89a 100644 --- a/docs/v3/resources/upgrade-to-prefect-3.mdx +++ b/docs/v3/resources/upgrade-to-prefect-3.mdx @@ -287,7 +287,7 @@ my_flow.serve( ```python Prefect 3.0 {11} from datetime import timedelta from prefect import flow -from prefect.client.schemas.schedules import IntervalSchedule +from prefect.schedules import Interval @flow def my_flow(): @@ -295,7 +295,7 @@ def my_flow(): my_flow.serve( name="my-flow", - schedules=[IntervalSchedule(interval=timedelta(minutes=1))] + schedules=[Interval(timedelta(minutes=1))] ) ``` From 703436b547815728cb2c4085072c9c6102bb26ec Mon Sep 17 00:00:00 2001 From: zzstoatzz Date: Wed, 5 Feb 2025 16:59:59 -0600 Subject: [PATCH 02/11] rm kwarg --- docs/v3/automate/add-schedules.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/v3/automate/add-schedules.mdx b/docs/v3/automate/add-schedules.mdx index 5599fa27e4b9..a0f32b517f3b 100644 --- a/docs/v3/automate/add-schedules.mdx +++ b/docs/v3/automate/add-schedules.mdx @@ -76,7 +76,7 @@ my_flow.serve( name="flowing", schedules=[ Interval( - interval=timedelta(minutes=10), + timedelta(minutes=10), anchor_date=datetime(2026, 1, 1, 0, 0), timezone="America/Chicago" ) From 7d33f0155701cb3e74a368c73e6fcb8c63cc18c5 Mon Sep 17 00:00:00 2001 From: zzstoatzz Date: Thu, 6 Feb 2025 11:05:32 -0600 Subject: [PATCH 03/11] apply review suggestions --- docs/v3/automate/add-schedules.mdx | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/docs/v3/automate/add-schedules.mdx b/docs/v3/automate/add-schedules.mdx index a0f32b517f3b..194f01706471 100644 --- a/docs/v3/automate/add-schedules.mdx +++ b/docs/v3/automate/add-schedules.mdx @@ -74,13 +74,11 @@ from myproject.flows import my_flow my_flow.serve( name="flowing", - schedules=[ - Interval( - timedelta(minutes=10), - anchor_date=datetime(2026, 1, 1, 0, 0), - timezone="America/Chicago" - ) - ] + schedule=Interval( + timedelta(minutes=10), + anchor_date=datetime(2026, 1, 1, 0, 0), + timezone="America/Chicago" + ) ) ``` @@ -301,7 +299,7 @@ Instead of creating independent deployments with different default parameters an Whether using `.serve` or `.deploy`, you can pass `parameters` to your deployment `schedules`: ```python send_email_flow.py {13,17-20} -from prefect import flow, parameter +from prefect import flow from prefect.schedules import Cron @flow @@ -312,11 +310,11 @@ send_email.serve( name="my-flow", schedules=[ Cron( - cron="0 8 * * *", + "0 8 * * *", parameters={"to": "jim.halpert@dundermiflin.com"} ), Cron( - cron="5 8 * * *", + "5 8 * * *", parameters={ "to": "dwight.schrute@dundermiflin.com", "message": "Stop goofing off! You're assistant _to_ the regional manager!" @@ -333,7 +331,7 @@ This deployment will schedule runs that: - Send "Stop goofing off! You're assistant _to_ the regional manager!" to Dwight at 8:05 AM every day -Use the same pattern for any schedule type in `prefect.schedules`, e.g. `Interval` and `RRule`. +Use the same pattern to bind parameters to schedules for any schedule type in `prefect.schedules`, whether providing one schedule via the `schedule` kwarg or multiple schedules via `schedules`. ### Schedule parameters in `prefect.yaml` From 19dbe0723f44ff0c61939e58eb465a58d2a508aa Mon Sep 17 00:00:00 2001 From: nate nowack Date: Thu, 6 Feb 2025 12:21:33 -0600 Subject: [PATCH 04/11] Update docs/v3/automate/add-schedules.mdx Co-authored-by: daniel-prefect --- docs/v3/automate/add-schedules.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/v3/automate/add-schedules.mdx b/docs/v3/automate/add-schedules.mdx index 194f01706471..2bef41a4960d 100644 --- a/docs/v3/automate/add-schedules.mdx +++ b/docs/v3/automate/add-schedules.mdx @@ -348,7 +348,7 @@ deployments: to: "jim.halpert@dundermiflin.com" - cron: "5 8 * * *" parameters: - to: "dwight.schrute@dundermiflin.com" + to: "dwight.schrute@dundermifflin.com" message: "Stop goofing off! You're assistant _to_ the regional manager!" ``` From 708aed954b27b5aa57de971848abf2f3945f29e4 Mon Sep 17 00:00:00 2001 From: nate nowack Date: Thu, 6 Feb 2025 12:21:38 -0600 Subject: [PATCH 05/11] Update docs/v3/automate/add-schedules.mdx Co-authored-by: daniel-prefect --- docs/v3/automate/add-schedules.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/v3/automate/add-schedules.mdx b/docs/v3/automate/add-schedules.mdx index 2bef41a4960d..9b3e9e9b15e5 100644 --- a/docs/v3/automate/add-schedules.mdx +++ b/docs/v3/automate/add-schedules.mdx @@ -345,7 +345,7 @@ deployments: schedules: - cron: "0 8 * * *" parameters: - to: "jim.halpert@dundermiflin.com" + to: "jim.halpert@dundermifflin.com" - cron: "5 8 * * *" parameters: to: "dwight.schrute@dundermifflin.com" From 68deb582b188d9e63a81f41922134ae0e1679ba6 Mon Sep 17 00:00:00 2001 From: nate nowack Date: Thu, 6 Feb 2025 12:21:49 -0600 Subject: [PATCH 06/11] Update docs/v3/automate/add-schedules.mdx Co-authored-by: daniel-prefect --- docs/v3/automate/add-schedules.mdx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/v3/automate/add-schedules.mdx b/docs/v3/automate/add-schedules.mdx index 9b3e9e9b15e5..55e59c331351 100644 --- a/docs/v3/automate/add-schedules.mdx +++ b/docs/v3/automate/add-schedules.mdx @@ -331,7 +331,8 @@ This deployment will schedule runs that: - Send "Stop goofing off! You're assistant _to_ the regional manager!" to Dwight at 8:05 AM every day -Use the same pattern to bind parameters to schedules for any schedule type in `prefect.schedules`, whether providing one schedule via the `schedule` kwarg or multiple schedules via `schedules`. +Use the same pattern to bind parameters to any schedule type in `prefect.schedules`. +You can provide one schedule via the `schedule` kwarg or multiple schedules via `schedules`. ### Schedule parameters in `prefect.yaml` From 20363a41ce2eacd927794b737c100d7a97bb5c29 Mon Sep 17 00:00:00 2001 From: nate nowack Date: Thu, 6 Feb 2025 12:21:55 -0600 Subject: [PATCH 07/11] Update docs/v3/automate/add-schedules.mdx Co-authored-by: daniel-prefect --- docs/v3/automate/add-schedules.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/v3/automate/add-schedules.mdx b/docs/v3/automate/add-schedules.mdx index 55e59c331351..0d502c1b38c1 100644 --- a/docs/v3/automate/add-schedules.mdx +++ b/docs/v3/automate/add-schedules.mdx @@ -311,7 +311,7 @@ send_email.serve( schedules=[ Cron( "0 8 * * *", - parameters={"to": "jim.halpert@dundermiflin.com"} + parameters={"to": "jim.halpert@dundermifflin.com"} ), Cron( "5 8 * * *", From 5dce7b477dc15804c9633324f742845d13ec4e97 Mon Sep 17 00:00:00 2001 From: nate nowack Date: Thu, 6 Feb 2025 12:22:03 -0600 Subject: [PATCH 08/11] Update docs/v3/automate/add-schedules.mdx Co-authored-by: daniel-prefect --- docs/v3/automate/add-schedules.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/v3/automate/add-schedules.mdx b/docs/v3/automate/add-schedules.mdx index 0d502c1b38c1..e1aa3bd13c84 100644 --- a/docs/v3/automate/add-schedules.mdx +++ b/docs/v3/automate/add-schedules.mdx @@ -323,7 +323,7 @@ send_email.serve( ] ) ``` -Note our flow has a default `message` parameter, but we've overridden it for the second schedule. +Note that our flow has a default `message` parameter, but we've overridden it for the second schedule. This deployment will schedule runs that: From f4aab7d6e5a41cdff8a84f0687b2dfb11d264c28 Mon Sep 17 00:00:00 2001 From: nate nowack Date: Thu, 6 Feb 2025 12:22:10 -0600 Subject: [PATCH 09/11] Update docs/v3/automate/add-schedules.mdx Co-authored-by: daniel-prefect --- docs/v3/automate/add-schedules.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/v3/automate/add-schedules.mdx b/docs/v3/automate/add-schedules.mdx index e1aa3bd13c84..f455a53ed115 100644 --- a/docs/v3/automate/add-schedules.mdx +++ b/docs/v3/automate/add-schedules.mdx @@ -316,7 +316,7 @@ send_email.serve( Cron( "5 8 * * *", parameters={ - "to": "dwight.schrute@dundermiflin.com", + "to": "dwight.schrute@dundermifflin.com", "message": "Stop goofing off! You're assistant _to_ the regional manager!" } ) From 12b83c4821acdec461a433ea580fb2ab2ccf07ca Mon Sep 17 00:00:00 2001 From: nate nowack Date: Thu, 6 Feb 2025 12:22:29 -0600 Subject: [PATCH 10/11] Update docs/v3/automate/add-schedules.mdx Co-authored-by: daniel-prefect --- docs/v3/automate/add-schedules.mdx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/v3/automate/add-schedules.mdx b/docs/v3/automate/add-schedules.mdx index f455a53ed115..40d233e7b8e8 100644 --- a/docs/v3/automate/add-schedules.mdx +++ b/docs/v3/automate/add-schedules.mdx @@ -290,7 +290,8 @@ with a UTC start date maintains a 9 AM UTC time. ## Associating parameters with schedules Using any of the above methods to create a schedule, you can bind parameters to your schedules. -For example, say you have a flow that sends an email. Every day at 8:00 AM you want to send a message to one recipient, and at 8:05 AM you want to send a different message to another recipient. +For example, say you have a flow that sends an email. +Every day at 8:00 AM you want to send a message to one recipient, and at 8:05 AM you want to send a different message to another recipient. Instead of creating independent deployments with different default parameters and schedules, you can bind parameters to the schedules themselves: From 0fecf05c07c78dcdc43272dcc62cd3bdd9ce6b2d Mon Sep 17 00:00:00 2001 From: nate nowack Date: Thu, 6 Feb 2025 12:23:00 -0600 Subject: [PATCH 11/11] Update docs/v3/automate/add-schedules.mdx Co-authored-by: daniel-prefect --- docs/v3/automate/add-schedules.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/v3/automate/add-schedules.mdx b/docs/v3/automate/add-schedules.mdx index 40d233e7b8e8..a8de5a8b3ad3 100644 --- a/docs/v3/automate/add-schedules.mdx +++ b/docs/v3/automate/add-schedules.mdx @@ -287,7 +287,7 @@ A 9 AM daily schedule with a DST-aware start date maintains a local 9 AM time th with a UTC start date maintains a 9 AM UTC time. -## Associating parameters with schedules +## Associate parameters with schedules Using any of the above methods to create a schedule, you can bind parameters to your schedules. For example, say you have a flow that sends an email.