Fix worker control fallback for running detect workers
This commit is contained in:
@@ -940,6 +940,10 @@ class DetectWorker:
|
||||
|
||||
def _runtime_heartbeat_loop(self):
|
||||
while not self._runtime_heartbeat_stop.wait(self.runtime_heartbeat_interval):
|
||||
try:
|
||||
self._consume_pending_control_command()
|
||||
except Exception as e:
|
||||
logger.debug(f"运行态心跳补偿消费待执行控制指令失败: {e}")
|
||||
try:
|
||||
self._update_runtime_state(
|
||||
self._last_runtime_phase,
|
||||
@@ -1157,11 +1161,29 @@ class DetectWorker:
|
||||
)
|
||||
return True
|
||||
|
||||
def _acknowledge_pending_control_command(self, control_payload):
|
||||
if not self.use_redis or self.redis_client is None:
|
||||
return
|
||||
request_id = str((control_payload or {}).get("request_id", "")).strip()
|
||||
if not request_id:
|
||||
return
|
||||
try:
|
||||
raw_pending = self.redis_client.get(PENDING_CONTROL_KEY)
|
||||
if not raw_pending:
|
||||
return
|
||||
pending_payload = json.loads(raw_pending)
|
||||
pending_request_id = str((pending_payload or {}).get("request_id", "")).strip()
|
||||
if pending_request_id and pending_request_id == request_id:
|
||||
self.redis_client.delete(PENDING_CONTROL_KEY)
|
||||
except Exception as e:
|
||||
logger.debug(f"确认待执行控制指令失败: {e}")
|
||||
|
||||
def _handle_control_message(self, payload):
|
||||
try:
|
||||
control_payload = json.loads(payload) if isinstance(payload, str) else payload
|
||||
except Exception:
|
||||
control_payload = {"action": str(payload)}
|
||||
self._acknowledge_pending_control_command(control_payload)
|
||||
action = str(control_payload.get("action", "")).strip()
|
||||
if action == "start_detection":
|
||||
self.start_detection_async(source="redis-control", control_payload=control_payload)
|
||||
|
||||
Reference in New Issue
Block a user