diff options
Diffstat (limited to 'src/endpoint')
-rw-r--r-- | src/endpoint/configured.rs | 5 | ||||
-rw-r--r-- | src/endpoint/error.rs | 30 | ||||
-rw-r--r-- | src/endpoint/scheduler.rs | 6 |
3 files changed, 5 insertions, 36 deletions
diff --git a/src/endpoint/configured.rs b/src/endpoint/configured.rs index 191e565..a478857 100644 --- a/src/endpoint/configured.rs +++ b/src/endpoint/configured.rs @@ -1,6 +1,5 @@ use std::fmt::{Debug, Formatter}; use std::path::PathBuf; -use std::result::Result as RResult; use std::str::FromStr; use std::sync::Arc; @@ -176,7 +175,7 @@ impl Endpoint { .map(|_| ()) } - pub async fn run_job(&self, job: RunnableJob, logsink: UnboundedSender<LogItem>, staging: Arc<RwLock<StagingStore>>) -> RResult<(Vec<ArtifactPath>, ContainerHash, Script), ContainerError> { + pub async fn run_job(&self, job: RunnableJob, logsink: UnboundedSender<LogItem>, staging: Arc<RwLock<StagingStore>>) -> Result<(Vec<ArtifactPath>, ContainerHash, Script)> { let (container_id, _warnings) = { let envs = job.environment() .into_iter() @@ -365,7 +364,7 @@ impl Endpoint { let script: Script = job.script().clone(); match exited_successfully { - Some(false) => Err(ContainerError::container_error(ContainerHash::from(container_id), self.uri().clone())), + Some(false) => Err(ContainerError::container_error(ContainerHash::from(container_id), self.uri().clone())).map_err(Error::from), Some(true) | None => { container.stop(Some(std::time::Duration::new(1, 0))) .await diff --git a/src/endpoint/error.rs b/src/endpoint/error.rs index dc4468a..5638efe 100644 --- a/src/endpoint/error.rs +++ b/src/endpoint/error.rs @@ -4,44 +4,16 @@ use crate::util::docker::ContainerHash; #[derive(ThisError, Debug)] pub enum ContainerError { - - #[error("Error during container run: {container_id}")] + #[error("Error during container run, connect using `docker --host {uri} exec -it {container_id} /bin/bash`")] ContainerError { container_id: ContainerHash, uri: String, }, - - #[error("{0}")] - Err(anyhow::Error), } impl ContainerError { pub fn container_error(container_id: ContainerHash, uri: String) -> Self { ContainerError::ContainerError { container_id, uri } } - - pub fn explain_container_error(&self) -> Option<String> { - match self { - ContainerError::ContainerError { container_id, uri } => Some({ - indoc::formatdoc!(r#" - Container did not exit successfully: {container_id} - It was not stopped because of this. - - Use - - docker --host {uri} exec -it {container_id} /bin/bash - - to access and debug. - "#, uri = uri, container_id = container_id) - }), - _ => None, - } - } -} - -impl From<anyhow::Error> for ContainerError { - fn from(ae: anyhow::Error) -> Self { - ContainerError::Err(ae) - } } diff --git a/src/endpoint/scheduler.rs b/src/endpoint/scheduler.rs index 6d0eb1e..1b15789 100644 --- a/src/endpoint/scheduler.rs +++ b/src/endpoint/scheduler.rs @@ -1,5 +1,4 @@ use std::path::PathBuf; -use std::result::Result as RResult; use std::sync::Arc; use anyhow::Context; @@ -18,7 +17,6 @@ use tokio::sync::mpsc::UnboundedReceiver; use uuid::Uuid; use crate::db::models as dbmodels; -use crate::endpoint::ContainerError; use crate::endpoint::Endpoint; use crate::endpoint::EndpointConfiguration; use crate::filestore::StagingStore; @@ -131,7 +129,7 @@ impl std::fmt::Debug for JobHandle { } impl JobHandle { - pub async fn run(self) -> RResult<Vec<dbmodels::Artifact>, ContainerError> { + pub async fn run(self) -> Result<Vec<dbmodels::Artifact>> { let (log_sender, log_receiver) = tokio::sync::mpsc::unbounded_channel::<LogItem>(); let ep = self.endpoint.read().await; let endpoint = dbmodels::Endpoint::create_or_fetch(&self.db, ep.name())?; @@ -156,7 +154,7 @@ impl JobHandle { trace!("Found result for job {}: {:?}", job_id, res); let log = logres.with_context(|| anyhow!("Collecting logs for job on '{}'", ep.name()))?; - let (paths, container_hash, script) = res.with_context(|| anyhow!("Running job on '{}'", ep.name()))?; + let (paths, container_hash, script) = res.with_context(|| anyhow!("Error during running job on '{}'", ep.name()))?; let job = dbmodels::Job::create(&self.db, &job_id, &self.submit, &endpoint, &package, &image, &container_hash, &script, &log)?; for env in envs { |