This repository has been archived by the owner on Feb 16, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 353
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added a task scheduler for recurring tasks
- Loading branch information
Jonas Winkler
committed
Nov 9, 2020
1 parent
5871ce3
commit 9d22d9c
Showing
15 changed files
with
240 additions
and
189 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -65,7 +65,6 @@ target/ | |
.virtualenv | ||
virtualenv | ||
/venv | ||
docker-compose.yml | ||
docker-compose.env | ||
|
||
# Used for development | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,7 +25,6 @@ COPY Pipfile* ./ | |
#Dependencies | ||
RUN apt-get update \ | ||
&& DEBIAN_FRONTEND="noninteractive" apt-get -y --no-install-recommends install \ | ||
anacron \ | ||
build-essential \ | ||
curl \ | ||
ghostscript \ | ||
|
@@ -60,7 +59,6 @@ RUN apt-get update \ | |
COPY scripts/imagemagick-policy.xml /etc/ImageMagick-6/policy.xml | ||
COPY scripts/gunicorn.conf.py ./ | ||
COPY scripts/supervisord.conf /etc/supervisord.conf | ||
COPY scripts/paperless-cron /etc/cron.daily/ | ||
COPY scripts/docker-entrypoint.sh /sbin/docker-entrypoint.sh | ||
|
||
# copy app | ||
|
@@ -71,16 +69,14 @@ COPY --from=frontend /usr/src/paperless/src-ui/dist/paperless-ui/ ./src/document | |
RUN addgroup --gid 1000 paperless \ | ||
&& useradd --uid 1000 --gid paperless --home-dir /usr/src/paperless paperless \ | ||
&& chown -R paperless:paperless . \ | ||
&& chmod 755 /sbin/docker-entrypoint.sh \ | ||
&& chmod +x /etc/cron.daily/paperless-cron \ | ||
&& rm /etc/cron.daily/apt-compat /etc/cron.daily/dpkg | ||
&& chmod 755 /sbin/docker-entrypoint.sh | ||
|
||
WORKDIR /usr/src/paperless/src/ | ||
|
||
RUN sudo -HEu paperless python3 manage.py collectstatic --clear --no-input | ||
|
||
VOLUME ["/usr/src/paperless/data", "/usr/src/paperless/consume", "/usr/src/paperless/export"] | ||
ENTRYPOINT ["/sbin/docker-entrypoint.sh"] | ||
CMD ["python3", "manage.py", "--help"] | ||
CMD ["supervisord", "-c", "/etc/supervisord.conf"] | ||
|
||
LABEL maintainer="Jonas Winkler <[email protected]>" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# Generated by Django 3.1.3 on 2020-11-09 16:36 | ||
|
||
from django.db import migrations | ||
from django.db.migrations import RunPython | ||
from django_q.models import Schedule | ||
from django_q.tasks import schedule | ||
|
||
|
||
def add_schedules(apps, schema_editor): | ||
schedule('documents.tasks.train_classifier', name="Train the classifier", schedule_type=Schedule.HOURLY) | ||
schedule('documents.tasks.index_optimize', name="Optimize the index", schedule_type=Schedule.DAILY) | ||
schedule('documents.tasks.consume_mail', name="Check E-Mail", schedule_type=Schedule.MINUTES, minutes=10) | ||
|
||
|
||
def remove_schedules(apps, schema_editor): | ||
Schedule.objects.all().delete() | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('documents', '1000_update_paperless_all'), | ||
('django_q', '0013_task_attempt_count'), | ||
] | ||
|
||
operations = [ | ||
RunPython(add_schedules, remove_schedules) | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import logging | ||
|
||
from django.conf import settings | ||
from django_q.tasks import async_task, result | ||
from whoosh.writing import AsyncWriter | ||
|
||
from documents import index | ||
from documents.classifier import DocumentClassifier, \ | ||
IncompatibleClassifierVersionError | ||
from documents.mail import MailFetcher | ||
from documents.models import Document | ||
|
||
|
||
def consume_mail(): | ||
MailFetcher().pull() | ||
|
||
|
||
def index_optimize(): | ||
index.open_index().optimize() | ||
|
||
|
||
def index_reindex(): | ||
documents = Document.objects.all() | ||
|
||
ix = index.open_index(recreate=True) | ||
|
||
with AsyncWriter(ix) as writer: | ||
for document in documents: | ||
index.update_document(writer, document) | ||
|
||
|
||
def train_classifier(): | ||
classifier = DocumentClassifier() | ||
|
||
try: | ||
# load the classifier, since we might not have to train it again. | ||
classifier.reload() | ||
except (FileNotFoundError, IncompatibleClassifierVersionError): | ||
# This is what we're going to fix here. | ||
pass | ||
|
||
try: | ||
if classifier.train(): | ||
logging.getLogger(__name__).info( | ||
"Saving updated classifier model to {}...".format( | ||
settings.MODEL_FILE) | ||
) | ||
classifier.save_classifier() | ||
else: | ||
logging.getLogger(__name__).debug( | ||
"Training data unchanged." | ||
) | ||
|
||
except Exception as e: | ||
logging.getLogger(__name__).error( | ||
"Classifier error: " + str(e) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters