From b9a6932027960513c91435f19f72c756c5bc4b40 Mon Sep 17 00:00:00 2001 From: Jake Howard Date: Sun, 12 Aug 2018 21:41:21 +0100 Subject: [PATCH] Add scheduler to do wagtail maintainence --- Pipfile | 1 + Pipfile.lock | 16 +++++++++++- Procfile | 1 + .../common/management/commands/scheduler.py | 25 +++++++++++++++++++ project/settings.py | 15 +++++++++++ 5 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 project/common/management/commands/scheduler.py diff --git a/Pipfile b/Pipfile index ede0a59..73c7792 100644 --- a/Pipfile +++ b/Pipfile @@ -17,6 +17,7 @@ wagtail-markdown = "*" wagtail-metadata = "*" "beautifulsoup4" = "*" honcho = "*" +apscheduler = "*" [dev-packages] mypy = "*" diff --git a/Pipfile.lock b/Pipfile.lock index cecb090..e950179 100644 --- a/Pipfile.lock +++ b/Pipfile.lock @@ -1,7 +1,7 @@ { "_meta": { "hash": { - "sha256": "7e5e4e6264138d1006434f06a80432b48823e721ad7628d1ef08cd7e5c107f71" + "sha256": "6980a024219b52487dfcf494d8eb84ed8fec1d9a4ab942c9198d0ec872aa95f7" }, "pipfile-spec": 6, "requires": { @@ -16,6 +16,14 @@ ] }, "default": { + "apscheduler": { + "hashes": [ + "sha256:6aba721f4db411be8f5ffe89acbaa174fe46425e15edf32ed7bfdfafb6ec1eb4", + "sha256:f255126d188703d68af84d9159df7dce7bed0bb351bf8551d33fe0988bae2bf0" + ], + "index": "pypi", + "version": "==3.5.2" + }, "beautifulsoup4": { "hashes": [ "sha256:194ec62a25438adcb3fdb06378b26559eda1ea8a747367d34c33cef9c7f48d57", @@ -289,6 +297,12 @@ ], "version": "==1.11.0" }, + "tzlocal": { + "hashes": [ + "sha256:4ebeb848845ac898da6519b9b31879cf13b6626f7184c496037b818e238f2c4e" + ], + "version": "==1.5.1" + }, "unidecode": { "hashes": [ "sha256:280a6ab88e1f2eb5af79edff450021a0d3f0448952847cd79677e55e58bad051", diff --git a/Procfile b/Procfile index 07f4d51..5128091 100644 --- a/Procfile +++ b/Procfile @@ -1 +1,2 @@ web: python3 manage.py runserver 0.0.0.0:8000 +scheduler: python3 manage.py scheduler diff --git a/project/common/management/commands/scheduler.py b/project/common/management/commands/scheduler.py new file mode 100644 index 0000000..6fe6510 --- /dev/null +++ b/project/common/management/commands/scheduler.py @@ -0,0 +1,25 @@ +from apscheduler.schedulers.blocking import BlockingScheduler +from django.core.management.base import BaseCommand +from django.core.management import call_command +import logging +import functools + + +logger = logging.getLogger(__file__) + + +class Command(BaseCommand): + + @classmethod + def call_management_command(cls, command_name): + wrapped = functools.partial(call_command, command_name) + wrapped.__qualname__ = command_name + return wrapped + + def handle(self, **options): + scheduler = BlockingScheduler() + scheduler.add_job(self.call_management_command("publish_scheduled_pages"), 'cron', minute=0) + scheduler.add_job(self.call_management_command("fixtree"), 'cron', day_of_week=0) + scheduler.add_job(self.call_management_command("update_index"), 'cron', day_of_week=0) + scheduler.add_job(self.call_management_command("search_garbage_collect"), 'cron', day_of_week=0) + scheduler.start() diff --git a/project/settings.py b/project/settings.py index a6bd468..d17733d 100644 --- a/project/settings.py +++ b/project/settings.py @@ -179,3 +179,18 @@ if 'ELASTICSEARCH_URL' in os.environ: 'INDEX_SETTINGS': {}, } } + + +LOGGING = { + 'version': 1, + 'handlers': { + 'console': { + 'level': 'DEBUG', + 'class': 'logging.StreamHandler', + }, + }, + 'root': { + 'handlers': ['console'], + 'level': 'INFO', + }, +}