Skip to content

Commit

Permalink
Merge pull request #74 from dev-lymar/feat/dev-adding-automatic-docum…
Browse files Browse the repository at this point in the history
…ent-cleaning

Feat/dev adding automatic document cleaning
  • Loading branch information
dev-lymar committed Jun 28, 2024
2 parents 054db5b + 2ded2f5 commit 70135c2
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 1 deletion.
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),
},
}

0 comments on commit 70135c2

Please sign in to comment.