mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-04-09 09:58:20 -05:00
Moved logging logic into the consumer
This commit is contained in:
parent
b11825832d
commit
ca21929cee
@ -142,6 +142,11 @@ class Consumer(object):
|
|||||||
self._cleanup_tempdir(tempdir)
|
self._cleanup_tempdir(tempdir)
|
||||||
self._cleanup_doc(doc)
|
self._cleanup_doc(doc)
|
||||||
|
|
||||||
|
self.log(
|
||||||
|
"info",
|
||||||
|
"Document {} consumption finished".format(document)
|
||||||
|
)
|
||||||
|
|
||||||
document_consumption_finished.send(
|
document_consumption_finished.send(
|
||||||
sender=self.__class__,
|
sender=self.__class__,
|
||||||
document=document,
|
document=document,
|
||||||
|
@ -4,16 +4,10 @@ import os
|
|||||||
import time
|
import time
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.contrib.contenttypes.models import ContentType
|
|
||||||
from django.core.management.base import BaseCommand, CommandError
|
from django.core.management.base import BaseCommand, CommandError
|
||||||
from django.contrib.admin.models import LogEntry, ADDITION
|
|
||||||
from django.contrib.auth.models import User
|
|
||||||
from django.dispatch import receiver
|
|
||||||
|
|
||||||
from ...models import Document
|
|
||||||
from ...consumer import Consumer, ConsumerError
|
from ...consumer import Consumer, ConsumerError
|
||||||
from ...mail import MailFetcher, MailFetcherError
|
from ...mail import MailFetcher, MailFetcherError
|
||||||
from ...signals import document_consumption_finished
|
|
||||||
|
|
||||||
|
|
||||||
class Command(BaseCommand):
|
class Command(BaseCommand):
|
||||||
@ -22,7 +16,6 @@ class Command(BaseCommand):
|
|||||||
consumption directory, and fetch any mail available.
|
consumption directory, and fetch any mail available.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
CONSUME_USER_ID = 1
|
|
||||||
LOOP_TIME = 10 # Seconds
|
LOOP_TIME = 10 # Seconds
|
||||||
MAIL_DELTA = datetime.timedelta(minutes=10)
|
MAIL_DELTA = datetime.timedelta(minutes=10)
|
||||||
|
|
||||||
@ -74,17 +67,3 @@ class Command(BaseCommand):
|
|||||||
delta = self.mail_fetcher.last_checked + self.MAIL_DELTA
|
delta = self.mail_fetcher.last_checked + self.MAIL_DELTA
|
||||||
if delta < datetime.datetime.now():
|
if delta < datetime.datetime.now():
|
||||||
self.mail_fetcher.pull()
|
self.mail_fetcher.pull()
|
||||||
|
|
||||||
@receiver(document_consumption_finished)
|
|
||||||
def notify_finished(sender, document=None, logging_group=None, **kwargs):
|
|
||||||
doctype = ContentType.objects.get_for_model(Document)
|
|
||||||
user = User.objects.get(pk=Command.CONSUME_USER_ID)
|
|
||||||
|
|
||||||
LogEntry.objects.log_action(
|
|
||||||
user_id=user.pk,
|
|
||||||
content_type_id=doctype.pk,
|
|
||||||
object_id=document.pk,
|
|
||||||
object_repr=repr(document),
|
|
||||||
action_flag=ADDITION,
|
|
||||||
change_message='Document %s consumption finished' % document.title
|
|
||||||
)
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user