1
Fork 0

Add scheduler to do wagtail maintainence

This commit is contained in:
Jake Howard 2018-08-12 21:41:21 +01:00
parent bfd43954f4
commit b9a6932027
Signed by: jake
GPG key ID: 57AFB45680EDD477
5 changed files with 57 additions and 1 deletions

View file

@ -17,6 +17,7 @@ wagtail-markdown = "*"
wagtail-metadata = "*"
"beautifulsoup4" = "*"
honcho = "*"
apscheduler = "*"
[dev-packages]
mypy = "*"

16
Pipfile.lock generated
View file

@ -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",

View file

@ -1 +1,2 @@
web: python3 manage.py runserver 0.0.0.0:8000
scheduler: python3 manage.py scheduler

View file

@ -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()

View file

@ -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',
},
}