phase 17: wire extractor→aggregation→recommendation queue chain, add company_id_map to extractor
This commit is contained in:
@@ -6,11 +6,16 @@ import json
|
||||
import logging
|
||||
|
||||
import asyncpg
|
||||
import redis.asyncio as aioredis
|
||||
|
||||
from services.aggregation.worker import aggregate_company
|
||||
from services.shared.config import load_config
|
||||
from services.shared.logging import setup_logging
|
||||
from services.shared.redis_keys import QUEUE_AGGREGATION, queue_key
|
||||
from services.shared.logging import inject_trace_context, setup_logging
|
||||
from services.shared.redis_keys import (
|
||||
QUEUE_AGGREGATION,
|
||||
QUEUE_RECOMMENDATION,
|
||||
queue_key,
|
||||
)
|
||||
|
||||
logger = logging.getLogger("aggregation_main")
|
||||
|
||||
@@ -20,11 +25,9 @@ async def main() -> None:
|
||||
setup_logging("aggregation", level=config.log_level, json_output=config.json_logs)
|
||||
|
||||
pool = await asyncpg.create_pool(dsn=config.postgres.dsn, min_size=2, max_size=8)
|
||||
|
||||
import redis.asyncio as aioredis
|
||||
|
||||
redis_client = aioredis.from_url(config.redis.url)
|
||||
queue = queue_key(QUEUE_AGGREGATION)
|
||||
rec_queue = queue_key(QUEUE_RECOMMENDATION)
|
||||
logger.info("Aggregation worker started, polling %s", queue)
|
||||
|
||||
try:
|
||||
@@ -34,8 +37,7 @@ async def main() -> None:
|
||||
await asyncio.sleep(1)
|
||||
continue
|
||||
|
||||
payload = raw
|
||||
job = json.loads(payload)
|
||||
job = json.loads(raw)
|
||||
ticker = job.get("ticker", "")
|
||||
|
||||
logger.info("Processing aggregation job for %s", ticker)
|
||||
@@ -46,6 +48,17 @@ async def main() -> None:
|
||||
"Aggregation complete for %s: %d windows",
|
||||
ticker, len(summaries),
|
||||
)
|
||||
|
||||
# Enqueue recommendation job for each window that produced a trend
|
||||
for summary in summaries:
|
||||
if summary.trend_strength > 0:
|
||||
await redis_client.rpush(
|
||||
rec_queue,
|
||||
json.dumps(inject_trace_context({
|
||||
"ticker": ticker,
|
||||
"window": summary.window.value,
|
||||
})),
|
||||
)
|
||||
except Exception:
|
||||
logger.exception("Aggregation failed for %s", ticker)
|
||||
finally:
|
||||
|
||||
Reference in New Issue
Block a user