generated from stjude-biohackathon/KIDS24-team
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
revise: multiple updates to the backend execution engine
- Loading branch information
1 parent
147e52f
commit d20d8de
Showing
8 changed files
with
442 additions
and
107 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,50 @@ | ||
//! Task runner services. | ||
use futures::future::BoxFuture; | ||
use futures::stream::FuturesUnordered; | ||
use tokio::sync::oneshot::Receiver; | ||
|
||
use crate::engine::service::runner::backend::docker; | ||
use crate::engine::service::runner::backend::Reply; | ||
use crate::engine::Task; | ||
|
||
pub mod backend; | ||
|
||
/// A submitted task handle. | ||
#[derive(Debug)] | ||
pub struct Handle { | ||
/// The callback that is executed when a task is completed. | ||
pub callback: Receiver<Reply>, | ||
} | ||
|
||
/// A generic task runner. | ||
#[derive(Debug)] | ||
pub struct Runner { | ||
/// The task runner itself. | ||
runner: docker::Runner, | ||
|
||
/// The list of submitted tasks. | ||
pub tasks: FuturesUnordered<BoxFuture<'static, ()>>, | ||
} | ||
|
||
impl Runner { | ||
/// Creates a Docker-backed [`Runner`]. | ||
/// | ||
/// # Panics | ||
/// | ||
/// If initialization of the [`bollard`](bollard) client fails. | ||
pub fn docker() -> Self { | ||
Self { | ||
runner: docker::Runner::try_new().unwrap(), | ||
tasks: Default::default(), | ||
} | ||
} | ||
|
||
/// Submits a task to be executed by the backend. | ||
pub fn submit(&self, task: Task) -> Handle { | ||
let (tx, rx) = tokio::sync::oneshot::channel(); | ||
self.tasks.push(Box::pin(self.runner.run(task, tx))); | ||
|
||
Handle { callback: rx } | ||
} | ||
} |
Oops, something went wrong.