[WEB-1206] chore: bulk delete api logs (#4374)

* chore: bulk delete api logs

* chore: deletion time change
This commit is contained in:
Bavisetti Narayan 2024-05-06 15:19:03 +05:30 committed by GitHub
parent f1fda4ae4a
commit 653005bb3b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 20 additions and 0 deletions

View File

@ -0,0 +1,15 @@
from django.utils import timezone
from datetime import timedelta
from plane.db.models import APIActivityLog
from celery import shared_task
@shared_task
def delete_api_logs():
# Get the logs older than 30 days to delete
logs_to_delete = APIActivityLog.objects.filter(
created_at__lte=timezone.now() - timedelta(days=30)
)
# Delete the logs
logs_to_delete._raw_delete(logs_to_delete.db)

View File

@ -32,6 +32,10 @@ app.conf.beat_schedule = {
"task": "plane.bgtasks.email_notification_task.stack_email_notification", "task": "plane.bgtasks.email_notification_task.stack_email_notification",
"schedule": crontab(minute="*/5"), "schedule": crontab(minute="*/5"),
}, },
"check-every-day-to-delete-api-logs": {
"task": "plane.bgtasks.api_logs_task.delete_api_logs",
"schedule": crontab(hour=0, minute=0),
},
} }
# Load task modules from all registered Django app configs. # Load task modules from all registered Django app configs.

View File

@ -293,6 +293,7 @@ CELERY_IMPORTS = (
"plane.bgtasks.exporter_expired_task", "plane.bgtasks.exporter_expired_task",
"plane.bgtasks.file_asset_task", "plane.bgtasks.file_asset_task",
"plane.bgtasks.email_notification_task", "plane.bgtasks.email_notification_task",
"plane.bgtasks.api_logs_task",
# management tasks # management tasks
"plane.bgtasks.dummy_data_task", "plane.bgtasks.dummy_data_task",
) )