mirror of
https://github.com/hatchet-dev/hatchet.git
synced 2025-12-31 05:39:41 -06:00
* api changes * doc changes * move docs * generated * generate * pkg * backmerge main * revert to main * revert main * race? * remove go tests
46 lines
855 B
Python
46 lines
855 B
Python
import time
|
|
|
|
from hatchet_sdk import (
|
|
ConcurrencyExpression,
|
|
ConcurrencyLimitStrategy,
|
|
Context,
|
|
EmptyModel,
|
|
Hatchet,
|
|
)
|
|
|
|
hatchet = Hatchet(debug=True)
|
|
|
|
# > Default priority
|
|
DEFAULT_PRIORITY = 1
|
|
SLEEP_TIME = 0.25
|
|
|
|
priority_workflow = hatchet.workflow(
|
|
name="PriorityWorkflow",
|
|
default_priority=DEFAULT_PRIORITY,
|
|
concurrency=ConcurrencyExpression(
|
|
max_runs=1,
|
|
expression="'true'",
|
|
limit_strategy=ConcurrencyLimitStrategy.GROUP_ROUND_ROBIN,
|
|
),
|
|
)
|
|
|
|
|
|
@priority_workflow.task()
|
|
def priority_task(input: EmptyModel, ctx: Context) -> None:
|
|
print("Priority:", ctx.priority)
|
|
time.sleep(SLEEP_TIME)
|
|
|
|
|
|
def main() -> None:
|
|
worker = hatchet.worker(
|
|
"priority-worker",
|
|
slots=1,
|
|
workflows=[priority_workflow],
|
|
)
|
|
|
|
worker.start()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|