I am using Django Cron package in a docker container where I specify my cron functions like this:
class CreateSnapshots(CronJobBase):
RUN_EVERY_MINS = 15 # every 15 mins
schedule = Schedule(run_every_mins=RUN_EVERY_MINS)
code = 'crontab.cronjobs.CreateSnapshots'
def do(self):
print("Running CreateSnapshots now..")
In my docker-entrypoint.sh for Kubernetes, I specify this:
python manage.py runcrons
The cronjob doesn't run every 15 minutes as instructed but when I do python manage.py runcrons
in the bash of container, the cronjob runs immediately. Any idea why is it not running every 15 minutes as specified? or a piece of configuration I am missing?
I have specified this in my settings.py:
CRON_CLASSES = [
"crontab.cronjobs.CreateSnapshots",
]
My Kubernetes Deployment Spec:
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
annotations:
kompose.cmd: kompose convert -f docker-compose.yml
kompose.version: 1.14.0 (fa706f2)
creationTimestamp: null
labels:
io.kompose.service: cronjobs
name: cronjobs
spec:
replicas: 1
strategy:
type: Recreate
template:
metadata:
creationTimestamp: null
labels:
io.kompose.service: cronjobs
spec:
imagePullSecrets:
- name: mycompregcred
containers:
- args:
- python
- manage.py
- runserver
- 0.0.0.0:8003
image: eu.gcr.io/my-project-123/cronjobs
name: cronjobs
ports:
- containerPort: 8003
resources: {}
volumeMounts:
- mountPath: /cronjobs
name: cronjobs-claim0
- mountPath: /cronjobs/common
name: cronjobs-claim1
restartPolicy: Always
volumes:
- name: cronjobs-claim0
persistentVolumeClaim:
claimName: cronjobs-claim0
- name: cronjobs-claim1
persistentVolumeClaim:
claimName: cronjobs-claim1
status: {}
And my docker-compose.yaml's cronjob app part:
cronjobs:
image: cronjobs
build: ./cronjobs
depends_on:
- db
My full docker-entrypoint.sh looks like this:
#!/bin/sh
wait-for-it db:5432
python manage.py collectstatic --no-input
python manage.py migrate django_cron
python manage.py runcrons
gunicorn cronjobs.wsgi -b 0.0.0.0:8000