mirror of
https://github.com/hatchet-dev/hatchet.git
synced 2026-01-06 00:40:10 -06:00
feat(py): schedule_workflows (#287)
* feat: schedule workflows * docs: delay events * fix: linting * release: py 0.18.0
This commit is contained in:
13
python-sdk/examples/delayed/event_test.py
Normal file
13
python-sdk/examples/delayed/event_test.py
Normal file
@@ -0,0 +1,13 @@
|
||||
from hatchet_sdk import new_client
|
||||
from dotenv import load_dotenv
|
||||
|
||||
load_dotenv()
|
||||
|
||||
client = new_client()
|
||||
|
||||
client.event.push(
|
||||
"printer:schedule",
|
||||
{
|
||||
"message": "test"
|
||||
}
|
||||
)
|
||||
36
python-sdk/examples/delayed/worker.py
Normal file
36
python-sdk/examples/delayed/worker.py
Normal file
@@ -0,0 +1,36 @@
|
||||
from datetime import datetime, timedelta
|
||||
from hatchet_sdk import Hatchet, Context
|
||||
from dotenv import load_dotenv
|
||||
|
||||
load_dotenv()
|
||||
|
||||
hatchet = Hatchet(debug=True)
|
||||
|
||||
@hatchet.workflow(on_events=["printer:schedule"])
|
||||
class PrintSchedule:
|
||||
@hatchet.step()
|
||||
def schedule(self, context:Context):
|
||||
now = datetime.now()
|
||||
print(f"the time is \t {now.strftime("%H:%M:%S")}")
|
||||
future_time = now + timedelta(seconds=15)
|
||||
print(f"scheduling for \t {future_time.strftime("%H:%M:%S")}")
|
||||
|
||||
hatchet.client.admin.schedule_workflow(
|
||||
'PrintPrinter',
|
||||
[future_time],
|
||||
context.workflow_input()
|
||||
)
|
||||
|
||||
@hatchet.workflow()
|
||||
class PrintPrinter:
|
||||
@hatchet.step()
|
||||
def step1(self, context: Context):
|
||||
now = datetime.now()
|
||||
print(f"printed at \t {now.strftime("%H:%M:%S")}")
|
||||
print(f"message \t {context.workflow_input()['message']}")
|
||||
|
||||
worker = hatchet.worker('test-worker', max_runs=4)
|
||||
worker.register_workflow(PrintSchedule())
|
||||
worker.register_workflow(PrintPrinter())
|
||||
|
||||
worker.start()
|
||||
Reference in New Issue
Block a user