(input: web::Json<RunInput>)
| 30 | |
| 31 | #[post("/run")] |
| 32 | async fn run(input: web::Json<RunInput>) -> HttpResponse { |
| 33 | let slug = input.slug.clone(); |
| 34 | log::info!("Opening stack file: {:#?}", slug); |
| 35 | println!("Running {}!", slug); |
| 36 | |
| 37 | // Create a channel for streaming output |
| 38 | let (tx, mut rx) = tokio::sync::mpsc::channel(100); |
| 39 | |
| 40 | // Spawn the CLI command in a separate task |
| 41 | tokio::spawn(async move { |
| 42 | let output_callback = Box::new(move |line: String| { |
| 43 | let tx = tx.clone(); |
| 44 | tokio::spawn(async move { |
| 45 | let _ = tx.send(line).await; |
| 46 | }); |
| 47 | }); |
| 48 | |
| 49 | cli::run_with_callback(&slug, output_callback).await; |
| 50 | }); |
| 51 | |
| 52 | // Create a streaming response |
| 53 | HttpResponse::Ok() |
| 54 | .content_type("text/event-stream") |
| 55 | .streaming(Box::pin(async_stream::stream! { |
| 56 | while let Some(line) = rx.recv().await { |
| 57 | yield Ok::<_, actix_web::Error>(web::Bytes::from(format!("{}\n", line))); |
| 58 | } |
| 59 | })) |
| 60 | } |
| 61 | |
| 62 | #[actix_web::main] |
| 63 | pub async fn init(tauri: AppHandle) -> std::io::Result<()> { |
nothing calls this directly
no test coverage detected