Skip to content

Commit

Permalink
Feat dynamic crons (#265)
Browse files Browse the repository at this point in the history
* docs

* drop the sub mod

* chore: gen

* feat: scheduled and cron

* chore: generate

* release
  • Loading branch information
grutt authored Dec 3, 2024
1 parent 0887ce7 commit bc5cacb
Show file tree
Hide file tree
Showing 33 changed files with 5,776 additions and 992 deletions.
4 changes: 0 additions & 4 deletions .gitmodules

This file was deleted.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Hatchet Python SDK

This is the [Hatchet](https://hatchet.run) Python SDK. For usage, see the [docs](https://docs.hatchet.run/sdks/python-sdk/).
This is the [Hatchet](https://hatchet.run) Python SDK. For usage, see the [docs](https://docs.hatchet.run).
28 changes: 0 additions & 28 deletions branch-sync.sh

This file was deleted.

37 changes: 37 additions & 0 deletions examples/cron/programatic-async.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
from dotenv import load_dotenv

from hatchet_sdk import Hatchet

load_dotenv()

hatchet = Hatchet()


async def create_cron():
# ❓ Create
cron_trigger = await hatchet.cron.aio.create(
workflow_name="simple-cron-workflow",
cron_name="customer-a-daily-report",
expression="0 12 * * *",
input={
"name": "John Doe",
},
additional_metadata={
"customer_id": "customer-a",
},
)

id = cron_trigger.metadata.id # the id of the cron trigger
# !!

# ❓ Delete
await hatchet.cron.aio.delete(cron_trigger=cron_trigger.metadata.id)
# !!

# ❓ List
cron_triggers = await hatchet.cron.aio.list()
# !!

# ❓ Get
cron_trigger = await hatchet.cron.aio.get(cron_trigger=cron_trigger.metadata.id)
# !!
35 changes: 35 additions & 0 deletions examples/cron/programatic-sync.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
from dotenv import load_dotenv

from hatchet_sdk import Hatchet

load_dotenv()

hatchet = Hatchet()

# ❓ Create
cron_trigger = hatchet.cron.create(
workflow_name="simple-cron-workflow",
cron_name="customer-a-daily-report",
expression="0 12 * * *",
input={
"name": "John Doe",
},
additional_metadata={
"customer_id": "customer-a",
},
)

id = cron_trigger.metadata.id # the id of the cron trigger
# !!

# ❓ Delete
hatchet.cron.delete(cron_trigger=cron_trigger.metadata.id)
# !!

# ❓ List
cron_triggers = hatchet.cron.list()
# !!

# ❓ Get
cron_trigger = hatchet.cron.get(cron_trigger=cron_trigger.metadata.id)
# !!
37 changes: 37 additions & 0 deletions examples/cron/workflow-definition.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import time

from dotenv import load_dotenv

from hatchet_sdk import Context, Hatchet

load_dotenv()

hatchet = Hatchet(debug=True)


# ❓ Workflow Definition Cron Trigger
# Adding a cron trigger to a workflow is as simple
# as adding a `cron expression` to the `on_cron`
# prop of the workflow definition
@hatchet.workflow(on_cron="* * * * *")
class CronWorkflow:
@hatchet.step()
def step1(self, context: Context):

return {
"time": "step1",
}


# !!


def main():
workflow = CronWorkflow()
worker = hatchet.worker("test-worker", max_runs=1)
worker.register_workflow(workflow)
worker.start()


if __name__ == "__main__":
main()
39 changes: 39 additions & 0 deletions examples/scheduled/programatic-async.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
from datetime import datetime, timedelta

from dotenv import load_dotenv

from hatchet_sdk import Hatchet
from hatchet_sdk.clients.rest.models.scheduled_workflows import ScheduledWorkflows

load_dotenv()

hatchet = Hatchet()


async def create_scheduled():
# ❓ Create
scheduled_run = await hatchet.scheduled.aio.create(
workflow_name="simple-workflow",
trigger_at=datetime.now() + 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
# !!

# ❓ Delete
await hatchet.scheduled.aio.delete(scheduled=scheduled_run.metadata.id)
# !!

# ❓ List
scheduled_runs = await hatchet.scheduled.aio.list()
# !!

# ❓ Get
scheduled_run = await hatchet.scheduled.aio.get(scheduled=scheduled_run.metadata.id)
# !!
36 changes: 36 additions & 0 deletions examples/scheduled/programatic-sync.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
from datetime import datetime, timedelta

from dotenv import load_dotenv

from hatchet_sdk import Hatchet

load_dotenv()

hatchet = Hatchet()

# ❓ Create
scheduled_run = hatchet.scheduled.create(
workflow_name="simple-workflow",
trigger_at=datetime.now() + 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
# !!

# ❓ Delete
hatchet.scheduled.delete(scheduled=scheduled_run.metadata.id)
# !!

# ❓ List
scheduled_runs = hatchet.scheduled.list()
# !!

# ❓ Get
scheduled_run = hatchet.scheduled.get(scheduled=scheduled_run.metadata.id)
# !!
6 changes: 3 additions & 3 deletions generate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ openapi-generator-cli version || npm install @openapitools/openapi-generator-cli
# fi

# generate deps from hatchet repo
cd hatchet/ && sh ./hack/oas/generate-server.sh && cd $ROOT_DIR
cd ../oss/ && sh ./hack/oas/generate-server.sh && cd $ROOT_DIR

# generate python rest client

Expand All @@ -27,7 +27,7 @@ mkdir -p $dst_dir
tmp_dir=./tmp

# generate into tmp folder
openapi-generator-cli generate -i ./hatchet/bin/oas/openapi.yaml -g python -o ./tmp --skip-validate-spec \
openapi-generator-cli generate -i ../oss/bin/oas/openapi.yaml -g python -o ./tmp --skip-validate-spec \
--library asyncio \
--global-property=apiTests=false \
--global-property=apiDocs=true \
Expand All @@ -42,7 +42,7 @@ mv $tmp_dir/hatchet_sdk/clients/rest/exceptions.py $dst_dir/exceptions.py
mv $tmp_dir/hatchet_sdk/clients/rest/__init__.py $dst_dir/__init__.py
mv $tmp_dir/hatchet_sdk/clients/rest/rest.py $dst_dir/rest.py

openapi-generator-cli generate -i ./hatchet/bin/oas/openapi.yaml -g python -o . --skip-validate-spec \
openapi-generator-cli generate -i ../oss/bin/oas/openapi.yaml -g python -o . --skip-validate-spec \
--library asyncio \
--global-property=apis,models \
--global-property=apiTests=false \
Expand Down
1 change: 0 additions & 1 deletion hatchet
Submodule hatchet deleted from f82137
21 changes: 21 additions & 0 deletions hatchet_sdk/clients/rest/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@
from hatchet_sdk.clients.rest.models.create_api_token_response import (
CreateAPITokenResponse,
)
from hatchet_sdk.clients.rest.models.create_cron_workflow_trigger_request import (
CreateCronWorkflowTriggerRequest,
)
from hatchet_sdk.clients.rest.models.create_event_request import CreateEventRequest
from hatchet_sdk.clients.rest.models.create_pull_request_from_step_run import (
CreatePullRequestFromStepRun,
Expand All @@ -84,6 +87,11 @@
CreateTenantInviteRequest,
)
from hatchet_sdk.clients.rest.models.create_tenant_request import CreateTenantRequest
from hatchet_sdk.clients.rest.models.cron_workflows import CronWorkflows
from hatchet_sdk.clients.rest.models.cron_workflows_list import CronWorkflowsList
from hatchet_sdk.clients.rest.models.cron_workflows_order_by_field import (
CronWorkflowsOrderByField,
)
from hatchet_sdk.clients.rest.models.event import Event
from hatchet_sdk.clients.rest.models.event_data import EventData
from hatchet_sdk.clients.rest.models.event_key_list import EventKeyList
Expand Down Expand Up @@ -141,6 +149,17 @@
ReplayWorkflowRunsResponse,
)
from hatchet_sdk.clients.rest.models.rerun_step_run_request import RerunStepRunRequest
from hatchet_sdk.clients.rest.models.schedule_workflow_run_request import (
ScheduleWorkflowRunRequest,
)
from hatchet_sdk.clients.rest.models.scheduled_run_status import ScheduledRunStatus
from hatchet_sdk.clients.rest.models.scheduled_workflows import ScheduledWorkflows
from hatchet_sdk.clients.rest.models.scheduled_workflows_list import (
ScheduledWorkflowsList,
)
from hatchet_sdk.clients.rest.models.scheduled_workflows_order_by_field import (
ScheduledWorkflowsOrderByField,
)
from hatchet_sdk.clients.rest.models.semaphore_slots import SemaphoreSlots
from hatchet_sdk.clients.rest.models.slack_webhook import SlackWebhook
from hatchet_sdk.clients.rest.models.sns_integration import SNSIntegration
Expand Down Expand Up @@ -219,6 +238,8 @@
from hatchet_sdk.clients.rest.models.worker import Worker
from hatchet_sdk.clients.rest.models.worker_label import WorkerLabel
from hatchet_sdk.clients.rest.models.worker_list import WorkerList
from hatchet_sdk.clients.rest.models.worker_runtime_info import WorkerRuntimeInfo
from hatchet_sdk.clients.rest.models.worker_runtime_sdks import WorkerRuntimeSDKs
from hatchet_sdk.clients.rest.models.workflow import Workflow
from hatchet_sdk.clients.rest.models.workflow_concurrency import WorkflowConcurrency
from hatchet_sdk.clients.rest.models.workflow_kind import WorkflowKind
Expand Down
Loading

0 comments on commit bc5cacb

Please sign in to comment.