use super::{
convert::local_target_of,
execute::{ExecContext, execute_job_catching},
};
use crate::settings::WorkerSettings;
use indicatrix_render_jobs::{
ComputeChoice, JobOutcome, JobSink, LocalEngines, RenderJobFile, TransferChoice,
};
use std::{
path::{Path, PathBuf},
sync::atomic::AtomicBool,
};
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct RemoteEndpoint {
pub address: String,
pub cert_dir: PathBuf,
}
#[derive(Debug, Clone, Default)]
pub struct HeadlessOptions {
pub local: LocalEngines,
pub remote: Option<RemoteEndpoint>,
pub compute: Option<ComputeChoice>,
pub transfer: Option<TransferChoice>,
pub contribute_local: Option<bool>,
pub output: Option<PathBuf>,
pub restart_frames: bool,
}
pub fn run_job(
job: &RenderJobFile,
job_dir: &Path,
options: &HeadlessOptions,
cancel: &AtomicBool,
sink: &mut dyn JobSink,
) -> JobOutcome {
let worker = options.remote.as_ref().map(|remote| WorkerSettings {
address: remote.address.clone(),
cert_dir: remote.cert_dir.display().to_string(),
..WorkerSettings::default()
});
let ctx = ExecContext {
base_dir: job_dir.to_path_buf(),
local_compute: local_target_of(options.local),
worker,
compute_override: options.compute,
transfer_override: options.transfer,
contribute_local_override: options.contribute_local,
output_override: options.output.clone(),
restart_frames: options.restart_frames,
};
execute_job_catching(job, &ctx, cancel, sink)
}
#[must_use]
pub const fn gpu_compiled_in() -> bool {
cfg!(feature = "gpu")
}