Skip to content
Snippets Groups Projects
Commit 9f4c7ac2 authored by HeJ's avatar HeJ
Browse files

Docker: use housekeeping's integrated forever mode

parent dc001fcf
No related branches found
No related tags found
No related merge requests found
......@@ -99,12 +99,12 @@ if [ "$1" == "shell" -o "$1" == "createsuperuser" -o "$1" == "test" ]; then
fi
if [ "$1" == "housekeeping" ]; then
while true; do
date
interval="${HOUSEKEEPING_SLEEP_SECONDS:-300}"
if [ "$interval" -gt 0 ]; then
python3 $APP_HOME/manage.py housekeeping --forever --forever-delay="$interval"
else
python3 $APP_HOME/manage.py housekeeping
sleep "${HOUSEKEEPING_SLEEP_SECONDS:-300}"
echo
done
fi
fi
if [ "$1" == "build" ]; then
......
import time
from django.core.management.base import BaseCommand
from django.core.management.base import BaseCommand, CommandError
from django.utils import timezone
from ...models.messages import DirectMessage
......@@ -63,6 +63,12 @@ class Command(BaseCommand):
def handle(self, *args, **options):
# call _do_housekeeping repeatedly (unless --forever is not set)
forever = options.get('forever')
forever_delay = options.get('forever_delay', '0')
if forever:
if forever_delay <= 0:
raise CommandError('The --forever-delay value must a positive value (in seconds).')
print(f'Running housekeeping forever each {forever_delay}s:', end='\n\n')
while True:
if forever:
print(timezone.now().isoformat())
......@@ -72,7 +78,7 @@ class Command(BaseCommand):
if forever:
print() # empty line
try:
time.sleep(options.get('forever_delay'))
time.sleep(forever_delay)
except KeyboardInterrupt:
print('Aborted.')
break
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment