From db10d8bcb5cec778ff104c4ca5b50c88ade3161d Mon Sep 17 00:00:00 2001 From: Thomas Sileo Date: Sun, 8 Sep 2019 16:57:00 +0200 Subject: [PATCH] Add new startup script --- run.sh | 1 + startup.py | 12 ++++++++++++ utils/local_actor_cache.py | 17 +++++++++++++++++ 3 files changed, 30 insertions(+) create mode 100644 startup.py create mode 100644 utils/local_actor_cache.py diff --git a/run.sh b/run.sh index 11f11fb..9cb4fda 100755 --- a/run.sh +++ b/run.sh @@ -1,5 +1,6 @@ #!/bin/bash python -c "import logging; logging.basicConfig(level=logging.DEBUG); from core import migrations; migrations.perform()" python -c "from core import indexes; indexes.create_indexes()" +python startup.py (sleep 5 && curl -X POST -u :$POUSETACHES_AUTH_KEY $MICROBLOGPUB_POUSSETACHES_HOST/resume)& gunicorn -t 600 -w 5 -b 0.0.0.0:5005 --log-level debug app:app diff --git a/startup.py b/startup.py new file mode 100644 index 0000000..7ee7db0 --- /dev/null +++ b/startup.py @@ -0,0 +1,12 @@ +import app # noqa: F401 # here to init the backend +from core.activitypub import _actor_hash +from core.shared import MY_PERSON +from core.shared import p +from core.tasks import Tasks +from utils.local_actor_cache import is_actor_updated + +h = _actor_hash(MY_PERSON, local=True) +if is_actor_updated(h): + Tasks.send_actor_update() + +p.push({}, "/task/cleanup", schedule="@every 1h") diff --git a/utils/local_actor_cache.py b/utils/local_actor_cache.py new file mode 100644 index 0000000..c0c3e67 --- /dev/null +++ b/utils/local_actor_cache.py @@ -0,0 +1,17 @@ +from pathlib import Path + +_CACHE_FILE = Path(__file__).parent.absolute() / ".." / "config" / "local_actor_hash" + + +def is_actor_updated(actor_hash: str) -> bool: + actor_updated = False + if _CACHE_FILE.exists(): + current_hash = _CACHE_FILE.read_text() + if actor_hash != current_hash: + actor_updated = True + + if actor_updated: + with _CACHE_FILE.open("w") as f: + f.write(actor_hash) + + return actor_updated