I have two Django applications that I’m running on Amazon Linux using Gunicorn. Each Django application has its own cron jobs defined in the settings.py file using django_crontab. However, I’m facing issues when trying to add cron jobs from both applications to the crontab.
Here is the structure of my applications:
Application 1
/path/to/app1/
├── manage.py
├── app1/
│ ├── settings.py
│ └── ...
Application 2
/path/to/app2/
├── manage.py
├── app2/
│ ├── settings.py
│ └── ...
In settings.py of each application, I have defined cron jobs like this:
# app1/settings.py
CRONJOBS = [
('*/10 * * * *', 'app1.cron.my_scheduled_task'),
]
# app2/settings.py
CRONJOBS = [
('*/15 * * * *', 'app2.cron.another_scheduled_task'),
]
When I try to add the cron jobs for each application using the following commands:
cd /path/to/app1
source /path/to/venv/bin/activate
python manage.py crontab add
cd /path/to/app2
source /path/to/venv/bin/activate
python manage.py crontab add
When i do the python manage.py crontab add
for the second application, i get an error
RuntimeError: No job with hash 65f37180992aa5435pidg617281f3e6 found. It seems the crontab is out of sync with your settings.CRONJOBS. Run "python manage.py crontab add" again to resolve this issue!
This hash ID corresponds to a job from the first application.
How do I add cron jobs from both applications to the crontab without them conflicting?
What I’ve Tried:
Ensuring that each application has its own virtual environment.
Running python manage.py crontab add
in each application’s directory.
Desired Outcome:
I want to be able to add cron jobs from both applications to the crontab without encountering hash ID conflicts.