Skip to content

Commit

Permalink
Changed the filtering of users of the task and the schedule
Browse files Browse the repository at this point in the history
  • Loading branch information
ArtemKAF committed Nov 22, 2023
1 parent 48179de commit 9419f03
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 2 deletions.
2 changes: 1 addition & 1 deletion backend/backend/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
},
}

Expand Down
7 changes: 6 additions & 1 deletion backend/users/tasks.py
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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()
40 changes: 40 additions & 0 deletions infra_bt/docker-compose.production.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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/
Expand Down

0 comments on commit 9419f03

Please sign in to comment.