Spaces:
Paused
Paused
Download nexus_worker.py from TeamError404/nexus: direct link, hf CLI and curl.
- Browser
- Download file 3.05 kB
-
https://huggingface.co/spaces/TeamError404/nexus/resolve/main/nexus_worker.py
- Command line
-
hf download hf://spaces/TeamError404/nexus/nexus_worker.py
-
curl -L -o nexus_worker.py https://huggingface.co/spaces/TeamError404/nexus/resolve/main/nexus_worker.py
3.05 kB
| """ | |
| Arq Worker configuration and runner. | |
| Run this script to process background tasks: `arq worker.py` | |
| """ | |
| import asyncio | |
| import os | |
| from arq import cron | |
| from arq.connections import RedisSettings | |
| from core.config import get_settings | |
| from core.tasks import ( | |
| monitor_sla_thresholds, | |
| execute_remediation_hook, | |
| generate_ticket_embedding, | |
| notify_mentions, | |
| auto_summarize_ticket, | |
| index_kb_article, | |
| record_system_heartbeat, | |
| vectorize_nexus_interaction, | |
| generate_global_insight, | |
| crystallize_memory, | |
| nexus_pulse_check, | |
| send_triple_notification, | |
| purge_stale_semantic_cache | |
| ) | |
| from agents.workflow import run_ai_workflow | |
| settings = get_settings() | |
| from core.logging import setup_logging | |
| async def startup(ctx): | |
| """Worker startup hook.""" | |
| setup_logging() | |
| print("!!! ARQ-WORKER BOOTSTRAPPING: [V_734] !!!") | |
| print(f"Arq Worker starting on {settings.REDIS_URL}...") | |
| # Initialize connection pools if needed | |
| async def shutdown(ctx): | |
| """Worker shutdown hook.""" | |
| print("Arq Worker shutting down...") | |
| from urllib.parse import urlparse | |
| class WorkerSettings: | |
| # --- REDIS CONFIGURATION (Standard DSN + Cloud Optimization) --- | |
| from core.config import get_redis_settings | |
| redis_settings = get_redis_settings() | |
| # ---------------------------------------------------------------- | |
| # Priority Management: Unified worker listening to both queues | |
| # Using 'queues' list instead of 'queue_name' to support multiple channels | |
| queues = ["arq:queue", "arq:critical"] | |
| # List of functions to register for background execution | |
| functions = [ | |
| monitor_sla_thresholds, | |
| execute_remediation_hook, | |
| generate_ticket_embedding, | |
| run_ai_workflow, | |
| notify_mentions, | |
| auto_summarize_ticket, | |
| index_kb_article, | |
| record_system_heartbeat, | |
| vectorize_nexus_interaction, | |
| generate_global_insight, | |
| crystallize_memory, | |
| nexus_pulse_check, | |
| send_triple_notification, | |
| purge_stale_semantic_cache | |
| ] | |
| # Concurrency / Performance | |
| max_jobs = 10 | |
| job_timeout = 600 # 10 minutes max for complex AI tasks | |
| poll_delay = 30 # TUNED: Reduced to 5s for near real-time AI responsiveness | |
| keep_result = 600 # Clear job results from Redis after 10 minutes | |
| # Retry Policy - Durable Backoff for AI/LLM 429 Errors | |
| max_retries = 5 | |
| retry_delay_seconds = 10 | |
| # Periodic tasks (SLA Monitoring & Heartbeat) | |
| # Optimized for low-cost cloud Redis | |
| cron_jobs = [ | |
| cron(monitor_sla_thresholds, minute={0, 20, 40}), # Every 10 minutes (Improved resolution) | |
| cron(record_system_heartbeat, hour={0, 12}, minute=0), # Twice a day | |
| cron(generate_global_insight, hour=3, minute=0), # Once a day at 3 AM | |
| cron(nexus_pulse_check, minute=set(range(0, 60, 15))), # Every 15 minutes | |
| cron(purge_stale_semantic_cache, hour={0, 6, 12, 18}, minute=0) # Every 6 hours | |
| ] | |
| on_startup = startup | |
| on_shutdown = shutdown | |