fix container cli (#2654)

This commit is contained in:
Aiden McClelland
2024-06-25 12:34:47 -06:00
committed by GitHub
parent 0a98ccff0c
commit 0e506f5716
4 changed files with 173 additions and 410 deletions

View File

@@ -25,7 +25,7 @@ use crate::rpc_continuations::Guid;
#[derive(Debug)]
pub struct CliContextSeed {
pub runtime: OnceCell<Runtime>,
pub runtime: OnceCell<Arc<Runtime>>,
pub base_url: Url,
pub rpc_url: Url,
pub registry_url: Option<Url>,
@@ -249,16 +249,19 @@ impl std::ops::Deref for CliContext {
}
}
impl Context for CliContext {
fn runtime(&self) -> tokio::runtime::Handle {
self.runtime
.get_or_init(|| {
tokio::runtime::Builder::new_multi_thread()
.enable_all()
.build()
.unwrap()
})
.handle()
.clone()
fn runtime(&self) -> Option<Arc<Runtime>> {
Some(
self.runtime
.get_or_init(|| {
Arc::new(
tokio::runtime::Builder::new_current_thread()
.enable_all()
.build()
.unwrap(),
)
})
.clone(),
)
}
}
impl CallRemote<RpcContext> for CliContext {
@@ -290,7 +293,7 @@ impl CallRemote<InstallContext> for CliContext {
#[test]
fn test() {
let ctx = CliContext::init(ClientConfig::default()).unwrap();
ctx.runtime().block_on(async {
ctx.runtime().unwrap().block_on(async {
reqwest::Client::new()
.get("http://example.com")
.send()

View File

@@ -19,7 +19,7 @@ pub struct ContainerClientConfig {
pub struct ContainerCliSeed {
socket: PathBuf,
runtime: OnceCell<Runtime>,
runtime: OnceCell<Arc<Runtime>>,
}
#[derive(Clone)]
@@ -35,17 +35,20 @@ impl ContainerCliContext {
}
}
impl Context for ContainerCliContext {
fn runtime(&self) -> tokio::runtime::Handle {
self.0
.runtime
.get_or_init(|| {
tokio::runtime::Builder::new_current_thread()
.enable_all()
.build()
.unwrap()
})
.handle()
.clone()
fn runtime(&self) -> Option<Arc<Runtime>> {
Some(
self.0
.runtime
.get_or_init(|| {
Arc::new(
tokio::runtime::Builder::new_current_thread()
.enable_all()
.build()
.unwrap(),
)
})
.clone(),
)
}
}

View File

@@ -899,50 +899,15 @@ async fn running(context: EffectContext, params: ParamsPackageId) -> Result<Valu
Ok(json!(matches!(package, MainStatus::Running { .. })))
}
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, TS)]
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, Parser, TS)]
#[serde(rename_all = "camelCase")]
#[ts(export)]
struct ProcedureId {
#[serde(default)]
#[arg(default_value_t, long)]
procedure_id: Guid,
}
impl FromArgMatches for ProcedureId {
fn from_arg_matches(matches: &clap::ArgMatches) -> Result<Self, clap::Error> {
Ok(Self {
procedure_id: matches.get_one("procedure-id").cloned().unwrap_or_default(),
})
}
fn from_arg_matches_mut(matches: &mut clap::ArgMatches) -> Result<Self, clap::Error> {
Ok(Self {
procedure_id: matches.get_one("procedure-id").cloned().unwrap_or_default(),
})
}
fn update_from_arg_matches(&mut self, matches: &clap::ArgMatches) -> Result<(), clap::Error> {
self.procedure_id = matches.get_one("procedure-id").cloned().unwrap_or_default();
Ok(())
}
fn update_from_arg_matches_mut(
&mut self,
matches: &mut clap::ArgMatches,
) -> Result<(), clap::Error> {
self.procedure_id = matches.get_one("procedure-id").cloned().unwrap_or_default();
Ok(())
}
}
impl CommandFactory for ProcedureId {
fn command() -> clap::Command {
Self::command_for_update().arg(
clap::Arg::new("procedure-id")
.action(clap::ArgAction::Set)
.value_parser(clap::value_parser!(Guid)),
)
}
fn command_for_update() -> clap::Command {
Self::command()
}
}
async fn restart(
context: EffectContext,
ProcedureId { procedure_id }: ProcedureId,