I’m trying to start simple crontab-django job scheduled (os is Ubuntu 20.04):
this is the myapp/cron.py file as mentioned in the documentation
cron.py
from .models import Cats
def my_scheduled_job():
Cats.objects.create(text='Testt')
and this is the settings i used frm the documentation
CRONJOBS = [
('*/1 * * * *', 'coins.cron.my_scheduled_job')
]
INSTALLED_APPS = (
'django_crontab',
...
)
i keep getting this error
Traceback (most recent call last):
File "manage.py", line 22, in <module>
main()
File "manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "/home/madahsm/python projects/corntab/lib/python3.8/site-packages/django/core/management/__init__.py", line 446, in execute_from_command_line
utility.execute()
File "/home/madahsm/python projects/corntab/lib/python3.8/site-packages/django/core/management/__init__.py", line 440, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/madahsm/python projects/corntab/lib/python3.8/site-packages/django/core/management/base.py", line 402, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/madahsm/python projects/corntab/lib/python3.8/site-packages/django/core/management/base.py", line 448, in execute
output = self.handle(*args, **options)
File "/home/madahsm/python projects/corntab/lib/python3.8/site-packages/django_crontab/management/commands/crontab.py", line 29, in handle
Crontab().run_job(options['jobhash'])
File "/home/madahsm/python projects/corntab/lib/python3.8/site-packages/django_crontab/crontab.py", line 126, in run_job
job = self.__get_job_by_hash(job_hash)
File "/home/madahsm/python projects/corntab/lib/python3.8/site-packages/django_crontab/crontab.py", line 171, in __get_job_by_hash
raise RuntimeError(
RuntimeError: No job with hash None found. It seems the crontab is out of sync with your settings.CRONJOBS. Run "python manage.py crontab add" again to resolve this issue!
even i tried to add python manage.py crontab add again and show and it appears
python manage.py crontab add
removing cronjob: (crontab) -> ('*/1 * * * *', 'coins.cron.my_scheduled_job')
adding cronjob: (75d02c7cc7be0475f399b3786aefe170) -> ('*/1 * * * *', 'coins.cron.my_scheduled_job')
python manage.py crontab show
crontab -> ('*/1 * * * *', 'coins.cron.my_scheduled_job')
its only work for one time if i run like this:
python manage.py crontab run 75d02c7cc7be0475f399b3786aefe170
2
Answers
It should already be added to your system crontab. Check it with
crontab -l
in the terminal.Edit:
It seems because you have a space in your directory name, try to rename
python projects
topython-projects
and rerun theadd
command.