fix(douyu): 修复斗鱼链路 P0/P1 隐患并增强 P2 运维队列可观测性
This commit is contained in:
@@ -384,6 +384,7 @@ class ExecutionEventBatchWriter:
|
||||
self._flushing = False
|
||||
self._stop = False
|
||||
self._thread: threading.Thread | None = None
|
||||
self._failed_batches = 0
|
||||
|
||||
def start(self) -> None:
|
||||
with self._cond:
|
||||
@@ -401,6 +402,15 @@ class ExecutionEventBatchWriter:
|
||||
with self._cond:
|
||||
return self._thread is not None and self._thread.is_alive()
|
||||
|
||||
def status(self) -> dict[str, Any]:
|
||||
with self._cond:
|
||||
return {
|
||||
"running": self._thread is not None and self._thread.is_alive(),
|
||||
"pending": len(self._queue),
|
||||
"flushing": self._flushing,
|
||||
"failed_batches": self._failed_batches,
|
||||
}
|
||||
|
||||
def _drain_sync(self) -> bool:
|
||||
"""在后台线程未运行时按 FIFO 同步写完队列中剩余事件。"""
|
||||
with self._write_lock:
|
||||
@@ -486,7 +496,10 @@ class ExecutionEventBatchWriter:
|
||||
self._flushing = True
|
||||
try:
|
||||
with self._write_lock:
|
||||
append_execution_events(batch)
|
||||
ok = append_execution_events(batch)
|
||||
if not ok:
|
||||
with self._cond:
|
||||
self._failed_batches += 1
|
||||
finally:
|
||||
with self._cond:
|
||||
self._flushing = False
|
||||
|
||||
Reference in New Issue
Block a user