diff --git a/backend/backend/settings.py b/backend/backend/settings.py index 4bb6b4d..0e6c72a 100644 --- a/backend/backend/settings.py +++ b/backend/backend/settings.py @@ -247,7 +247,7 @@ CELERY_BEAT_SCHEDULE = { 'delete_not_active_users': { 'task': 'users.tasks.delete_not_active_users', - 'schedule': crontab(minute='*/2'), + 'schedule': crontab(hour='*/24'), }, } diff --git a/backend/users/tasks.py b/backend/users/tasks.py index b741b1d..a47375c 100644 --- a/backend/users/tasks.py +++ b/backend/users/tasks.py @@ -1,5 +1,6 @@ from django.contrib.auth import get_user_model from django.db import transaction +from django.utils import timezone from backend import celery_app @@ -8,5 +9,9 @@ @celery_app.task def delete_not_active_users(): + tomorrow = timezone.now() - timezone.timedelta(days=1) with transaction.atomic(): - User.objects.filter(is_active=False).delete() + User.objects.filter( + is_active=False, + date_joined__lt=tomorrow, + ).exclude(role=User.DELETED).delete() diff --git a/infra_bt/docker-compose.production.yml b/infra_bt/docker-compose.production.yml index bf5ce2b..4712646 100644 --- a/infra_bt/docker-compose.production.yml +++ b/infra_bt/docker-compose.production.yml @@ -23,6 +23,18 @@ services: timeout: 3s retries: 5 + redis: + image: redis:alpine3.18 + hostname: redis + ports: + - "6379:6379" + restart: unless-stopped + healthcheck: + test: ["CMD", "redis-cli", "ping"] + interval: 5s + timeout: 3s + retries: 5 + backend: image: 1yunker/volunteers_backend env_file: .env @@ -33,6 +45,34 @@ services: db: condition: service_healthy + celery: + image: 1yunker/volunteers_backend + env_file: .env + volumes: + - static_data:/backend_static + - media_data:/app/media + command: celery -A backend.celery_app worker -l info + restart: unless-stopped + depends_on: + backend: + condition: service_started + redis: + condition: service_healthy + + celery-beat: + image: 1yunker/volunteers_backend + env_file: .env + volumes: + - static_data:/backend_static + - media_data:/app/media + command: celery -A backend beat -l info + restart: unless-stopped + depends_on: + backend: + condition: service_started + redis: + condition: service_healthy + frontend: image: 1yunker/volunteers_frontend command: cp -r /app/. /static_files/