add timeout mcp poll
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import time
|
||||
from collections.abc import Iterable
|
||||
|
||||
from .graylog_mcp import GraylogMcpClient
|
||||
@@ -68,7 +69,7 @@ class GraylogStreamSource:
|
||||
if not isinstance(self.mapping, dict):
|
||||
raise RuntimeError("invalid_graylog_field_mapping")
|
||||
|
||||
def fetch(self, *, max_events: int = 5_000, range_seconds: int = 300, probe_status: dict[str, object] | None = None) -> tuple[list[LogEvent], dict[str, object]]:
|
||||
def fetch(self, *, max_events: int = 5_000, range_seconds: int = 300, probe_status: dict[str, object] | None = None, deadline_monotonic: float | None = None) -> tuple[list[LogEvent], dict[str, object]]:
|
||||
if probe_status is not None:
|
||||
status = dict(probe_status)
|
||||
else:
|
||||
@@ -98,6 +99,9 @@ class GraylogStreamSource:
|
||||
pages = 0
|
||||
partial_error = ""
|
||||
while len(events) < max_events:
|
||||
if deadline_monotonic is not None and time.monotonic() >= deadline_monotonic:
|
||||
partial_error = "poll_budget_exceeded"
|
||||
break
|
||||
request_limit = min(page_size, max_events - len(events))
|
||||
try:
|
||||
result = self.client.call_tool("search_messages", {**arguments, "limit": request_limit, "offset": len(events)})
|
||||
|
||||
Reference in New Issue
Block a user