use biolib::Runtime;
fn main() {
if !Runtime::check_is_environment_biolib_app() {
println!("Not running inside a BioLib app - Runtime functions won't work");
println!("Run this code inside a BioLib app container to use Runtime features");
return;
}
example_get_job_info();
example_set_result_name();
example_read_secrets();
example_create_note();
}
fn example_get_job_info() {
let job_id = Runtime::get_job_id().expect("Failed to get job ID");
println!("Current job ID: {job_id}");
let app_uri = Runtime::get_app_uri().expect("Failed to get app URI");
println!("Running app: {app_uri}");
let is_cloud = Runtime::check_is_environment_biolib_cloud().unwrap_or(false);
println!("Running in cloud: {is_cloud}");
if let Ok(Some(machine)) = Runtime::get_job_requested_machine() {
println!("Requested machine: {machine}");
}
let is_spot = Runtime::is_spot_machine_requested().unwrap_or(false);
println!("Spot instance requested: {is_spot}");
let max_workers = Runtime::get_max_workers().unwrap_or(1);
println!("Max workers: {max_workers}");
}
fn example_set_result_name() {
Runtime::set_main_result_prefix("my-analysis-result").expect("Failed to set result prefix");
Runtime::set_result_name_prefix("my-analysis-result").expect("Failed to set result prefix");
Runtime::set_result_name_from_string("Analysis of sample XYZ with parameters A=1, B=2")
.expect("Failed to set result name");
Runtime::set_result_name_from_file("/input/my_sample.fasta")
.expect("Failed to set result name from file");
Runtime::set_result_name_prefix_from_fasta("/input/input_abc123.fasta")
.expect("Failed to set result name from FASTA");
}
fn example_read_secrets() {
match Runtime::get_secret("API_KEY") {
Ok(secret_bytes) => {
let secret = String::from_utf8_lossy(&secret_bytes);
println!("Got API key: {}...", &secret[..secret.len().min(4)]);
}
Err(err) => {
println!("Could not read API_KEY secret: {err}");
}
}
match Runtime::get_temporary_client_secret("USER_TOKEN") {
Ok(secret_bytes) => {
let secret = String::from_utf8_lossy(&secret_bytes);
println!("Got user token: {}...", &secret[..secret.len().min(4)]);
}
Err(err) => {
println!("Could not read USER_TOKEN secret: {err}");
}
}
}
fn example_create_note() {
Runtime::create_result_note("Analysis completed successfully with 95% confidence")
.expect("Failed to create note");
Runtime::create_result_note("Parameters used: threshold=0.5, iterations=100")
.expect("Failed to create note");
}
fn _example_oauth_token() {
match Runtime::get_oauth_access_token("read:data write:results") {
Ok(token) => {
println!("Got OAuth token: {}...", &token[..token.len().min(10)]);
}
Err(err) => {
println!("Could not get OAuth token: {err}");
}
}
}
fn _example_job_auth_token() {
let auth_token = Runtime::get_job_auth_token().expect("Failed to get auth token");
println!(
"Job auth token: {}...",
&auth_token[..auth_token.len().min(10)]
);
}