services: update comfy agent, senpai md consumer, and swapper deps
This commit is contained in:
@@ -79,12 +79,24 @@ async def process_events(
|
||||
events_per_sec_count = 0
|
||||
time.monotonic()
|
||||
|
||||
feature_compute_interval = 1.0 / max(settings.features_pub_rate_hz, 1.0)
|
||||
next_feature_compute: dict[str, float] = {}
|
||||
next_signal_emit: dict[str, float] = {}
|
||||
signal_cooldown_sec = 1.0
|
||||
|
||||
batch_counter = 0
|
||||
while True:
|
||||
try:
|
||||
event = await consumer.queue.get()
|
||||
except asyncio.CancelledError:
|
||||
break
|
||||
|
||||
# Yield to event loop every N events so HTTP API stays responsive
|
||||
batch_counter += 1
|
||||
if batch_counter >= 5:
|
||||
batch_counter = 0
|
||||
await asyncio.sleep(0)
|
||||
|
||||
proc_start = time.monotonic()
|
||||
|
||||
try:
|
||||
@@ -110,15 +122,24 @@ async def process_events(
|
||||
else:
|
||||
symbol = None
|
||||
|
||||
# Compute features + publish (only for trade/quote events)
|
||||
# Compute features + publish with per-symbol throttling
|
||||
if symbol and settings.features_enabled:
|
||||
snapshot = make_feature_snapshot(state, symbol)
|
||||
await publisher.publish_features(snapshot)
|
||||
now_mono = time.monotonic()
|
||||
due = next_feature_compute.get(symbol, 0.0)
|
||||
if now_mono >= due:
|
||||
snapshot = make_feature_snapshot(state, symbol)
|
||||
# Cache for fast HTTP API responses
|
||||
api.cache_features(symbol, snapshot.features)
|
||||
await publisher.publish_features(snapshot)
|
||||
|
||||
# Check for trade signal
|
||||
sig = check_signal(snapshot.features, symbol)
|
||||
if sig:
|
||||
await publisher.publish_signal(sig)
|
||||
# Check for trade signal with cooldown to avoid flood
|
||||
sig = check_signal(snapshot.features, symbol)
|
||||
sig_due = next_signal_emit.get(symbol, 0.0)
|
||||
if sig and now_mono >= sig_due:
|
||||
await publisher.publish_signal(sig)
|
||||
next_signal_emit[symbol] = now_mono + signal_cooldown_sec
|
||||
|
||||
next_feature_compute[symbol] = now_mono + feature_compute_interval
|
||||
|
||||
# Processing latency metric
|
||||
proc_ms = (time.monotonic() - proc_start) * 1000
|
||||
|
||||
Reference in New Issue
Block a user