Last active
October 26, 2020 11:45
-
-
Save vivekrk1992/92f13b5f85a675cd563821f3c4cf0a61 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
reference url | |
""" | |
https://pypi.org/project/django-crontab/ | |
""" | |
install cron tab for django | |
""" | |
pip install django-crontab | |
""" | |
add it to installed apps in django settings.py: | |
""" | |
INSTALLED_APPS = ( | |
'django_crontab', | |
... | |
) | |
""" | |
create one script with any file app_name.cron.py | |
""" | |
def hi(): | |
print('iam an cron job') | |
f = open('/home/host_name/django_cron.txt', 'w') | |
f.close() | |
""" | |
now add this to your settings.py: | |
""" | |
CRONJOBS = [ | |
('*/5 * * * *', 'app_name.cron.hi') | |
] | |
""" | |
we can pass the argument also | |
""" | |
CRONJOBS = [ | |
('*/5 * * * *', 'myapp.cron.other_scheduled_job', ['arg1', 'arg2'], {'verbose': 0}), | |
('0 4 * * *', 'django.core.management.call_command', ['clearsessions']), | |
] | |
""" | |
we created cronjabs script and then add when to execute the script in setting.py also | |
now we add the cronjob to initiate to run this command | |
""" | |
python manage.py crontab add | |
""" | |
we want to see initiated cronjobs execute this command | |
""" | |
python manage.py crontab show | |
""" | |
we want to remove initiated cronjob excute this command | |
""" | |
python manage.py crontab remove | |
""" | |
now we check the home folder the 'django_cron.txt' file exist | |
enjoy -) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
1 2 3 4 5