Closed pomarec closed 2 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
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.
This would run "runcrons" every minutes in foreground. The usecase is for docker containers.