|
1 |
| -# Nuxt Minimal Starter |
2 |
| - |
3 |
| -Look at the [Nuxt documentation](https://nuxt.com/docs/getting-started/introduction) to learn more. |
4 |
| - |
5 |
| -## Setup |
6 |
| - |
7 |
| -Make sure to install dependencies: |
8 |
| - |
9 |
| -```bash |
10 |
| -# npm |
11 |
| -npm install |
12 |
| - |
13 |
| -# pnpm |
14 |
| -pnpm install |
15 |
| - |
16 |
| -# yarn |
17 |
| -yarn install |
18 |
| - |
19 |
| -# bun |
20 |
| -bun install |
| 1 | +## Broker-agnostic admin pangel for Taskiq |
| 2 | + |
| 3 | +Tasks Page | Task Details Page |
| 4 | +:-------------------------:|:-------------------------: |
| 5 | + |  |
| 6 | + |
| 7 | +### Usage |
| 8 | + |
| 9 | +1) Add this middleware to your taskiq broker: |
| 10 | + |
| 11 | +```python |
| 12 | +from typing import Any |
| 13 | +from datetime import datetime, UTC |
| 14 | + |
| 15 | +import httpx |
| 16 | +from taskiq import TaskiqMiddleware, TaskiqResult, TaskiqMessage |
| 17 | + |
| 18 | +TASKIQ_ADMIN_URL = "..." # or your env vars from .env |
| 19 | +TASKIQ_ADMIN_API_TOKEN = "..." # or your env vars from .env |
| 20 | + |
| 21 | + |
| 22 | +class TaskiqAdminMiddleware(TaskiqMiddleware): |
| 23 | + async def pre_execute(self, message: TaskiqMessage): |
| 24 | + """""" |
| 25 | + |
| 26 | + async with httpx.AsyncClient() as client: |
| 27 | + await client.post( |
| 28 | + headers={"access-token": TASKIQ_ADMIN_API_TOKEN}, |
| 29 | + url=f"{TASKIQ_ADMIN_URL}/tasks/{message.task_id}/started", |
| 30 | + json={ |
| 31 | + "worker": "WIP", |
| 32 | + "args": message.args, |
| 33 | + "kwargs": message.kwargs, |
| 34 | + "taskName": message.task_name, |
| 35 | + "startedAt": datetime.now(UTC) |
| 36 | + .replace(tzinfo=None) |
| 37 | + .isoformat(), |
| 38 | + }, |
| 39 | + ) |
| 40 | + |
| 41 | + return super().pre_execute(message) |
| 42 | + |
| 43 | + async def post_execute( |
| 44 | + self, |
| 45 | + message: TaskiqMessage, |
| 46 | + result: TaskiqResult[Any], |
| 47 | + ): |
| 48 | + """""" |
| 49 | + |
| 50 | + async with httpx.AsyncClient() as client: |
| 51 | + await client.post( |
| 52 | + headers={"access-token": TASKIQ_ADMIN_API_TOKEN}, |
| 53 | + url=f"{TASKIQ_ADMIN_URL}/tasks/{message.task_id}/executed", |
| 54 | + json={ |
| 55 | + "error": result.error |
| 56 | + if result.error is None |
| 57 | + else repr(result.error), |
| 58 | + "result": result.return_value, |
| 59 | + "returnValue": result.return_value, |
| 60 | + "executionTime": result.execution_time, |
| 61 | + "finishedAt": datetime.now(UTC) |
| 62 | + .replace(tzinfo=None) |
| 63 | + .isoformat(), |
| 64 | + }, |
| 65 | + ) |
| 66 | + |
| 67 | + return super().post_execute(message, result) |
21 | 68 | ```
|
22 | 69 |
|
23 |
| -## Development Server |
24 |
| - |
25 |
| -Start the development server on `http://localhost:3000`: |
| 70 | +2) Pull the image from DockerHub: `docker pull artur10/taskiq-admin:1.0.0` |
26 | 71 |
|
| 72 | +3) Replace `ACCESS_TOKEN` with any secret enough string and run: |
27 | 73 | ```bash
|
28 |
| -# npm |
29 |
| -npm run dev |
30 |
| - |
31 |
| -# pnpm |
32 |
| -pnpm dev |
33 |
| - |
34 |
| -# yarn |
35 |
| -yarn dev |
36 |
| - |
37 |
| -# bun |
38 |
| -bun run dev |
39 |
| -``` |
40 |
| - |
41 |
| -## Production |
42 |
| - |
43 |
| -Build the application for production: |
44 |
| - |
45 |
| -```bash |
46 |
| -# npm |
47 |
| -npm run build |
48 |
| - |
49 |
| -# pnpm |
50 |
| -pnpm build |
51 |
| - |
52 |
| -# yarn |
53 |
| -yarn build |
54 |
| - |
55 |
| -# bun |
56 |
| -bun run build |
57 |
| -``` |
58 |
| - |
59 |
| -Locally preview production build: |
60 |
| - |
61 |
| -```bash |
62 |
| -# npm |
63 |
| -npm run preview |
64 |
| - |
65 |
| -# pnpm |
66 |
| -pnpm preview |
67 |
| - |
68 |
| -# yarn |
69 |
| -yarn preview |
70 |
| - |
71 |
| -# bun |
72 |
| -bun run preview |
| 74 | +docker run -d --rm \ |
| 75 | + -e ACCESS_TOKEN=supersecret \ |
| 76 | + -p "3000:3000" \ |
| 77 | + -v ./taskiq-admin-data/:/usr/database/ \ |
| 78 | + --name taskiq-admin \ |
| 79 | + artur10/taskiq-admin:1.0.0 |
73 | 80 | ```
|
74 | 81 |
|
75 |
| -Check out the [deployment documentation](https://nuxt.com/docs/getting-started/deployment) for more information. |
| 82 | +4) Go to `http://localhost:3000/tasks` |
0 commit comments