Cron Job for Django Project not activating

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



Cron Job for Django Project not activating



I am trying to add a cronjob to my django project that will reset the scores of my game every 1 minutes.
I used cron tab and I think it’s my pathing/location of the function that is causing it to not trigger.
Here is the hierarchy of the files and a few files in each of them.


ProjectBackend—
ProjectBackend—
- settings.py
- wsgi.py
__init__.py
urls.py
manage.py
heroku
scores—
admin.py
cron.py
models.py
views.py
urls.py
apps.py



In the settings.py above, I have the following : I added only crontab to installed_apps and the cronjob array.


CRONJOBS = [
('*/1 * * * *', ’scores.cron.my_scheduled_job’)
]
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'scores.apps.ScoresConfig',
'django_crontab',
]



I have replaced the cronjob’s second parameter with ’ProjectBackend.scores.cron.my_scheduled_job’ and other variations with no luck. I chose ‘scores’ instead of 'scores.apps.ScoresConfig' because it is designed as the name in apps.py



I placed the function called my_scheduled_job in the cron.py in the above location.



Right now all the function does is print out a string, which does not show up on Terminal when I do the following in the directory where manage.py is located.


‘Python3 manage.py crontab add’
‘Python3 manage.py crontab show’



To which it says : Currently active jobs in crontab: ('*/1 * * * *', ‘scores.cron.my_scheduled_job')
After this, I do python3 manage.py runserver and nothing happens.



https://pypi.org/project/django-crontab/ I followed this. Do I have everything set up correctly?





I would recommend to use a Django Command docs.djangoproject.com/en/2.1/howto/custom-management-commands and then creating a cronjob by editing the crontab list crontab -e and adding your own timing...
– eddwinpaz
Aug 13 at 0:55





@eddwinpaz What would our equivalent be to placing it in the management/commands folder? Do we put management inside of scores?
– Robert Pelican
Aug 13 at 1:00





please check this.. it might help you. coderwall.com/p/k5p6ag/run-django-commands-using-cron
– eddwinpaz
Aug 14 at 14:04




2 Answers
2



django_cronjob runs with crontab not with run server command



you can also use your manage command and write your code to that command and add it to crontab manually or when a function called with python code.



It looks like , there is something wrong with configuration of cronjob. You can visit this link given below:
http://django-cron.readthedocs.io/en/latest/sample_cron_configurations.html



You can also visit this link for more description about crontab
https://kite.com/python/docs/celery.task.schedules.crontab






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

make 2 or more post in bootsrap

Store custom data using WC_Cart add_to_cart() method in Woocommerce 3

Firebase Auth - with Email and Password - Check user already registered