ISO-27001-Risk-Management/.venv/lib/python3.11/site-packages/django_crontab/management/commands/crontab.py
2025-09-24 18:13:40 +02:00

31 lines
1.1 KiB
Python

from __future__ import print_function
from django.core.management.base import BaseCommand
from django_crontab.crontab import Crontab
class Command(BaseCommand):
help = 'run this command to add, show or remove the jobs defined in CRONJOBS setting from/to crontab'
def add_arguments(self, parser):
parser.add_argument('subcommand', choices=['add', 'show', 'remove', 'run'])
parser.add_argument('jobhash', nargs='?')
def handle(self, *args, **options):
"""
Dispatches by given subcommand
"""
if options['subcommand'] == 'add':
with Crontab(**options) as crontab:
crontab.remove_jobs()
crontab.add_jobs()
elif options['subcommand'] == 'show':
with Crontab(readonly=True, **options) as crontab:
crontab.show_jobs()
elif options['subcommand'] == 'remove':
with Crontab(**options) as crontab:
crontab.remove_jobs()
elif options['subcommand'] == 'run':
Crontab().run_job(options['jobhash'])
else:
print(self.help)