Skip to main content

run_oop_with_options

Function run_oop_with_options 

Source
pub async fn run_oop_with_options(opts: OopRunOptions) -> Result<()>
Expand description

Run an out-of-process gear with the given options

This function:

  1. Creates a root CancellationToken for the process
  2. Hooks OS signals (SIGTERM, SIGINT, Ctrl+C) to trigger cancellation
  3. Loads configuration and initializes logging
  4. Connects to the DirectoryService
  5. Registers the gear instance
  6. Starts a background heartbeat loop (using a child token)
  7. Runs the gear lifecycle with ShutdownOptions::Token
  8. Deregisters from DirectoryService on shutdown

§Shutdown Model

A single root cancellation token drives shutdown for the entire process. OS signals are hooked at this bootstrap level (not via ShutdownOptions::Signals). The heartbeat loop and gear runtime both observe this token tree.

§Arguments

  • opts - Bootstrap configuration options

§Returns

  • Ok(()) - If the gear lifecycle completed successfully
  • Err(e) - If any step failed

§Example

use toolkit::bootstrap::oop::{OopRunOptions, run_oop_with_options};

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    let opts = OopRunOptions {
        gear_name: "file-parser".to_string(),
        instance_id: None,
        directory_endpoint: "http://127.0.0.1:50051".to_string(),
        config_path: None,
        verbose: 1,
        print_config: false,
        heartbeat_interval_secs: 5,
    };

    run_oop_with_options(opts).await
}

§Errors

Returns an error if the OoP gear fails to start or run.