Refactor fleet module and add cleanup script
- Update Celery configuration in celery.py - Modify base settings for improved performance - Enhance task management in fleet tasks.py - Revise fleet views.py for better data handling - Add cleanup_tmp_archives.sh script for temporary file management - Adjust docker-compose.prod.yml for consistency - Optimize fleetDashboardStore.js with reduced code complexity
This commit is contained in:
@@ -2,11 +2,33 @@
|
||||
|
||||
import os
|
||||
from celery import Celery
|
||||
from celery import Task
|
||||
import gc
|
||||
import logging
|
||||
|
||||
# Postavi Django settings modul
|
||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'core.settings')
|
||||
|
||||
app = Celery('core')
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class ResourceAwareTask(Task):
|
||||
"""Celery base task s hookovima za memory-heavy async operacije."""
|
||||
|
||||
abstract = True
|
||||
|
||||
def on_success(self, retval, task_id, args, kwargs):
|
||||
logger.info("Celery task uspješan: %s (%s)", self.name, task_id)
|
||||
super().on_success(retval, task_id, args, kwargs)
|
||||
|
||||
def on_failure(self, exc, task_id, args, kwargs, einfo):
|
||||
logger.exception("Celery task neuspješan: %s (%s): %s", self.name, task_id, exc)
|
||||
super().on_failure(exc, task_id, args, kwargs, einfo)
|
||||
|
||||
def after_return(self, status, retval, task_id, args, kwargs, einfo):
|
||||
gc.collect()
|
||||
super().after_return(status, retval, task_id, args, kwargs, einfo)
|
||||
|
||||
# Koristi konfiguraciju iz settings.py s prefiksom 'CELERY_'
|
||||
app.config_from_object('django.conf:settings', namespace='CELERY')
|
||||
|
||||
@@ -154,6 +154,10 @@ REDIS_URL = os.environ.get('REDIS_URL', 'redis://localhost:6379/0')
|
||||
|
||||
CELERY_BROKER_URL = REDIS_URL
|
||||
CELERY_RESULT_BACKEND = REDIS_URL
|
||||
CELERY_WORKER_PREFETCH_MULTIPLIER = 1
|
||||
CELERY_TASK_ACKS_LATE = True
|
||||
CELERY_WORKER_MAX_TASKS_PER_CHILD = 20
|
||||
CELERY_WORKER_MAX_MEMORY_PER_CHILD = 300000
|
||||
|
||||
# Ako želiš koristiti Redis kao brzi cache sustav unutar Djanga (izvrsno za ERP performanse)
|
||||
# Za ovo ti je potreban paket 'django-redis' u requirements.txt
|
||||
@@ -175,6 +179,14 @@ CELERY_BEAT_SCHEDULE = {
|
||||
'task': 'modules.fleet.tasks.cleanup_expired_generated_pdfs_task',
|
||||
'schedule': crontab(minute=0),
|
||||
},
|
||||
'cleanup-expired-generated-archives-hourly': {
|
||||
'task': 'modules.fleet.tasks.cleanup_expired_generated_archives_task',
|
||||
'schedule': crontab(minute=10),
|
||||
},
|
||||
'cleanup-stale-tmp-archives-daily': {
|
||||
'task': 'modules.fleet.tasks.cleanup_stale_tmp_archives_task',
|
||||
'schedule': crontab(hour=3, minute=30),
|
||||
},
|
||||
'notify-upcoming-tasks-daily': {
|
||||
'task': 'modules.task_management.tasks.notify_upcoming_tasks',
|
||||
'schedule': crontab(hour=8, minute=0),
|
||||
|
||||
Reference in New Issue
Block a user