complete jobs more sensibly

- fix tuple in tar export I accidentally broke by following pylint blindly
- just use job.set_status to complete jobs since it does everything we need
- fix/avoid Celery "not JSON deserializable" error by not saving whole job including user value
This commit is contained in:
Hugh Rundle 2023-10-23 20:44:52 +11:00
parent ddec2dbaa9
commit e29c93a1e9
No known key found for this signature in database
GPG key ID: A7E35779918253F9
2 changed files with 5 additions and 7 deletions

View file

@ -42,13 +42,12 @@ def start_export_task(**kwargs):
job.export_data = ContentFile(b"", str(uuid4()))
json_data = json_export(job.user)
tar_export(json_data, job.user, job.export_data)
job.save(update_fields=["export_data"])
except Exception as err: # pylint: disable=broad-except
logger.exception("User Export Job %s Failed with error: %s", job.id, err)
job.set_status("failed")
job.set_status(
"complete"
) # need to explicitly set this here to trigger notifications
job.save(update_fields=["export_data"])
job.set_status("complete")
def tar_export(json_data: str, user, file):
@ -61,7 +60,7 @@ def tar_export(json_data: str, user, file):
if getattr(user, "avatar", False):
tar.add_image(user.avatar, filename="avatar")
editions = get_books_for_user(user)
editions, books = get_books_for_user(user) # pylint: disable=unused-argument
for book in editions:
if getattr(book, "cover", False):
tar.add_image(book.cover)

View file

@ -61,8 +61,7 @@ def start_import_task(**kwargs):
process_books(job, tar)
job.set_status("complete") # set here to trigger notifications
job.save()
job.set_status("complete")
archive_file.close()
except Exception as err: # pylint: disable=broad-except