Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Be more strict when updating jobs, set update_fields on each .save() #664

Merged
merged 1 commit into from
May 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docker-app/qfieldcloud/core/management/commands/dequeue.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def handle(self, *args, **options):
if queued_job:
logging.info(f"Dequeued job {queued_job.id}, run!")
queued_job.status = Job.Status.QUEUED
queued_job.save()
queued_job.save(update_fields=["status"])

if queued_job:
self._run(queued_job)
Expand Down
16 changes: 8 additions & 8 deletions docker-app/worker_wrapper/wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def __init__(self, job_id: str) -> None:
if self.job:
self.job.status = Job.Status.FAILED
self.job.feedback = feedback
self.job.save()
self.job.save(update_fields=["status", "feedback"])
logger.exception(msg, exc_info=err)
else:
logger.critical(msg, exc_info=err)
Expand Down Expand Up @@ -108,7 +108,7 @@ def run(self):
try:
self.job.status = Job.Status.STARTED
self.job.started_at = timezone.now()
self.job.save()
self.job.save(update_fields=["status", "started_at"])

self.before_docker_run()

Expand Down Expand Up @@ -147,10 +147,11 @@ def run(self):

self.job.output = output.decode("utf-8")
self.job.feedback = feedback
self.job.save()
self.job.save(update_fields=["output", "feedback"])

if exit_code != 0 or feedback.get("error") is not None:
self.job.status = Job.Status.FAILED
self.job.save(update_fields=["status"])

try:
self.after_docker_exception()
Expand All @@ -160,7 +161,6 @@ def run(self):
exc_info=err,
)

self.job.save()
return

# make sure we have reloaded the project, since someone might have changed it already
Expand All @@ -170,7 +170,7 @@ def run(self):

self.job.finished_at = timezone.now()
self.job.status = Job.Status.FINISHED
self.job.save()
self.job.save(update_fields=["status", "finished_at"])

except Exception as err:
(_type, _value, tb) = sys.exc_info()
Expand Down Expand Up @@ -198,7 +198,7 @@ def run(self):
exc_info=err,
)

self.job.save()
self.job.save(update_fields=["status", "feedback", "finished_at"])
except Exception as err:
logger.error(
"Failed to handle exception and update the job status", exc_info=err
Expand Down Expand Up @@ -244,7 +244,7 @@ def _run_docker(

# `docker_started_at`/`docker_finished_at` tracks the time spent on docker only
self.job.docker_started_at = timezone.now()
self.job.save()
self.job.save(update_fields=["docker_started_at"])

container: Container = client.containers.run( # type:ignore
QGIS_CONTAINER_NAME,
Expand Down Expand Up @@ -278,7 +278,7 @@ def _run_docker(

# `docker_started_at`/`docker_finished_at` tracks the time spent on docker only
self.job.docker_finished_at = timezone.now()
self.job.save()
self.job.save(update_fields=["docker_finished_at"])

logs = b""
# Retry reading the logs, as it may fail
Expand Down