mirror of
https://github.com/hatchet-dev/hatchet.git
synced 2026-01-06 00:40:10 -06:00
Fe overhaul docs (#1640)
* api changes * doc changes * move docs * generated * generate * pkg * backmerge main * revert to main * revert main * race? * remove go tests
This commit is contained in:
17
examples/python/logger/client.py
Normal file
17
examples/python/logger/client.py
Normal file
@@ -0,0 +1,17 @@
|
||||
# > RootLogger
|
||||
|
||||
|
||||
import logging
|
||||
|
||||
from hatchet_sdk import ClientConfig, Hatchet
|
||||
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
|
||||
root_logger = logging.getLogger()
|
||||
|
||||
hatchet = Hatchet(
|
||||
debug=True,
|
||||
config=ClientConfig(
|
||||
logger=root_logger,
|
||||
),
|
||||
)
|
||||
10
examples/python/logger/test_logger.py
Normal file
10
examples/python/logger/test_logger.py
Normal file
@@ -0,0 +1,10 @@
|
||||
import pytest
|
||||
|
||||
from examples.logger.workflow import logging_workflow
|
||||
|
||||
|
||||
@pytest.mark.asyncio(loop_scope="session")
|
||||
async def test_run() -> None:
|
||||
result = await logging_workflow.aio_run()
|
||||
|
||||
assert result["root_logger"]["status"] == "success"
|
||||
3
examples/python/logger/trigger.py
Normal file
3
examples/python/logger/trigger.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from examples.logger.workflow import logging_workflow
|
||||
|
||||
logging_workflow.run()
|
||||
12
examples/python/logger/worker.py
Normal file
12
examples/python/logger/worker.py
Normal file
@@ -0,0 +1,12 @@
|
||||
from examples.logger.client import hatchet
|
||||
from examples.logger.workflow import logging_workflow
|
||||
|
||||
|
||||
def main() -> None:
|
||||
worker = hatchet.worker("logger-worker", slots=5, workflows=[logging_workflow])
|
||||
|
||||
worker.start()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
39
examples/python/logger/workflow.py
Normal file
39
examples/python/logger/workflow.py
Normal file
@@ -0,0 +1,39 @@
|
||||
# > LoggingWorkflow
|
||||
|
||||
import logging
|
||||
import time
|
||||
|
||||
from examples.logger.client import hatchet
|
||||
from hatchet_sdk import Context, EmptyModel
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
logging_workflow = hatchet.workflow(
|
||||
name="LoggingWorkflow",
|
||||
)
|
||||
|
||||
|
||||
@logging_workflow.task()
|
||||
def root_logger(input: EmptyModel, ctx: Context) -> dict[str, str]:
|
||||
for i in range(12):
|
||||
logger.info("executed step1 - {}".format(i))
|
||||
logger.info({"step1": "step1"})
|
||||
|
||||
time.sleep(0.1)
|
||||
|
||||
return {"status": "success"}
|
||||
|
||||
|
||||
|
||||
# > ContextLogger
|
||||
|
||||
|
||||
@logging_workflow.task()
|
||||
def context_logger(input: EmptyModel, ctx: Context) -> dict[str, str]:
|
||||
for i in range(12):
|
||||
ctx.log("executed step1 - {}".format(i))
|
||||
ctx.log({"step1": "step1"})
|
||||
|
||||
time.sleep(0.1)
|
||||
|
||||
return {"status": "success"}
|
||||
Reference in New Issue
Block a user