flower celery

This commit is contained in:
IGNY8 VPS (Salman)
2025-12-10 17:46:37 +00:00
parent 87d1392b4c
commit 6997702b12
8 changed files with 1096 additions and 0 deletions

View File

@@ -48,6 +48,16 @@ app.conf.beat_schedule = {
'task': 'igny8_core.purge_soft_deleted',
'schedule': crontab(hour=3, minute=15),
},
# Daily application package backup at midnight
'daily-app-package-backup': {
'task': 'backup.create_daily_app_package',
'schedule': crontab(hour=0, minute=0), # Daily at 00:00
},
# Weekly cleanup of old packages (every Monday at 1 AM)
'weekly-package-cleanup': {
'task': 'backup.cleanup_old_packages',
'schedule': crontab(hour=1, minute=0, day_of_week=1), # Monday at 01:00
},
}
@app.task(bind=True, ignore_result=True)

View File

@@ -0,0 +1,133 @@
"""
IGNY8 Daily Backup Task - Celery Scheduled Task
Creates daily application package backups at midnight
"""
from celery import shared_task
from celery.utils.log import get_task_logger
import subprocess
import os
from datetime import datetime
logger = get_task_logger(__name__)
@shared_task(name='backup.create_daily_app_package')
def create_daily_app_package():
"""
Daily scheduled task to create IGNY8 application package backup.
Runs at 00:00 UTC daily via Celery Beat.
This creates a portable package containing only source code,
excluding node_modules, .venv, dist, and other generated files.
Returns:
dict: Status information about the backup operation
"""
logger.info("🚀 Starting daily IGNY8 application package backup...")
script_path = "/data/app/igny8/scripts/package_app.sh"
try:
# Check if script exists
if not os.path.exists(script_path):
error_msg = f"Packaging script not found at {script_path}"
logger.error(f"{error_msg}")
return {
'success': False,
'error': error_msg,
'timestamp': datetime.now().isoformat()
}
# Execute packaging script
logger.info(f"📦 Executing packaging script: {script_path}")
result = subprocess.run(
['/bin/bash', script_path],
capture_output=True,
text=True,
timeout=300 # 5 minute timeout
)
if result.returncode == 0:
logger.info("✅ Daily application package created successfully!")
logger.info(f"Output: {result.stdout}")
return {
'success': True,
'message': 'Application package created successfully',
'output': result.stdout,
'timestamp': datetime.now().isoformat()
}
else:
error_msg = f"Packaging script failed with code {result.returncode}"
logger.error(f"{error_msg}")
logger.error(f"Error output: {result.stderr}")
return {
'success': False,
'error': error_msg,
'stderr': result.stderr,
'timestamp': datetime.now().isoformat()
}
except subprocess.TimeoutExpired:
error_msg = "Packaging script timed out after 5 minutes"
logger.error(f"⏱️ {error_msg}")
return {
'success': False,
'error': error_msg,
'timestamp': datetime.now().isoformat()
}
except Exception as e:
error_msg = f"Unexpected error during packaging: {str(e)}"
logger.error(f"💥 {error_msg}")
return {
'success': False,
'error': error_msg,
'timestamp': datetime.now().isoformat()
}
@shared_task(name='backup.cleanup_old_packages')
def cleanup_old_packages():
"""
Cleanup old package backups (older than 30 days).
Runs weekly.
Returns:
dict: Status information about cleanup operation
"""
logger.info("🧹 Starting cleanup of old application packages...")
backup_dir = "/data/backups/igny8"
try:
# Find and delete packages older than 30 days
result = subprocess.run(
['find', backup_dir, '-name', 'igny8-app-*.tar.gz', '-type', 'f', '-mtime', '+30', '-delete'],
capture_output=True,
text=True
)
# Also delete old checksum files
subprocess.run(
['find', backup_dir, '-name', 'igny8-app-*.sha256', '-type', 'f', '-mtime', '+30', '-delete'],
capture_output=True,
text=True
)
logger.info("✅ Old packages cleaned up successfully")
return {
'success': True,
'message': 'Old packages cleaned up (30+ days)',
'timestamp': datetime.now().isoformat()
}
except Exception as e:
error_msg = f"Error during cleanup: {str(e)}"
logger.error(f"{error_msg}")
return {
'success': False,
'error': error_msg,
'timestamp': datetime.now().isoformat()
}

View File

@@ -9,6 +9,7 @@ django-cors-headers
PyJWT>=2.8.0
requests>=2.31.0
celery>=5.3.0
flower>=2.0.0
beautifulsoup4>=4.12.0
psutil>=5.9.0
docker>=7.0.0