Skip to main content

run_in_container_stream

Function run_in_container_stream 

Source
pub async fn run_in_container_stream(
    image_name: &str,
    run_cmd: &str,
    source: &str,
    ext: &str,
    limits: ResourceLimits,
    tx: Sender<OutputChunk>,
) -> Result<(Option<i64>, String, String, bool, bool), Error>
Expand description

流式执行:与 run_in_container 相同的容器生命周期与清理(ContainerGuard), 但边读日志流边推 chunk 到 tx,同时保留完整 buffer 供调用方回填 EXEC_TASKS。

run_in_container 的差异:

  1. 日志循环里每块 chunk 既 tx.send 推流,也 append 到本地 buffer。
  2. tokio::select! 在日志读取中并发等待 tx 关闭——客户端断开(SSE 关闭) → tx 所有 Sender drop → rx 返回 None → 中止读取。
  3. 终态推 OutputChunk::Done 后 return。

返回完整 buffer(exit_code / stdout / stderr / oom / timed_out),供调用方写 EXEC_TASKS, 让轮询兜底路径(get_exec_result)也能拿到完整结果。