mirror of
https://github.com/hatchet-dev/hatchet.git
synced 2026-01-07 01:09:38 -06:00
feat(ts): improved custom logger (#1652)
* wip improved signatures * feat: retry count and improved logger * task pre * update example
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
import asyncio
|
||||
from datetime import datetime, timedelta
|
||||
from random import choice
|
||||
from typing import AsyncGenerator, Literal
|
||||
from subprocess import Popen
|
||||
from typing import Any, AsyncGenerator, Literal
|
||||
from uuid import uuid4
|
||||
|
||||
import pytest
|
||||
@@ -60,8 +61,20 @@ async def dummy_runs() -> None:
|
||||
return None
|
||||
|
||||
|
||||
@pytest.mark.asyncio()
|
||||
async def test_priority(hatchet: Hatchet, dummy_runs: None) -> None:
|
||||
@pytest.mark.parametrize(
|
||||
"on_demand_worker",
|
||||
[
|
||||
(
|
||||
["poetry", "run", "python", "examples/priority/worker.py", "--slots", "1"],
|
||||
8003,
|
||||
)
|
||||
],
|
||||
indirect=True,
|
||||
)
|
||||
@pytest.mark.asyncio(loop_scope="session")
|
||||
async def test_priority(
|
||||
hatchet: Hatchet, dummy_runs: None, on_demand_worker: Popen[Any]
|
||||
) -> None:
|
||||
test_run_id = str(uuid4())
|
||||
choices: list[Priority] = ["low", "medium", "high", "default"]
|
||||
N = 30
|
||||
@@ -134,8 +147,20 @@ async def test_priority(hatchet: Hatchet, dummy_runs: None) -> None:
|
||||
assert curr.finished_at >= curr.started_at
|
||||
|
||||
|
||||
@pytest.mark.asyncio()
|
||||
async def test_priority_via_scheduling(hatchet: Hatchet, dummy_runs: None) -> None:
|
||||
@pytest.mark.parametrize(
|
||||
"on_demand_worker",
|
||||
[
|
||||
(
|
||||
["poetry", "run", "python", "examples/priority/worker.py", "--slots", "1"],
|
||||
8003,
|
||||
)
|
||||
],
|
||||
indirect=True,
|
||||
)
|
||||
@pytest.mark.asyncio(loop_scope="session")
|
||||
async def test_priority_via_scheduling(
|
||||
hatchet: Hatchet, dummy_runs: None, on_demand_worker: Popen[Any]
|
||||
) -> None:
|
||||
test_run_id = str(uuid4())
|
||||
sleep_time = 3
|
||||
n = 30
|
||||
@@ -258,8 +283,20 @@ def time_until_next_minute() -> float:
|
||||
return (next_minute - now).total_seconds()
|
||||
|
||||
|
||||
@pytest.mark.asyncio()
|
||||
async def test_priority_via_cron(hatchet: Hatchet, crons: tuple[str, str, int]) -> None:
|
||||
@pytest.mark.parametrize(
|
||||
"on_demand_worker",
|
||||
[
|
||||
(
|
||||
["poetry", "run", "python", "examples/priority/worker.py", "--slots", "1"],
|
||||
8003,
|
||||
)
|
||||
],
|
||||
indirect=True,
|
||||
)
|
||||
@pytest.mark.asyncio(loop_scope="session")
|
||||
async def test_priority_via_cron(
|
||||
hatchet: Hatchet, crons: tuple[str, str, int], on_demand_worker: Popen[Any]
|
||||
) -> None:
|
||||
workflow_id, test_run_id, n = crons
|
||||
|
||||
await asyncio.sleep(time_until_next_minute() + 10)
|
||||
|
||||
@@ -1,12 +1,6 @@
|
||||
import time
|
||||
|
||||
from hatchet_sdk import (
|
||||
ConcurrencyExpression,
|
||||
ConcurrencyLimitStrategy,
|
||||
Context,
|
||||
EmptyModel,
|
||||
Hatchet,
|
||||
)
|
||||
from hatchet_sdk import Context, EmptyModel, Hatchet
|
||||
|
||||
hatchet = Hatchet(debug=True)
|
||||
|
||||
@@ -17,11 +11,6 @@ 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,
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user