Skip to content

Commit bd861b8

Browse files
authored
Merge pull request #42 from danfimov/fix-bugs
fix: multiple bugs
2 parents ee18243 + 0a2986f commit bd861b8

File tree

9 files changed

+29
-20
lines changed

9 files changed

+29
-20
lines changed

taskiq_dashboard/api/application.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import contextlib
2+
import pathlib
23
import typing as tp
34

45
import fastapi
@@ -65,7 +66,7 @@ def get_application() -> fastapi.FastAPI:
6566
app.include_router(router=event_router)
6667
app.include_router(router=action_router)
6768
app.include_router(router=schedule_router)
68-
app.mount('/static', StaticFiles(directory='taskiq_dashboard/api/static'), name='static')
69+
app.mount('/static', StaticFiles(directory=pathlib.Path(__file__).parent / 'static'), name='static')
6970
app.add_middleware(AccessTokenMiddleware)
7071
setup_dishka(container=dependencies.container, app=app)
7172
return app

taskiq_dashboard/api/routers/task.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,8 @@ async def task_details(
102102
"""
103103
Display detailed information for a specific task.
104104
"""
105-
# Get task by ID
106105
task = await repository.get_task_by_id(task_id)
107-
108106
if task is None:
109-
# If task is not found, return 404 page
110107
return jinja_templates.TemplateResponse(
111108
name='404.html',
112109
context={
@@ -115,16 +112,15 @@ async def task_details(
115112
},
116113
status_code=404,
117114
)
118-
119-
# Convert task to JSON for the frontend
120-
task_json = json.dumps(task.model_dump(mode='json'))
121-
115+
result_json = None
116+
if task.result:
117+
result_json = json.dumps(task.result, indent=2, ensure_ascii=False)
122118
return jinja_templates.TemplateResponse(
123119
name='task_details.html',
124120
context={
125121
'request': request,
126122
'task': task,
127-
'task_json': task_json,
123+
'task_result': result_json,
128124
'enable_actions': request.app.state.broker is not None,
129125
'enable_additional_actions': False, # Placeholder for future features like retries with different args
130126
},

taskiq_dashboard/api/templates.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
import pathlib
2+
13
from fastapi.templating import Jinja2Templates
24

35

4-
jinja_templates = Jinja2Templates(directory='taskiq_dashboard/api/templates')
6+
jinja_templates = Jinja2Templates(directory=pathlib.Path(__file__).parent / 'templates')

taskiq_dashboard/api/templates/partial/task_list_item.html

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,12 @@
2323
</span>
2424
</td>
2525
<td class="px-6 py-4 group-hover:bg-ctp-blue-100/20 w-auto">{{ task.worker }}</td>
26-
<td class="px-6 py-4 group-hover:bg-ctp-blue-100/20 w-min">{{ task.started_at.strftime('%Y-%m-%d %H:%M:%S') }}</td>
26+
27+
{% if task.started_at %}
28+
<td class="px-6 py-4 group-hover:bg-ctp-blue-100/20 w-min">{{ task.started_at.strftime('%Y-%m-%d %H:%M:%S') }}</td>
29+
{% else %}
30+
<td class="px-6 py-4 group-hover:bg-ctp-blue-100/20 w-min">-</td>
31+
{% endif %}
2732
<td class="px-6 py-4 group-hover:bg-ctp-blue-100/20 w-min">
2833
{{ task.finished_at.strftime('%Y-%m-%d %H:%M:%S') if task.finished_at else '-' }}
2934
</td>

taskiq_dashboard/api/templates/task_details.html

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,11 @@ <h3>Task ID</h3>
116116
<div class="grid grid-cols-1 md:grid-cols-3 gap-6 mb-6">
117117
<div>
118118
<h3 class="mb-2">Started at</h3>
119-
<p class="font-light">{{ task.started_at.strftime('%Y-%m-%d %H:%M:%S') }}</p>
119+
{% if task.started_at %}
120+
<p class="font-light">{{ task.started_at.strftime('%Y-%m-%d %H:%M:%S') }}</p>
121+
{% else %}
122+
<p class="font-light">Not started yet</p>
123+
{% endif %}
120124
</div>
121125
<div>
122126
<h3 class="mb-2">Finished at</h3>
@@ -189,9 +193,9 @@ <h2 class="font-bold text-xl">Task result</h2>
189193

190194
<div class="mb-4">
191195
<h3 class="mb-2 font-normal">Result</h3>
192-
{% if task.result %}
196+
{% if task_result %}
193197
<div class="bg-ctp-base rounded p-4 overflow-x-auto">
194-
<pre class="whitespace-pre-wrap text-sm">{{ task.result | tojson(indent=2) }}</pre>
198+
<pre class="whitespace-pre-wrap text-sm">{{ task_result | safe }}</pre>
195199
</div>
196200
{% elif task.status == 0 %}
197201
<p class="font-light text-ctp-subtext0">Task is still in progress</p>

taskiq_dashboard/domain/dto/task.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class Task(pydantic.BaseModel):
1919
kwargs: dict[str, tp.Any] = pydantic.Field(default_factory=dict)
2020
labels: dict[str, tp.Any] = pydantic.Field(default_factory=dict)
2121

22-
result: dict | pydantic.Json | None = None
22+
result: dict | list | pydantic.Json | None = None
2323
error: str | None = None
2424

2525
queued_at: datetime.datetime | None = None
@@ -36,7 +36,7 @@ class QueuedTask(pydantic.BaseModel):
3636
kwargs: dict[str, tp.Any] = pydantic.Field(default_factory=dict)
3737
labels: dict[str, tp.Any] = pydantic.Field(default_factory=dict)
3838
task_name: str
39-
worker: str
39+
worker: str | None
4040
queued_at: datetime.datetime
4141

4242
model_config = pydantic.ConfigDict(

taskiq_dashboard/infrastructure/services/task_service.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ async def create_task(
6666
id=task_id,
6767
name=task_arguments.task_name,
6868
status=TaskStatus.QUEUED.value,
69-
worker=task_arguments.worker,
69+
worker=task_arguments.worker or '',
7070
args=task_arguments.args,
7171
kwargs=task_arguments.kwargs,
7272
labels=task_arguments.labels,
@@ -91,7 +91,7 @@ async def update_task(
9191
kwargs=task_arguments.kwargs,
9292
labels=task_arguments.labels,
9393
name=task_arguments.task_name,
94-
worker=task_arguments.worker,
94+
worker=task_arguments.worker or '',
9595
)
9696
else:
9797
task_status = TaskStatus.FAILURE if task_arguments.error is not None else TaskStatus.COMPLETED

taskiq_dashboard/infrastructure/settings.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ class Settings(pydantic_settings.BaseSettings):
121121
env_prefix='TASKIQ_DASHBOARD__',
122122
env_file=('conf/.env', os.getenv('ENV_FILE', '.env')),
123123
env_file_encoding='utf-8',
124+
extra='ignore',
124125
)
125126

126127

taskiq_dashboard/interface/application.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class TaskiqDashboard:
1313
def __init__(
1414
self,
1515
api_token: str,
16-
storage_type: str = 'sqlite',
16+
storage_type: tp.Literal['sqlite', 'postgres'] = 'sqlite',
1717
database_dsn: str = 'sqlite+aiosqlite:///taskiq_dashboard.db',
1818
broker: AsyncBroker | None = None,
1919
scheduler: TaskiqScheduler | None = None,
@@ -31,7 +31,7 @@ def __init__(
3131
"""
3232
self.settings = get_settings()
3333
self.settings.api.token = SecretStr(api_token)
34-
34+
self.settings.storage_type = storage_type
3535
if storage_type == 'sqlite':
3636
self.settings.sqlite = SqliteSettings(dsn=database_dsn) # type: ignore[call-arg]
3737
else:

0 commit comments

Comments
 (0)