Standalone admin panel with all data stored in SQLite database
Tasks Page | Task Details Page |
---|---|
![]() |
![]() |
- Add this middleware to your taskiq broker:
from typing import Any
from urllib.parse import urljoin
from datetime import datetime, UTC
import httpx
from taskiq import TaskiqMiddleware, TaskiqResult, TaskiqMessage
TASKIQ_ADMIN_URL = "..." # or os.getenv() to use .env vars
TASKIQ_ADMIN_API_TOKEN = "..." # or os.getenv() to use .env vars
class TaskiqAdminMiddleware(TaskiqMiddleware):
def __init__(self, taskiq_broker_name: str | None = None):
super().__init__()
self.__ta_broker_name = taskiq_broker_name
async def pre_execute(self, message: TaskiqMessage):
""""""
async with httpx.AsyncClient() as client:
await client.post(
headers={"access-token": TASKIQ_ADMIN_API_TOKEN},
url=urljoin(TASKIQ_ADMIN_URL, f"/api/tasks/{message.task_id}/started"),
json={
"args": message.args,
"kwargs": message.kwargs,
"taskName": message.task_name,
"worker": self.__ta_broker_name,
"startedAt": datetime.now(UTC).replace(tzinfo=None).isoformat(),
},
)
return super().pre_execute(message)
async def post_execute(
self,
message: TaskiqMessage,
result: TaskiqResult[Any],
):
""""""
async with httpx.AsyncClient() as client:
await client.post(
headers={"access-token": TASKIQ_ADMIN_API_TOKEN},
url=urljoin(TASKIQ_ADMIN_URL, f"/api/tasks/{message.task_id}/executed"),
json={
"error": result.error
if result.error is None
else repr(result.error),
"executionTime": result.execution_time,
"returnValue": {"return_value": result.return_value},
"finishedAt": datetime.now(UTC).replace(tzinfo=None).isoformat(),
},
)
return super().post_execute(message, result)
-
Pull the image from GitHub Container Registry:
docker pull ghcr.io/taskiq-python/taskiq-admin:latest
-
Replace
TASKIQ_ADMIN_API_TOKEN
with any secret enough string and run:
docker run -d --rm \
-p "3000:3000" \
-v "./taskiq-admin-data/:/usr/database/" \
-e "TASKIQ_ADMIN_API_TOKEN=supersecret" \
--name "taskiq-admin" \
"ghcr.io/taskiq-python/taskiq-admin:latest"
- Go to
http://localhost:3000/tasks
.env file example:
TASKIQ_ADMIN_URL="http://taskiq_admin:3000"
TASKIQ_ADMIN_API_TOKEN="supersecret"
compose.yml file example
services:
queue:
build:
context: .
dockerfile: ./Dockerfile
container_name: my_queue
command: taskiq worker app.tasks.queue:broker --workers 1 --max-async-tasks 20
env_file:
- .env
depends_on:
- redis
- taskiq_admin
taskiq_admin:
image: ghcr.io/taskiq-python/taskiq-admin:latest
container_name: taskiq_admin
ports:
- 3000:3000
env_file:
- .env
volumes:
- admin_data:/usr/database/
volumes:
admin_data:
- Run
pnpm install
to install all dependencies - Run
pnpm db:push
to create the sqlite database if needed - Run
pnpm dev
to run the project