Added an informational log message for consumer start

This commit is contained in:
Daniel Quinn 2016-03-06 17:26:07 +00:00
parent 2fba41ad75
commit 3b278c3a24
3 changed files with 25 additions and 2 deletions

View File

@ -1,10 +1,12 @@
import datetime
import logging
import os
import time
from django.conf import settings
from django.core.management.base import BaseCommand, CommandError
from ...models import Log
from ...consumer import Consumer, ConsumerError
from ...mail import MailFetcher, MailFetcherError
@ -44,6 +46,13 @@ class Command(BaseCommand):
except FileExistsError:
pass
logging.getLogger(__name__).info(
"Starting document consumer at {}".format(
settings.CONSUMPTION_DIR
),
extra={"component": Log.COMPONENT_CONSUMER}
)
try:
while True:
self.loop()

View File

@ -4,7 +4,7 @@ from django.db import models
from django.db.models.aggregates import Max
class Concat(models.Aggregate):
class GroupConcat(models.Aggregate):
"""
Theoretically, this should work in Sqlite, PostgreSQL, and MySQL, but I've
only ever tested it in Sqlite.
@ -60,7 +60,7 @@ class LogQuerySet(models.query.QuerySet):
def by_group(self):
return self.values("group").annotate(
time=Max("modified"),
messages=Concat("message"),
messages=GroupConcat("message"),
).order_by("-time")

View File

@ -1,6 +1,7 @@
import logging
import os
import re
import uuid
from django.conf import settings
from django.core.urlresolvers import reverse
@ -236,3 +237,16 @@ class Log(models.Model):
def __str__(self):
return self.message
def save(self, *args, **kwargs):
"""
To allow for the case where we don't want to group the message, we
shouldn't force the caller to specify a one-time group value. However,
allowing group=None means that the manager can't differentiate the
different un-grouped messages, so instead we set a random one here.
"""
if not self.group:
self.group = uuid.uuid4()
models.Model.save(self, *args, **kwargs)