*: ensure TaskResult uid is slugified to prevent URL errors

This commit is contained in:
Jens Langhammer
2020-10-16 21:31:12 +02:00
parent 96846220c3
commit 3454760731
2 changed files with 10 additions and 4 deletions

View File

@ -4,6 +4,7 @@ from typing import Any
from asgiref.sync import async_to_sync
from channels.layers import get_channel_layer
from django.db.models.base import Model
from django.utils.text import slugify
from structlog import get_logger
from passbook.lib.tasks import MonitoredTask, TaskResult, TaskResultStatus
@ -45,10 +46,14 @@ def outpost_controller(self: MonitoredTask, outpost_pk: str):
logs = ProxyDockerController(outpost).run_with_logs()
except ControllerException as exc:
self.set_status(
TaskResult(TaskResultStatus.ERROR, uid=outpost.name).with_error(exc)
TaskResult(TaskResultStatus.ERROR, uid=slugify(outpost.name)).with_error(
exc
)
)
else:
self.set_status(TaskResult(TaskResultStatus.SUCCESSFUL, logs, uid=outpost.name))
self.set_status(
TaskResult(TaskResultStatus.SUCCESSFUL, logs, uid=slugify(outpost.name))
)
@CELERY_APP.task()