wait.py 885 B

12345678910111213141516171819202122232425262728
  1. from __future__ import annotations
  2. import time
  3. from typing import Any
  4. from ..context import WorkflowContext
  5. from ..registry import control_ports, field_def, register_node
  6. def seconds_node(node: dict[str, Any], inputs: dict[str, Any], context: WorkflowContext) -> dict[str, Any]:
  7. seconds = float(inputs.get("seconds", node.get("params", {}).get("seconds", 1)))
  8. seconds = max(0, min(seconds, 3600))
  9. time.sleep(seconds)
  10. return {"seconds": seconds}
  11. register_node(
  12. {
  13. "type": "wait.seconds",
  14. "category": "wait",
  15. "label": "等待秒数",
  16. "params": {"seconds": field_def("number", "秒数", 1, minimum=0, maximum=3600)},
  17. "inputs": {"seconds": field_def("number", "秒数")},
  18. "outputs": {"seconds": {"type": "number", "label": "实际等待秒数"}},
  19. "control_ports": control_ports(),
  20. },
  21. seconds_node,
  22. )