Skip to content
Snippets Groups Projects

Link tasks to their restarts

Merged Theo Lesage requested to merge fk-task-restart into master
+ 5
1
@@ -223,7 +223,7 @@ class TaskRestart(ProcessACLMixin, CreateAPIView):
raise ValidationError(
detail="Task's state must be in a final state to be restarted."
)
if len(Task.objects.filter(original_task=task)) > 0:
if task.restarts.exists():
raise ValidationError(
detail="This task has already been restarted."
)
@@ -236,6 +236,10 @@ class TaskRestart(ProcessACLMixin, CreateAPIView):
# Rename the original task
basename, *_ = copy.slug.rsplit("_old", 1)
if copy.original_task_id:
basename, *_ = copy.slug.rsplit("_old", 1)
else:
basename = copy.slug
latest_task = Task.objects.filter(run=copy.run, slug__startswith=f"{basename}_old").order_by("-created").first()
if not latest_task:
# There is no previously restarted task: the original task will have the slug slug_old1
Loading