-
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.
feat(worker-runner): implemented instance graceful termination (#46)
Containers cannot be killed by request, except when termination fails.
- Loading branch information
Showing
7 changed files
with
183 additions
and
89 deletions.
There are no files selected for viewing
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,6 +1,5 @@ | ||
pub mod common; | ||
|
||
pub mod ctl; | ||
pub mod worker; | ||
|
||
pub mod etc; | ||
pub mod well_known; | ||
pub mod worker; |
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
use std::time::Duration; | ||
|
||
pub const GRACEFUL_SHUTDOWN_DEADLINE: Duration = Duration::from_secs(20); |
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 |
---|---|---|
@@ -0,0 +1,38 @@ | ||
use eyre::Report; | ||
use proto::common::instance::{self, InstanceId, InstanceSpec}; | ||
use tokio::sync::{mpsc, oneshot}; | ||
|
||
use super::Msg; | ||
|
||
#[derive(Clone)] | ||
pub struct RunnerHandle(pub mpsc::Sender<Msg>); | ||
|
||
impl RunnerHandle { | ||
async fn send(&self, msg: Msg) { | ||
_ = self.0.send(msg).await; | ||
} | ||
|
||
/// Sends a message and waits for a reply. | ||
async fn send_wait<F, R>(&self, f: F) -> R | ||
where | ||
F: FnOnce(oneshot::Sender<R>) -> Msg, | ||
{ | ||
let (tx, rx) = oneshot::channel(); | ||
self.send(f(tx)).await; | ||
rx.await.expect("actor must be alive") | ||
} | ||
|
||
#[allow(dead_code)] | ||
pub async fn deploy_instance(&self, spec: InstanceSpec) -> Result<(), Report> { | ||
self.send_wait(|tx| Msg::DeployInstance(spec, tx)).await | ||
} | ||
|
||
#[allow(dead_code)] | ||
pub async fn terminate_instance(&self, id: InstanceId) -> Result<(), Report> { | ||
self.send_wait(|tx| Msg::TerminateInstance(id, tx)).await | ||
} | ||
|
||
pub async fn report_instance_status(&self, id: InstanceId, status: instance::Status) { | ||
self.send(Msg::ReportInstanceStatus(id, status)).await; | ||
} | ||
} |
Oops, something went wrong.