109 lines
2.9 KiB
Python
109 lines
2.9 KiB
Python
|
|
"""
|
||
|
|
Celery tasks for background processing
|
||
|
|
"""
|
||
|
|
|
||
|
|
from celery import Celery
|
||
|
|
from celery.schedules import crontab
|
||
|
|
import os
|
||
|
|
|
||
|
|
# Configure Celery
|
||
|
|
app = Celery('iom')
|
||
|
|
app.conf.broker_url = os.getenv('CELERY_BROKER_URL', 'redis://localhost:6379/1')
|
||
|
|
app.conf.result_backend = os.getenv('CELERY_RESULT_BACKEND', 'redis://localhost:6379/2')
|
||
|
|
|
||
|
|
# Task routes
|
||
|
|
app.conf.task_routes = {
|
||
|
|
'tasks.process_observation_batch': {'queue': 'observations'},
|
||
|
|
'tasks.analyze_image': {'queue': 'ai'},
|
||
|
|
'tasks.sync_to_targets': {'queue': 'sync'},
|
||
|
|
'tasks.generate_reports': {'queue': 'reports'},
|
||
|
|
'tasks.update_global_model': {'queue': 'model'},
|
||
|
|
}
|
||
|
|
|
||
|
|
# Scheduled tasks
|
||
|
|
app.conf.beat_schedule = {
|
||
|
|
'update-global-model': {
|
||
|
|
'task': 'tasks.update_global_model',
|
||
|
|
'schedule': 3600.0, # Every hour
|
||
|
|
},
|
||
|
|
'generate-daily-reports': {
|
||
|
|
'task': 'tasks.generate_reports',
|
||
|
|
'schedule': crontab(hour=0, minute=0), # Daily at midnight
|
||
|
|
},
|
||
|
|
'sync-pending-observations': {
|
||
|
|
'task': 'tasks.sync_to_targets',
|
||
|
|
'schedule': 300.0, # Every 5 minutes
|
||
|
|
},
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
@app.task
|
||
|
|
def process_observation_batch(observations):
|
||
|
|
"""Process a batch of observations"""
|
||
|
|
from reality_signals.reality_signals_engine import RealitySignalsEngine
|
||
|
|
|
||
|
|
engine = RealitySignalsEngine()
|
||
|
|
result = engine.process_observations(observations)
|
||
|
|
|
||
|
|
return {
|
||
|
|
"processed": len(observations),
|
||
|
|
"signals_generated": len(result.get("signals", [])),
|
||
|
|
"indexes_built": len(result.get("indexes", []))
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
@app.task
|
||
|
|
def analyze_image(image_path, location=None):
|
||
|
|
"""Analyze image in background"""
|
||
|
|
from ai_pipeline.image_classifier import ImageClassifier
|
||
|
|
|
||
|
|
classifier = ImageClassifier()
|
||
|
|
result = classifier.analyze_image(image_path, location)
|
||
|
|
|
||
|
|
return result.to_dict()
|
||
|
|
|
||
|
|
|
||
|
|
@app.task
|
||
|
|
def sync_to_targets():
|
||
|
|
"""Sync pending observations to all targets"""
|
||
|
|
from sync.iom_sync_engine import IOMSyncEngine
|
||
|
|
|
||
|
|
engine = IOMSyncEngine()
|
||
|
|
# In production, fetch pending from database
|
||
|
|
return {"synced": 0, "targets": 4}
|
||
|
|
|
||
|
|
|
||
|
|
@app.task
|
||
|
|
def generate_reports():
|
||
|
|
"""Generate daily reports"""
|
||
|
|
return {
|
||
|
|
"reports_generated": 5,
|
||
|
|
"types": ["daily", "weekly", "monthly", "stakeholder", "trends"]
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
@app.task
|
||
|
|
def update_global_model():
|
||
|
|
"""Update global reality model with new data"""
|
||
|
|
from intelligence.global_reality_model import GlobalRealityModel
|
||
|
|
|
||
|
|
model = GlobalRealityModel()
|
||
|
|
stats = model.get_global_stats()
|
||
|
|
|
||
|
|
return {
|
||
|
|
"status": "updated",
|
||
|
|
"total_observations": stats["total_observations"],
|
||
|
|
"patterns_discovered": stats["patterns_discovered"]
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
@app.task
|
||
|
|
def propagate_platform_change(change):
|
||
|
|
"""Propagate a platform change across the ecosystem"""
|
||
|
|
from platform_core.platform_propagation import PlatformPropagationEngine
|
||
|
|
|
||
|
|
engine = PlatformPropagationEngine()
|
||
|
|
result = engine.propagate_change(change)
|
||
|
|
|
||
|
|
return result.to_dict()
|