Tivix / django-cron

Write cron business logic as a Python class and let this app do the rest! It enables Django projects to schedule cron tasks, tracks their success / failures, manages contention (via a cache) etc. Basically takes care of all the boring work for you :-)
www.tivix.com
MIT License
900 stars 193 forks source link

Feature request : ./manage.py runcrons --loop #123

Closed pomarec closed 2 years ago

pomarec commented 7 years ago

This would run "runcrons" every minutes in foreground. The usecase is for docker containers.

gregschmit commented 5 years ago

So I presume you want a parameter in front of the --loop for every N minutes?

E.g: python manage.py runcrons --loop 2

vanyakosmos commented 5 years ago

You can create custom command and run it whenever you want:

> python manage.py cronloop &

app/management/commands/cronloop.py:

from time import sleep

from django.core.management import BaseCommand, call_command

class Command(BaseCommand):
    help = 'Run cronjobs in loop.'

    def add_arguments(self, parser):
        parser.add_argument(
            '-s',
            '--sleep',
            dest='sleep',
            type=int,
            help="Sleep interval in seconds.",
            default=5 * 60,
        )

    def handle(self, *args, **options):
        s = options['sleep']
        while True:
            try:
                call_command('runcrons')
                sleep(s)
            except KeyboardInterrupt:
                break

Also I found this solution to be much easier then setting up cron/crontab in docker container and manage env vars in cron job.

JedrzejMaluszczak commented 2 years ago

Resolved https://github.com/Tivix/django-cron/pull/180