forked from benavlabs/FastAPI-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctions.py
More file actions
34 lines (22 loc) · 812 Bytes
/
functions.py
File metadata and controls
34 lines (22 loc) · 812 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import asyncio
import logging
from typing import Any
import structlog
import uvloop
from arq.worker import Worker
asyncio.set_event_loop_policy(uvloop.EventLoopPolicy())
# -------- background tasks --------
async def sample_background_task(ctx: Worker, name: str) -> str:
await asyncio.sleep(5)
return f"Task {name} is complete!"
# -------- base functions --------
async def startup(ctx: Worker) -> None:
logging.info("Worker Started")
async def shutdown(ctx: Worker) -> None:
logging.info("Worker end")
async def on_job_start(ctx: dict[str, Any]) -> None:
structlog.contextvars.bind_contextvars(job_id=ctx["job_id"])
logging.info("Job Started")
async def on_job_end(ctx: dict[str, Any]) -> None:
logging.info("Job Competed")
structlog.contextvars.clear_contextvars()