fix: dispatch detect start to mainland nodes
This commit is contained in:
@@ -8,7 +8,7 @@ from app.core.config import settings
|
||||
from app.services.debug_event_service import push_debug_event
|
||||
from app.services.sync_push_service import pull_detect_task_batch_now, push_runtime_projection_now
|
||||
from app.services.runtime_settings_service import get_runtime_settings
|
||||
from app.services.worker_control_service import _run_systemctl, normalize_systemctl_error, start_worker, stop_worker
|
||||
from app.services.worker_control_service import _run_systemctl, normalize_systemctl_error, send_worker_command, start_worker, stop_worker
|
||||
|
||||
|
||||
def _workspace_root() -> Path:
|
||||
@@ -134,8 +134,9 @@ def stop_sync_agent() -> tuple[bool, str]:
|
||||
return _run_systemd_action(service_name, "stop")
|
||||
|
||||
|
||||
def runtime_action(action: str) -> tuple[bool, str, dict]:
|
||||
def runtime_action(action: str, payload: dict | None = None) -> tuple[bool, str, dict]:
|
||||
normalized_action = str(action or "").strip().lower().replace("-", "_")
|
||||
normalized_payload = dict(payload or {})
|
||||
if normalized_action != "push_debug_probe":
|
||||
_emit_runtime_action_event(
|
||||
normalized_action,
|
||||
@@ -174,10 +175,42 @@ def runtime_action(action: str) -> tuple[bool, str, dict]:
|
||||
_emit_runtime_action_event(normalized_action, stage="finished", ok=ok, message=message, data=result)
|
||||
return ok, message, result
|
||||
if normalized_action == "pull_tasks":
|
||||
ok, message, data = pull_detect_task_batch_now()
|
||||
pull_limit = normalized_payload.get("limit")
|
||||
ok, message, data = pull_detect_task_batch_now(limit=int(pull_limit or 0) or None)
|
||||
result = _build_runtime_action_result(action=normalized_action, poll_after_seconds=2, refresh_runtime=True, ok=ok, message=message, data=data)
|
||||
_emit_runtime_action_event(normalized_action, stage="finished", ok=ok, message=message, data=result)
|
||||
return ok, message, result
|
||||
if normalized_action == "start_detection":
|
||||
command_ok, command_message = send_worker_command(
|
||||
"start_detection",
|
||||
payload={
|
||||
key: value
|
||||
for key, value in normalized_payload.items()
|
||||
if value not in (None, "")
|
||||
},
|
||||
)
|
||||
result = _build_runtime_action_result(
|
||||
action=normalized_action,
|
||||
poll_after_seconds=2,
|
||||
refresh_runtime=True,
|
||||
ok=command_ok,
|
||||
message=command_message,
|
||||
data={"payload": normalized_payload},
|
||||
)
|
||||
_emit_runtime_action_event(normalized_action, stage="finished", ok=command_ok, message=command_message, data=result)
|
||||
return command_ok, command_message, result
|
||||
if normalized_action == "stop_detection":
|
||||
command_ok, command_message = send_worker_command("stop_detection")
|
||||
result = _build_runtime_action_result(
|
||||
action=normalized_action,
|
||||
poll_after_seconds=2,
|
||||
refresh_runtime=True,
|
||||
ok=command_ok,
|
||||
message=command_message,
|
||||
data={},
|
||||
)
|
||||
_emit_runtime_action_event(normalized_action, stage="finished", ok=command_ok, message=command_message, data=result)
|
||||
return command_ok, command_message, result
|
||||
if normalized_action == "push_debug_probe":
|
||||
ok, message, data = push_debug_event(
|
||||
service="domain-api",
|
||||
|
||||
Reference in New Issue
Block a user