source · Rust

Vak Tool Worker

crates/vak-server/src/bin/vak-tool-worker.rs
Raw
1.2 KB31 linesSnapshot ed4ab258
  1. 1//! Standalone `__tool_worker` broker endpoint. The server process itself
  2. 2//! doubles as the worker in production (the `vak` binary wires the
  3. 3//! same subcommand); this tiny binary exists so tests can pin a REAL
  4. 4//! worker executable via `Core::set_tool_worker_exe` — a cargo test
  5. 5//! harness cannot speak the broker protocol.
  6. 6
  7. 7fn main() -> std::process::ExitCode {
  8. 8 let invoked = std::env::args_os().nth(1);
  9. 9 let tool_worker =
  10. 10 invoked.as_deref() == Some(std::ffi::OsStr::new(vak_tools::broker::WORKER_SUBCOMMAND));
  11. 11 let persistent_worker = invoked.as_deref()
  12. 12 == Some(std::ffi::OsStr::new(
  13. 13 vak_tools::broker::PERSISTENT_WORKER_SUBCOMMAND,
  14. 14 ));
  15. 15 if !tool_worker && !persistent_worker {
  16. 16 eprintln!("internal tool worker; do not invoke directly");
  17. 17 return std::process::ExitCode::from(64);
  18. 18 }
  19. 19 let code = match tokio::runtime::Builder::new_current_thread()
  20. 20 .enable_all()
  21. 21 .build()
  22. 22 {
  23. 23 Ok(runtime) if persistent_worker => {
  24. 24 runtime.block_on(vak_tools::broker::persistent_worker_main())
  25. 25 }
  26. 26 Ok(runtime) => runtime.block_on(vak_tools::broker::worker_main()),
  27. 27 Err(_) => 125,
  28. 28 };
  29. 29 std::process::ExitCode::from(u8::try_from(code).unwrap_or(125))
  30. 30}
  31. 31