mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-11-26 11:31:08 +00:00
add error handling and status for user exports
* fix Safari not downloading with the correct filename * add FAILED status * don't provide download link for stopped jobs
This commit is contained in:
parent
a4bfcb34d5
commit
781b01a007
3 changed files with 23 additions and 13 deletions
|
@ -35,13 +35,14 @@ def start_export_task(**kwargs):
|
|||
# don't start the job if it was stopped from the UI
|
||||
if job.complete:
|
||||
return
|
||||
|
||||
# This is where ChildJobs get made
|
||||
job.export_data = ContentFile(b"", str(uuid4()))
|
||||
|
||||
json_data = json_export(job.user)
|
||||
tar_export(json_data, job.user, job.export_data)
|
||||
|
||||
try:
|
||||
# This is where ChildJobs get made
|
||||
job.export_data = ContentFile(b"", str(uuid4()))
|
||||
json_data = json_export(job.user)
|
||||
tar_export(json_data, job.user, job.export_data)
|
||||
except Exception as err: # pylint: disable=broad-except
|
||||
logger.exception("Job %s Failed with error: %s", job.id, err)
|
||||
job.set_status("failed")
|
||||
job.save(update_fields=["export_data"])
|
||||
|
||||
|
||||
|
@ -56,7 +57,8 @@ def tar_export(json_data: str, user, f):
|
|||
|
||||
editions, books = get_books_for_user(user)
|
||||
for book in editions:
|
||||
tar.add_image(book.cover)
|
||||
if getattr(book, "cover", False):
|
||||
tar.add_image(book.cover)
|
||||
|
||||
f.close()
|
||||
|
||||
|
|
|
@ -19,6 +19,7 @@ class Job(models.Model):
|
|||
ACTIVE = "active", _("Active")
|
||||
COMPLETE = "complete", _("Complete")
|
||||
STOPPED = "stopped", _("Stopped")
|
||||
FAILED = "failed", _("Failed")
|
||||
|
||||
task_id = models.UUIDField(unique=True, null=True, blank=True)
|
||||
|
||||
|
@ -43,14 +44,17 @@ class Job(models.Model):
|
|||
|
||||
self.save(update_fields=["status", "complete", "updated_date"])
|
||||
|
||||
def stop_job(self):
|
||||
def stop_job(self, reason=None):
|
||||
"""Stop the job"""
|
||||
if self.complete:
|
||||
return
|
||||
|
||||
self.__terminate_job()
|
||||
|
||||
self.status = self.Status.STOPPED
|
||||
if reason and reason is "failed":
|
||||
self.status = self.Status.FAILED
|
||||
else:
|
||||
self.status = self.Status.STOPPED
|
||||
self.complete = True
|
||||
self.updated_date = timezone.now()
|
||||
|
||||
|
@ -72,6 +76,10 @@ class Job(models.Model):
|
|||
self.stop_job()
|
||||
return
|
||||
|
||||
if status == self.Status.FAILED:
|
||||
self.stop_job(reason="failed")
|
||||
return
|
||||
|
||||
self.updated_date = timezone.now()
|
||||
self.status = status
|
||||
|
||||
|
|
|
@ -48,8 +48,8 @@
|
|||
{% for job in jobs %}
|
||||
<tr>
|
||||
<td>
|
||||
{% if job.complete %}
|
||||
<p><a href="/preferences/user-export/{{ job.task_id }}">{{ job.created_date }}</a></p>
|
||||
{% if job.complete and not job.status == "stopped" and not job.status == "failed" %}
|
||||
<p><a download="" href="/preferences/user-export/{{ job.task_id }}">{{ job.created_date }}</a></p>
|
||||
{% else %}
|
||||
<p>{{ job.created_date }}</p>
|
||||
{% endif %}
|
||||
|
@ -57,7 +57,7 @@
|
|||
<td>{{ job.updated_date }}</td>
|
||||
<td>
|
||||
<span
|
||||
{% if job.status == "stopped" %}
|
||||
{% if job.status == "stopped" or job.status == "failed" %}
|
||||
class="tag is-danger"
|
||||
{% elif job.status == "pending" %}
|
||||
class="tag is-warning"
|
||||
|
|
Loading…
Reference in a new issue