summaryrefslogtreecommitdiffstats
path: root/src/endpoint/scheduler.rs
diff options
context:
space:
mode:
authorMatthias Beyer <matthias.beyer@atos.net>2021-02-15 09:47:43 +0100
committerMatthias Beyer <matthias.beyer@atos.net>2021-02-15 10:45:20 +0100
commitd21a9aeab8c68f0b84c479ff143c02658f9eda7f (patch)
treed3b16a9d014d92b6aea1b719086cadc2cf8a623b /src/endpoint/scheduler.rs
parent1447fc3674a376eef93873e1f18bedd633d870a2 (diff)
Fix: Return script errors properly
This patch fixes error returning from the JobHandle::run() implementation. Somehow, in the many rewrites, the error returning resulted in code that did not differentiate between script run errors and scheduling errors. This patch fixes this by making the JobHandle::run() method return Result<Result<Vec<ArtifactPath>>> whereas the outer error is the scheduling result and the inner error is the script result. The calling code was adapted accordingly. Signed-off-by: Matthias Beyer <matthias.beyer@atos.net>
Diffstat (limited to 'src/endpoint/scheduler.rs')
-rw-r--r--src/endpoint/scheduler.rs16
1 files changed, 12 insertions, 4 deletions
diff --git a/src/endpoint/scheduler.rs b/src/endpoint/scheduler.rs
index ce05e96..ecef98b 100644
--- a/src/endpoint/scheduler.rs
+++ b/src/endpoint/scheduler.rs
@@ -147,7 +147,7 @@ impl std::fmt::Debug for JobHandle {
}
impl JobHandle {
- pub async fn run(self) -> Result<Vec<ArtifactPath>> {
+ pub async fn run(self) -> Result<Result<Vec<ArtifactPath>>> {
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())?;
@@ -230,7 +230,7 @@ impl JobHandle {
trace!("Found result for job {}: {:?}", job_id, res);
let (paths, res) = res.unpack();
- let _ = res
+ let res = res
.with_context(|| anyhow!("Error during running job on '{}'", ep.name()))
.with_context(|| {
Self::create_job_run_error(
@@ -240,7 +240,15 @@ impl JobHandle {
ep.uri(),
&container_id,
)
- })?;
+ })
+ .map_err(Error::from);
+
+ if res.is_err() {
+ trace!("Error was returned from script");
+ return Ok({
+ res.map(|_| vec![]) // to have the proper type, will never be executed
+ })
+ }
// Have to do it the ugly way here because of borrowing semantics
let mut r = vec![];
@@ -257,7 +265,7 @@ impl JobHandle {
.clone()
});
}
- Ok(r)
+ Ok(Ok(r))
}
/// Helper to create an error object with a nice message.