Files
hatchet/examples/python/scheduled/programatic-sync.py
Gabe Ruttner 51464917f7 Feat: bulk management schedules (#2687)
* fix: filter + pagination state handling hack

* fix: use location.pathname

* update to go 1.25

* fix: add version to sdk-go.yml

* schedule run bulk actions

* lint

* typescript

* python

* lint

* docs

* lint docs

* lint

* feedback

* fix lint

* rm unused chunk

* rm statues

* i dont understand python linting sometimes

---------

Co-authored-by: mrkaye97 <mrkaye97@gmail.com>
Co-authored-by: Alexander Belanger <alexander@hatchet.run>
2025-12-23 07:44:12 -08:00

52 lines
1.3 KiB
Python

from datetime import datetime, timedelta, timezone
from hatchet_sdk import Hatchet
from hatchet_sdk.clients.rest.models.scheduled_run_status import ScheduledRunStatus
hatchet = Hatchet()
# > Create
scheduled_run = hatchet.scheduled.create(
workflow_name="simple-workflow",
trigger_at=datetime.now(tz=timezone.utc) + timedelta(seconds=10),
input={
"data": "simple-workflow-data",
},
additional_metadata={
"customer_id": "customer-a",
},
)
id = scheduled_run.metadata.id # the id of the scheduled run trigger
# > Reschedule
hatchet.scheduled.update(
scheduled_id=scheduled_run.metadata.id,
trigger_at=datetime.now(tz=timezone.utc) + timedelta(hours=1),
)
# > Delete
hatchet.scheduled.delete(scheduled_id=scheduled_run.metadata.id)
# > List
scheduled_runs = hatchet.scheduled.list()
# > Get
scheduled_run = hatchet.scheduled.get(scheduled_id=scheduled_run.metadata.id)
# > Bulk Delete
hatchet.scheduled.bulk_delete(scheduled_ids=[id])
hatchet.scheduled.bulk_delete(
workflow_id="workflow_id",
statuses=[ScheduledRunStatus.SCHEDULED],
additional_metadata={"customer_id": "customer-a"},
)
# > Bulk Reschedule
hatchet.scheduled.bulk_update(
[
(id, datetime.now(tz=timezone.utc) + timedelta(hours=2)),
]
)