mirror of
https://github.com/hatchet-dev/hatchet.git
synced 2026-03-18 02:33:00 -05:00
all python async
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
from datetime import datetime, timedelta, timezone
|
||||
|
||||
from hatchet_sdk import Hatchet
|
||||
from hatchet_sdk.clients.rest.models.scheduled_run_status import ScheduledRunStatus
|
||||
|
||||
hatchet = Hatchet()
|
||||
|
||||
@@ -20,6 +21,12 @@ async def create_scheduled() -> None:
|
||||
|
||||
scheduled_run.metadata.id # the id of the scheduled run trigger
|
||||
|
||||
# > Reschedule
|
||||
await hatchet.scheduled.aio_update(
|
||||
scheduled_id=scheduled_run.metadata.id,
|
||||
trigger_at=datetime.now(tz=timezone.utc) + timedelta(hours=1),
|
||||
)
|
||||
|
||||
# > Delete
|
||||
await hatchet.scheduled.aio_delete(scheduled_id=scheduled_run.metadata.id)
|
||||
|
||||
@@ -30,3 +37,21 @@ async def create_scheduled() -> None:
|
||||
scheduled_run = await hatchet.scheduled.aio_get(
|
||||
scheduled_id=scheduled_run.metadata.id
|
||||
)
|
||||
|
||||
id = scheduled_run.metadata.id
|
||||
|
||||
# > Bulk Delete
|
||||
await hatchet.scheduled.aio_bulk_delete(scheduled_ids=[id])
|
||||
|
||||
await hatchet.scheduled.aio_bulk_delete(
|
||||
workflow_id="workflow_id",
|
||||
statuses=[ScheduledRunStatus.SCHEDULED],
|
||||
additional_metadata={"customer_id": "customer-a"},
|
||||
)
|
||||
|
||||
# > Bulk Reschedule
|
||||
await hatchet.scheduled.aio_bulk_update(
|
||||
[
|
||||
(id, datetime.now(tz=timezone.utc) + timedelta(hours=2)),
|
||||
]
|
||||
)
|
||||
|
||||
@@ -84,7 +84,7 @@ Cron triggers can be created via the API at runtime, useful when the schedule is
|
||||
|
||||
<UniversalTabs items={["Python", "Typescript", "Go", "Ruby"]} variant="hidden">
|
||||
<Tabs.Tab title="Python">
|
||||
<Snippet src={snippets.python.cron.programatic_sync.create} />
|
||||
<Snippet src={snippets.python.cron.programatic_async.create} />
|
||||
</Tabs.Tab>
|
||||
<Tabs.Tab title="Typescript">
|
||||
<Snippet src={snippets.typescript.simple.cron.create} />
|
||||
@@ -109,7 +109,7 @@ A cron trigger is deleted by passing its ID to the delete method.
|
||||
|
||||
<UniversalTabs items={["Python", "Typescript", "Go", "Ruby"]} variant="hidden">
|
||||
<Tabs.Tab title="Python">
|
||||
<Snippet src={snippets.python.cron.programatic_sync.delete} />
|
||||
<Snippet src={snippets.python.cron.programatic_async.delete} />
|
||||
</Tabs.Tab>
|
||||
<Tabs.Tab title="Typescript">
|
||||
<Snippet src={snippets.typescript.simple.cron.delete} />
|
||||
@@ -133,7 +133,7 @@ Returns all cron triggers matching the provided criteria.
|
||||
|
||||
<UniversalTabs items={["Python", "Typescript", "Go", "Ruby"]} variant="hidden">
|
||||
<Tabs.Tab title="Python">
|
||||
<Snippet src={snippets.python.cron.programatic_sync.list} />
|
||||
<Snippet src={snippets.python.cron.programatic_async.list} />
|
||||
</Tabs.Tab>
|
||||
<Tabs.Tab title="Typescript">
|
||||
<Snippet src={snippets.typescript.simple.cron.list} />
|
||||
|
||||
@@ -24,7 +24,7 @@ Scheduled runs can be created programmatically. This gives an option for the tri
|
||||
<UniversalTabs items={["Python", "Typescript", "Go", "Ruby"]}>
|
||||
<Tabs.Tab title="Python">
|
||||
|
||||
<Snippet src={snippets.python.simple.schedule.schedule_a_task} />
|
||||
<Snippet src={snippets.python.scheduled.programatic_async.create} />
|
||||
|
||||
</Tabs.Tab>
|
||||
<Tabs.Tab title="Typescript">
|
||||
@@ -48,7 +48,7 @@ The API returns a scheduled run object whose ID should be persisted. It is requi
|
||||
|
||||
<UniversalTabs items={["Python", "Typescript", "Go", "Ruby"]} variant="hidden">
|
||||
<Tabs.Tab title="Python">
|
||||
<Snippet src={snippets.python.scheduled.programatic_sync.delete} />
|
||||
<Snippet src={snippets.python.scheduled.programatic_async.delete} />
|
||||
</Tabs.Tab>
|
||||
<Tabs.Tab title="Typescript">
|
||||
<Snippet src={snippets.typescript.simple.schedule.delete_a_scheduled_run} />
|
||||
@@ -65,7 +65,7 @@ The API returns a scheduled run object whose ID should be persisted. It is requi
|
||||
|
||||
<UniversalTabs items={["Python", "Typescript", "Go", "Ruby"]} variant="hidden">
|
||||
<Tabs.Tab title="Python">
|
||||
<Snippet src={snippets.python.scheduled.programatic_sync.list} />
|
||||
<Snippet src={snippets.python.scheduled.programatic_async.list} />
|
||||
</Tabs.Tab>
|
||||
<Tabs.Tab title="Typescript">
|
||||
<Snippet src={snippets.typescript.simple.schedule.list_scheduled_runs} />
|
||||
@@ -82,7 +82,7 @@ The API returns a scheduled run object whose ID should be persisted. It is requi
|
||||
|
||||
<UniversalTabs items={["Python", "Typescript", "Go", "Ruby"]} variant="hidden">
|
||||
<Tabs.Tab title="Python">
|
||||
<Snippet src={snippets.python.scheduled.programatic_sync.reschedule} />
|
||||
<Snippet src={snippets.python.scheduled.programatic_async.reschedule} />
|
||||
|
||||
</Tabs.Tab>
|
||||
<Tabs.Tab title="Typescript">
|
||||
@@ -111,8 +111,10 @@ Hatchet supports bulk delete and bulk reschedule operations for scheduled runs.
|
||||
|
||||
<UniversalTabs items={["Python", "Typescript", "Go", "Ruby"]} variant="hidden">
|
||||
<Tabs.Tab title="Python">
|
||||
<Snippet src={snippets.python.scheduled.programatic_sync.bulk_delete} />
|
||||
<Snippet src={snippets.python.scheduled.programatic_sync.bulk_reschedule} />
|
||||
<Snippet src={snippets.python.scheduled.programatic_async.bulk_delete} />
|
||||
<Snippet
|
||||
src={snippets.python.scheduled.programatic_async.bulk_reschedule}
|
||||
/>
|
||||
</Tabs.Tab>
|
||||
<Tabs.Tab title="Typescript">
|
||||
<Snippet
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
from datetime import datetime, timedelta, timezone
|
||||
|
||||
from hatchet_sdk import Hatchet
|
||||
from hatchet_sdk.clients.rest.models.scheduled_run_status import ScheduledRunStatus
|
||||
|
||||
hatchet = Hatchet()
|
||||
|
||||
@@ -21,6 +22,13 @@ async def create_scheduled() -> None:
|
||||
scheduled_run.metadata.id # the id of the scheduled run trigger
|
||||
# !!
|
||||
|
||||
# > Reschedule
|
||||
await hatchet.scheduled.aio_update(
|
||||
scheduled_id=scheduled_run.metadata.id,
|
||||
trigger_at=datetime.now(tz=timezone.utc) + timedelta(hours=1),
|
||||
)
|
||||
# !!
|
||||
|
||||
# > Delete
|
||||
await hatchet.scheduled.aio_delete(scheduled_id=scheduled_run.metadata.id)
|
||||
# !!
|
||||
@@ -34,3 +42,23 @@ async def create_scheduled() -> None:
|
||||
scheduled_id=scheduled_run.metadata.id
|
||||
)
|
||||
# !!
|
||||
|
||||
id = scheduled_run.metadata.id
|
||||
|
||||
# > Bulk Delete
|
||||
await hatchet.scheduled.aio_bulk_delete(scheduled_ids=[id])
|
||||
|
||||
await hatchet.scheduled.aio_bulk_delete(
|
||||
workflow_id="workflow_id",
|
||||
statuses=[ScheduledRunStatus.SCHEDULED],
|
||||
additional_metadata={"customer_id": "customer-a"},
|
||||
)
|
||||
# !!
|
||||
|
||||
# > Bulk Reschedule
|
||||
await hatchet.scheduled.aio_bulk_update(
|
||||
[
|
||||
(id, datetime.now(tz=timezone.utc) + timedelta(hours=2)),
|
||||
]
|
||||
)
|
||||
# !!
|
||||
|
||||
Reference in New Issue
Block a user