Commit dbb92573 authored by BAIRE Anthony's avatar BAIRE Anthony
Browse files

controller: always update the redis db after processing a job

This way we get redis updates when a job is deleted and this also
prevents inserting a 'DONE' state when the job is not done

Note: we never update the redis job state key from the django server to
avoid race conditions
parent 56ae85bf
Pipeline #36218 failed with stage
in 39 seconds
......@@ -1425,8 +1425,8 @@ class JobManager(Manager):
job.state = int(JobState.DONE)
# TODO report error to the user
job.result= int(JobResult.ERROR)
return
info.ver_id = ver.id
else:
info.ver_id = ver.id
elif state in (JobState.RUNNING, JobState.ABORTING): # pragma: nobranch
# job is already started
......@@ -1462,11 +1462,6 @@ class JobManager(Manager):
info.timeout -= uptime
log.debug("job %d uptime: %.1fs, adjusted timeout is: %.1f",
info.job_id, uptime, info.timeout)
else:
# unexpected state
if state != JobState.DONE:
log.warning("job id %d is in unexpected state %s", job_id, state.name)
return
if state == JobState.WAITING:
......@@ -1493,10 +1488,18 @@ class JobManager(Manager):
# -> wait for its termination
yield from self._finish_job(info, reset)
# replicate the job status/result in the redis database (this is needed
# for transitions to state DONE, but also to DELETED and ARCHIVED
# because the django server does not write any job state in redis)
with ses.begin():
job = ses.query(Job).filter_by(id=job_id).first()
result = None if job is None else JobResult(job.result).name
yield from self._notif_job_state(info, "DONE", result)
if job is None:
state, result = "DELETED", None
else:
state = JobState (job.state) .name
result = JobResult(job.result).name
yield from self._notif_job_state(info, state, result)
# send a notification to the aio frontend when the job state is changed
#
......
......@@ -66,7 +66,7 @@ from .forms import (
WebappForm,
WebappSandboxForm,
)
from .helpers import get_ssh_data, upload_data
from .helpers import get_ssh_data, upload_data, notify_controller
from .signals import job_post_save
from .templatetags.converters import status_icon
......@@ -698,6 +698,7 @@ class JobDelete(LoginRequiredMixin, DeleteView):
transaction.commit()
self.object = job = self.get_object()
notify_controller(job) # so that the DELETED/ARCHIVED state is propagated into the redis db
# delete the data dir if present
# FIXME: if this fail then we have dangling files staying in the way
......
Markdown is supported
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