From 3207f7de8bde8223ac773a6c7e89ad50b935a22a Mon Sep 17 00:00:00 2001 From: glic3 Date: Mon, 4 May 2015 15:02:23 +0200 Subject: [PATCH] Added setupcronbeat command --- .../management/commands/setupcronbeat.py | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 orchestra/contrib/tasks/management/commands/setupcronbeat.py diff --git a/orchestra/contrib/tasks/management/commands/setupcronbeat.py b/orchestra/contrib/tasks/management/commands/setupcronbeat.py new file mode 100644 index 00000000..d4857870 --- /dev/null +++ b/orchestra/contrib/tasks/management/commands/setupcronbeat.py @@ -0,0 +1,25 @@ +import os + +from django.core.management.base import BaseCommand, CommandError + +from orchestra.utils.paths import get_site_dir +from orchestra.utils.sys import run + + +class Command(BaseCommand): + help = 'Runs periodic tasks.' + + def handle(self, *args, **options): + context = { + 'site_dir': get_site_dir(), + 'orchestra_beat': run('which orchestra-beat').stdout.decode('utf8'), + 'venv': os.environ.get('VIRTUAL_ENV', ''), + } + content = run('crontab -l').stdout.decode('utf8') + if 'orchestra-beat' not in content: + if context['venv']: + content += "* * * * * . %(venv)s/bin/activate && %(orchestra_beat)s %(site_dir)s/manage.py; deactivate" % context + else: + content += "* * * * * %(orchestra_beat)s %(site_dir)s/manage.py" % context + context['content'] = content + run("echo '%(content)s' | crontab" % context, display=True)