Skip to main content

studio_worker/
lib.rs

1//! Library surface for the `studio-worker` binary.
2//!
3//! Exposes the worker's modules so integration tests (and downstream
4//! tooling) can drive the contract without going through the CLI.
5
6pub mod auto_register;
7pub mod cli;
8pub mod config;
9pub mod engine;
10pub mod http;
11pub mod runtime;
12pub mod service;
13pub mod sys;
14pub mod telemetry;
15#[doc(hidden)]
16pub mod test_support;
17pub mod types;
18#[cfg(feature = "ui")]
19pub mod ui;
20pub mod update;
21pub mod ws;
22
23pub const AGENT_VERSION: &str = env!("CARGO_PKG_VERSION");
24
25/// Sentry release identifier in the `<pkg>@<version>` form expected by
26/// Sentry's organisation-wide *Releases* feature.  Bare version strings
27/// collide across projects in the same org, so we namespace with the
28/// crate name.  Matches what `sentry::release_name!()` would expand to.
29pub const RELEASE_NAME: &str = concat!(env!("CARGO_PKG_NAME"), "@", env!("CARGO_PKG_VERSION"));
30
31/// Dispatch table for the CLI subcommands.  Lives in the library so we
32/// can drive it from tests without invoking the binary.
33pub async fn run_cli(args: cli::Cli) -> anyhow::Result<()> {
34    match args.command {
35        cli::Command::Run => runtime::run(args.config.as_deref()).await,
36        cli::Command::Register {
37            api_base_url,
38            label,
39            reset,
40        } => {
41            runtime::register(
42                args.config.as_deref(),
43                runtime::RegisterArgs {
44                    api_base_url,
45                    label,
46                    reset,
47                },
48            )
49            .await
50        }
51        cli::Command::Status => runtime::status(args.config.as_deref()).await,
52        cli::Command::InstallService => service::install(args.config.as_deref()),
53        cli::Command::UninstallService => service::uninstall(),
54        cli::Command::Enable => runtime::set_enabled(args.config.as_deref(), true),
55        cli::Command::Disable => runtime::set_enabled(args.config.as_deref(), false),
56        cli::Command::SetThreshold { gb } => runtime::set_threshold(args.config.as_deref(), gb),
57        cli::Command::Config => runtime::show_config(args.config.as_deref()),
58        cli::Command::CheckUpdate => runtime::check_update(args.config.as_deref()).await,
59        cli::Command::Ui => run_ui(args.config.as_deref()).await,
60    }
61}
62
63#[cfg(feature = "ui")]
64async fn run_ui(config_path: Option<&str>) -> anyhow::Result<()> {
65    ui::run(config_path)
66}
67
68#[cfg(not(feature = "ui"))]
69async fn run_ui(_config_path: Option<&str>) -> anyhow::Result<()> {
70    anyhow::bail!(
71        "this build of studio-worker was compiled without the `ui` cargo feature.\n\
72         Reinstall with `cargo install studio-worker --features ui` (or use the \
73         desktop installer from the releases page) to enable the native UI."
74    )
75}