Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/dev adding automatic document cleaning #74

Merged
merged 4 commits into from
Jun 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,21 @@ services:
networks:
- melnichanka

beat:
build: .
command: celery -A melnichanka beat -l info
restart: on-failure
env_file:
- .env
volumes:
- .:/app
- ./makedoc/tempdoc:/app/makedoc/tempdoc
depends_on:
- db
- rabbitmq
networks:
- melnichanka

redis:
image: redis:7.2.5-alpine
hostname: redis
Expand Down
22 changes: 22 additions & 0 deletions makedoc/tasks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import os
import shutil

from celery import shared_task
from django.conf import settings


@shared_task
def delete_files():
directory = settings.BASE_DIR / "makedoc" / "tempdoc"

if not os.path.exists(directory):
return "Directory does not exist"
for item in os.listdir(directory):
item_path = os.path.join(directory, item)
try:
if os.path.isdir(item_path):
shutil.rmtree(item_path)
except Exception as e:
return f"Failed to delete {item_path}. Reason {e}"

return "Successfully deleted all user folders"
12 changes: 11 additions & 1 deletion melnichanka/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from datetime import timedelta
from pathlib import Path

from celery.schedules import crontab
from dotenv import load_dotenv

load_dotenv()
Expand Down Expand Up @@ -190,7 +191,7 @@
}

SIMPLE_JWT = {
"ACCESS_TOKEN_LIFETIME": timedelta(minutes=30),
"ACCESS_TOKEN_LIFETIME": timedelta(minutes=60),
"REFRESH_TOKEN_LIFETIME": timedelta(days=10),
"ROTATE_REFRESH_TOKENS": True,
"BLACKLIST_AFTER_ROTATION": True,
Expand All @@ -215,3 +216,12 @@
"VERSION": "1.0.0",
"SERVE_INCLUDE_SCHEMA": False,
}

# Celery

CELERY_BEAT_SCHEDULE = {
"delete_files_daily": {
"task": "makedoc.tasks.delete_files",
"schedule": crontab(hour=23, minute=59),
},
}
Loading