<@ULVA73B9P> I would like to add a trigger in my p...
# ask-marvin
p
@Marvin I would like to add a trigger in my prefect flow to run everyday at 20:00, how could this be possible to inlcude in my prefect deployment?
m
thought for 228.5 seconds
Great question! In Prefect, what you’re describing is a schedule on a deployment (not a “trigger” in Prefect terminology). Here are a few easy ways to run your flow every day at 2000 - Important: by default, cron times are interpreted in UTC. If you want 20:00 in a specific timezone, set
timezone
. Option 1 — Add the schedule in code when creating the deployment
Copy code
from prefect import flow
from prefect.schedules import Cron

@flow
def my_flow():
    ...

if __name__ == "__main__":
    my_flow.deploy(
        name="daily-20h",
        work_pool_name="my-work-pool",
        schedule=Cron("0 20 * * *", timezone="UTC")  # change to your TZ, e.g. "America/New_York"
    )
Option 2 — Add a schedule via CLI to an existing deployment
Copy code
prefect deployment schedule create my-flow/daily-20h --cron "0 20 * * *" --timezone "UTC"
Option 3 — Configuration-as-code in prefect.yaml
Copy code
deployments:
  - name: daily-20h
    entrypoint: flows.py:my_flow
    work_pool:
      name: my-work-pool
    schedules:
      - cron: "0 20 * * *"
        timezone: "UTC"   # or your local timezone
        active: true
Helpful docs: - Create deployment schedules - Schedule concepts Quick check: should that 20:00 be in UTC or a specific timezone (e.g., America/New_York)? If you share your timezone, I can tailor the exact snippet.
p
@Marvin i live in Madrid, waht should be the UTC?
m
thought for 12.4 seconds
Madrid uses the Europe/Madrid timezone, which switches between CET (UTC+1) and CEST (UTC+2). So there isn’t a single fixed UTC time that is always 20:00 Madrid time. - If you want the flow to run at 20:00 local Madrid time year‑round, set the schedule timezone:
Copy code
from prefect.schedules import Cron

schedule = Cron("0 20 * * *", timezone="Europe/Madrid")
Or via CLI:
Copy code
prefect deployment schedule create my-flow/my-deployment --cron "0 20 * * *" --timezone "Europe/Madrid"
- If you must use UTC only, note: - Winter (CET): 20:00 Madrid = 19:00 UTC - Summer (CEST): 20:00 Madrid = 18:00 UTC A fixed UTC cron won’t match 20:00 Madrid across DST changes. Docs: Create deployment schedules
p
@Marvin could it be possible to use the cron paraemter instead of schedule and have the same response
m
thought for 27.7 seconds
Short answer: you can use the
cron
parameter on
deploy()
, but it will schedule in UTC. If you want 20:00 local Madrid time year‑round, use a schedule with a timezone (or the CLI with
--timezone
). - Using
cron
(UTC) — NOT 20:00 Madrid:
Copy code
my_flow.deploy(
    name="daily-20h",
    work_pool_name="my-work-pool",
    cron="0 20 * * *"  # runs at 20:00 UTC (21:00/22:00 in Madrid depending on DST)
)
- Correct (20:00 Europe/Madrid):
Copy code
from prefect.schedules import Cron

my_flow.deploy(
    name="daily-20h-madrid",
    work_pool_name="my-work-pool",
    schedule=Cron("0 20 * * *", timezone="Europe/Madrid"),
)
- Or via CLI:
Copy code
prefect deployment schedule create my-flow/daily-20h-madrid --cron "0 20 * * *" --timezone "Europe/Madrid"
Docs: Create deployment schedules | Schedule concepts If you share your deployment name, I can give you a ready-to-run command.