0

I work on a django project, which needs celery for running some tasks in the background. I also need to run some cron-jobs, so I installed django-crontab into the container, added to the INSTALLED_APPS in settings.py, "python manage.py crontab show" OUTPUT:

root@865809c7149e:/apps# python manage.py crontab show
Currently active jobs in crontab: ab590d03e928be09c5fc1a0048404548 -> ('*/3 * * * *', 'AppName.cron.cron_job_method', '>> /apps/crontab.log')

SADLY no crontab.log file appears... I don't understand why...

AND:

celery container exits on "docker compose up" with:

... celery-1 | ModuleNotFoundError: No module named 'django_crontab' celery-1 exited with code 1 web-1 | Watching for file changes with StatReloader

Here my docker-compose.yml

services:
db:
    image: postgres:17
    env_file: .env
    volumes:
        - ./local-db:/var/lib/postgresql/data

redis:
    image: redis:7

web:
    build: .
    command: python manage.py runserver 0:8030
    ports:
        - 8030:8030
    volumes:
        - ./projectDIR:/apps
    env_file: .env
    links:
        - db
    depends_on:
        - db
        - redis

celery:
    build: .
    command: celery -A projectDIR worker -l INFO
    env_file: .env
    volumes:
        - ./projectDIR:/apps
    environment:
        redis_url: redis://redis:6379/0
    links:
        - db
        - redis
        - web
    depends_on:
        - web
        - redis

ANY HELP IS VERY APPRECIATED!

Dockerfile:

FROM python:3.12
COPY requirements.txt requirements.txt
RUN pip install --upgrade pip
RUN pip install -r requirements.txt
RUN apt-get update
RUN apt-get install -y cron
RUN mkdir /apps
WORKDIR /apps
COPY projectDIR .

requirements.txt

Django==5.1.3
djangorestframework==3.15.2
django-debug-toolbar==4.4.6
django-crontab==0.7.1
psycopg==3.2.3
pandas==2.2.3
pillow==11.0.0
openpyxl==3.1.5
celery==5.4.0
celery-progress==0.4
django-celery-results==2.5.1
redis==5.2.0
4
  • Can you show the Dockerfile; what bit installs django-crontab? You should delete the obsolete links: blocks in the Compose file, and the volumes: that overwrite the entire image /apps directory can lead to unexpected results. Commented Jan 25 at 11:00
  • Please edit the question to include these details; don't try to paste code into comments. It'd also help to verify that some version of django-crontab is in fact in the requirements.txt file. Commented Jan 25 at 11:43
  • django-crontab is in in the requirements.txt Commented Jan 25 at 11:46
  • django-crontab was later added to the project (also reqs), and I have rebuilt the container. Commented Jan 25 at 11:53

1 Answer 1

0

So after hours of desperation I finally came to a solution (in case somebody has similar issues...):

  1. I commented out all lines of code referring to crontab (#) in django settings.py module to avoid the error...
  2. then i ran docker (to be able to exec bash):

$ docker compose up

  1. so I could bring up the terminal of celery container

$ docker compose exec celery bash

  1. where I simply executed a pip install:

$ pip install django-crontab

  1. Finally - after a cheap Ctrl+C - I restarted the container (step.2)

And Voila, NO ERRORS!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.