Commit 0c129948 authored by BAIRE Anthony's avatar BAIRE Anthony
Browse files

do not destroy jobs while they are running

(because the controller must free the allocated resources first)
parent 2874ba87
......@@ -217,6 +217,7 @@ class Webapp(TimeStampModel):
return query.order_by("-state", "-id").first()
class WebappParameter(TimeStampModel):
"""
Given parameters for a specific webapp
......@@ -388,6 +389,17 @@ class Job(TimeStampModel):
if self.state in (Job.DONE, Job.ARCHIVED)
else self.get_state_display)()
@property
def destroyable(self):
"""Tell if this job can be destroyed from the UI
The current job state machine does not support aborting and deleting a
running job in the same time. Destroying is disabled until its state is
DONE.
"""
return self.state not in (Job.RUNNING, Job.ABORTING)
# def __str__(self):
# return self.webapp
......
......@@ -659,8 +659,16 @@ class JobDelete(LoginRequiredMixin, DeleteView):
template_name = 'job_delete.html'
def delete(self, request, *args, **kwargs):
messages.success(self.request, self.success_message)
return super().delete(request, *args, **kwargs)
job = self.get_object()
if job.destroyable:
messages.success(self.request, self.success_message)
return super().delete(request, *args, **kwargs)
else:
messages.error(self.request, "cannot delete a running job")
return redirect('main:job_detail', job.id)
class JobFileDownload(LoginRequiredMixin, View):
......
......@@ -257,3 +257,16 @@ a {
border: none;
padding-left: 0;
}
/* font-awesome disabled buttons
*
* bootstrap defines the 'disabled' class for <a> elements but only if they
* have the 'btn' class
*
* a (probably) better alternative would be to use a bootstrap 'btn' button
* with a fa icon inside
*/
a.fa-layers.disabled:not(.btn) {
opacity: 0.65;
pointer-events: none;
}
......@@ -21,7 +21,7 @@
data-toggle="tooltip"
data-placement="top"
title="Delete this job"
class="fa-layers fa-2x">
class="fa-layers fa-2x{% if not job.destroyable %} disabled{% endif %}">
<i class="fas fa-square"></i>
<i class="fa-inverse fas fa-trash-alt" data-fa-transform="shrink-7 down-.25 left-.25"></i></span>
<span class="text-hide">Delete this job</span>
......
......@@ -40,7 +40,7 @@
data-toggle="tooltip"
data-placement="top"
title="Delete this job"
class="fa-layers fa-2x">
class="fa-layers fa-2x {% if not job.destroyable %}disabled{% endif %}">
<i class="fas fa-square"></i>
<i class="fa-inverse fas fa-trash-alt" data-fa-transform="shrink-7 down-.25 left-.25"></i>
<span class="text-hide">Delete this job</span>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment