use super::*;
#[derive(Clone, Default)]
pub struct ExternalBackend;
impl ExternalBackend {
pub fn new() -> Self {
Self
}
}
impl SessionBackend for ExternalBackend {
fn name(&self) -> &'static str {
"external"
}
fn capabilities(&self) -> Capabilities {
Capabilities {
spawn: true,
attach: true,
probe: true,
close: true,
focus: false,
rename: false,
}
}
fn available(&self) -> Result<bool> {
Ok(true)
}
fn spawn(&self, spec: SpawnSpec) -> Result<SessionRef> {
tracing::info!(
task = %spec.task_id,
command = %spec.command.join(" "),
"external placement: the client starts no process; the resident runtime dials in"
);
Ok(SessionRef {
task_id: spec.task_id.clone(),
backend: self.name().into(),
backend_ref: serde_json::json!({
"id": spec.task_id,
"placement": "external",
}),
generation: 1,
})
}
fn attach(&self, session: &SessionRef) -> Result<SessionRef> {
Ok(session.clone())
}
fn probe(&self, session: &SessionRef) -> Result<ResourceProbe> {
Ok(ResourceProbe {
alive: true,
attached: true,
detail: Some(serde_json::json!({
"placement": "external",
"task": session.task_id,
})),
})
}
fn close(&self, session: &SessionRef, reason: CloseReason, _force: bool) -> Result<()> {
tracing::info!(
task = %session.task_id,
?reason,
"external session closed; no process of this client's own to stop"
);
Ok(())
}
}