Merge pull request #1387 from paperless-ngx/bugfix-task-error-prevents-consume

Bugfix: Catch all exceptions during the task signals
This commit is contained in:
shamoon 2022-08-10 07:09:29 -07:00 committed by GitHub
commit 3af4808864
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -11,7 +11,6 @@ from django.contrib.contenttypes.models import ContentType
from django.db import DatabaseError
from django.db import models
from django.db.models import Q
from django.db.utils import OperationalError
from django.dispatch import receiver
from django.utils import termcolors
from django.utils import timezone
@ -514,7 +513,9 @@ def init_paperless_task(sender, task, **kwargs):
paperless_task.name = task["name"]
paperless_task.created = task["started"]
paperless_task.save()
except OperationalError as e:
except Exception as e:
# Don't let an exception in the signal handlers prevent
# a document from being consumed.
logger.error(f"Creating PaperlessTask failed: {e}")
@ -527,10 +528,10 @@ def paperless_task_started(sender, task, **kwargs):
)
paperless_task.started = timezone.now()
paperless_task.save()
except OperationalError as e:
logger.error(f"Creating PaperlessTask failed: {e}")
except PaperlessTask.DoesNotExist:
pass
except Exception as e:
logger.error(f"Creating PaperlessTask failed: {e}")
@receiver(models.signals.post_save, sender=django_q.models.Task)
@ -542,7 +543,7 @@ def update_paperless_task(sender, instance, **kwargs):
)
paperless_task.attempted_task = instance
paperless_task.save()
except OperationalError as e:
logger.error(f"Creating PaperlessTask failed: {e}")
except PaperlessTask.DoesNotExist:
pass
except Exception as e:
logger.error(f"Creating PaperlessTask failed: {e}")