Spaces:
Paused
Paused
File size: 3,054 Bytes
5eb4857 b7980f7 1818cda bc1617c 5eb4857 25925c2 5eb4857 25925c2 5eb4857 cc4d4a7 91ebb5b cc4d4a7 5eb4857 b7980f7 5eb4857 b7980f7 1818cda bc1617c 5eb4857 b7980f7 be01d40 b7980f7 5eb4857 be01d40 b7980f7 bc1617c 5eb4857 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 | """
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
|