mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-03-26 02:11:53 +00:00
@@ -64,56 +64,6 @@ impl EffectContext {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct WithProcedureId<T> {
|
||||
#[serde(default)]
|
||||
procedure_id: Guid,
|
||||
#[serde(flatten)]
|
||||
rest: T,
|
||||
}
|
||||
impl<T: FromArgMatches> FromArgMatches for WithProcedureId<T> {
|
||||
fn from_arg_matches(matches: &clap::ArgMatches) -> Result<Self, clap::Error> {
|
||||
let rest = T::from_arg_matches(matches)?;
|
||||
Ok(Self {
|
||||
procedure_id: matches.get_one("procedure-id").cloned().unwrap_or_default(),
|
||||
rest,
|
||||
})
|
||||
}
|
||||
fn from_arg_matches_mut(matches: &mut clap::ArgMatches) -> Result<Self, clap::Error> {
|
||||
let rest = T::from_arg_matches_mut(matches)?;
|
||||
Ok(Self {
|
||||
procedure_id: matches.get_one("procedure-id").cloned().unwrap_or_default(),
|
||||
rest,
|
||||
})
|
||||
}
|
||||
fn update_from_arg_matches(&mut self, matches: &clap::ArgMatches) -> Result<(), clap::Error> {
|
||||
self.rest.update_from_arg_matches(matches)?;
|
||||
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.rest.update_from_arg_matches_mut(matches)?;
|
||||
self.procedure_id = matches.get_one("procedure-id").cloned().unwrap_or_default();
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
impl<T: CommandFactory> CommandFactory for WithProcedureId<T> {
|
||||
fn command() -> clap::Command {
|
||||
T::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()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn service_effect_handler<C: Context>() -> ParentHandler<C> {
|
||||
ParentHandler::new()
|
||||
.subcommand("gitInfo", from_fn(|_: C| crate::version::git_info()))
|
||||
@@ -877,6 +827,8 @@ async fn exists(context: EffectContext, params: ParamsPackageId) -> Result<Value
|
||||
#[serde(rename_all = "camelCase")]
|
||||
#[ts(export)]
|
||||
struct ExecuteAction {
|
||||
#[serde(default)]
|
||||
procedure_id: Guid,
|
||||
#[ts(type = "string | null")]
|
||||
service_id: Option<PackageId>,
|
||||
#[ts(type = "string")]
|
||||
@@ -886,15 +838,12 @@ struct ExecuteAction {
|
||||
}
|
||||
async fn execute_action(
|
||||
context: EffectContext,
|
||||
WithProcedureId {
|
||||
ExecuteAction {
|
||||
procedure_id,
|
||||
rest:
|
||||
ExecuteAction {
|
||||
service_id,
|
||||
action_id,
|
||||
input,
|
||||
},
|
||||
}: WithProcedureId<ExecuteAction>,
|
||||
service_id,
|
||||
action_id,
|
||||
input,
|
||||
}: ExecuteAction,
|
||||
) -> Result<Value, Error> {
|
||||
let context = context.deref()?;
|
||||
let package_id = service_id
|
||||
@@ -950,9 +899,53 @@ async fn running(context: EffectContext, params: ParamsPackageId) -> Result<Valu
|
||||
Ok(json!(matches!(package, MainStatus::Running { .. })))
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, TS)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
#[ts(export)]
|
||||
struct ProcedureId {
|
||||
#[serde(default)]
|
||||
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,
|
||||
WithProcedureId { procedure_id, .. }: WithProcedureId<Empty>,
|
||||
ProcedureId { procedure_id }: ProcedureId,
|
||||
) -> Result<(), Error> {
|
||||
let context = context.deref()?;
|
||||
context.restart(procedure_id).await?;
|
||||
@@ -961,7 +954,7 @@ async fn restart(
|
||||
|
||||
async fn shutdown(
|
||||
context: EffectContext,
|
||||
WithProcedureId { procedure_id, .. }: WithProcedureId<Empty>,
|
||||
ProcedureId { procedure_id }: ProcedureId,
|
||||
) -> Result<(), Error> {
|
||||
let context = context.deref()?;
|
||||
context.stop(procedure_id).await?;
|
||||
@@ -1001,7 +994,6 @@ async fn set_configured(context: EffectContext, params: SetConfigured) -> Result
|
||||
enum SetMainStatusStatus {
|
||||
Running,
|
||||
Stopped,
|
||||
Starting,
|
||||
}
|
||||
impl FromStr for SetMainStatusStatus {
|
||||
type Err = color_eyre::eyre::Report;
|
||||
@@ -1009,7 +1001,6 @@ impl FromStr for SetMainStatusStatus {
|
||||
match s {
|
||||
"running" => Ok(Self::Running),
|
||||
"stopped" => Ok(Self::Stopped),
|
||||
"starting" => Ok(Self::Starting),
|
||||
_ => Err(eyre!("unknown status {s}")),
|
||||
}
|
||||
}
|
||||
@@ -1033,7 +1024,6 @@ async fn set_main_status(context: EffectContext, params: SetMainStatus) -> Resul
|
||||
match params.status {
|
||||
SetMainStatusStatus::Running => context.seed.started(),
|
||||
SetMainStatusStatus::Stopped => context.seed.stopped(),
|
||||
SetMainStatusStatus::Starting => context.seed.started(),
|
||||
}
|
||||
Ok(Value::Null)
|
||||
}
|
||||
@@ -1262,15 +1252,17 @@ impl ValueParserFactory for DependencyRequirement {
|
||||
#[command(rename_all = "camelCase")]
|
||||
#[ts(export)]
|
||||
struct SetDependenciesParams {
|
||||
#[serde(default)]
|
||||
procedure_id: Guid,
|
||||
dependencies: Vec<DependencyRequirement>,
|
||||
}
|
||||
|
||||
async fn set_dependencies(
|
||||
context: EffectContext,
|
||||
WithProcedureId {
|
||||
SetDependenciesParams {
|
||||
procedure_id,
|
||||
rest: SetDependenciesParams { dependencies },
|
||||
}: WithProcedureId<SetDependenciesParams>,
|
||||
dependencies,
|
||||
}: SetDependenciesParams,
|
||||
) -> Result<(), Error> {
|
||||
let context = context.deref()?;
|
||||
let id = &context.seed.id;
|
||||
|
||||
@@ -168,10 +168,6 @@ export class Daemons<Manifest extends SDKManifest, Ids extends string> {
|
||||
}
|
||||
|
||||
private updateMainHealth() {
|
||||
if (this.healthDaemons.every((x) => x.health.status === "success")) {
|
||||
this.effects.setMainStatus({ status: "running" })
|
||||
} else {
|
||||
this.effects.setMainStatus({ status: "starting" })
|
||||
}
|
||||
this.effects.setMainStatus({ status: "running" })
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
|
||||
import type { Guid } from "./Guid"
|
||||
|
||||
export type ExecuteAction = {
|
||||
procedureId: Guid
|
||||
serviceId: string | null
|
||||
actionId: string
|
||||
input: any
|
||||
|
||||
4
sdk/lib/osBindings/ProcedureId.ts
Normal file
4
sdk/lib/osBindings/ProcedureId.ts
Normal file
@@ -0,0 +1,4 @@
|
||||
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
|
||||
import type { Guid } from "./Guid"
|
||||
|
||||
export type ProcedureId = { procedureId: Guid }
|
||||
@@ -1,6 +1,8 @@
|
||||
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
|
||||
import type { DependencyRequirement } from "./DependencyRequirement"
|
||||
import type { Guid } from "./Guid"
|
||||
|
||||
export type SetDependenciesParams = {
|
||||
procedureId: Guid
|
||||
dependencies: Array<DependencyRequirement>
|
||||
}
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
|
||||
|
||||
export type SetMainStatusStatus = "running" | "stopped" | "starting"
|
||||
export type SetMainStatusStatus = "running" | "stopped"
|
||||
|
||||
@@ -108,6 +108,7 @@ export { PackageVersionInfo } from "./PackageVersionInfo"
|
||||
export { ParamsMaybePackageId } from "./ParamsMaybePackageId"
|
||||
export { ParamsPackageId } from "./ParamsPackageId"
|
||||
export { PasswordType } from "./PasswordType"
|
||||
export { ProcedureId } from "./ProcedureId"
|
||||
export { Progress } from "./Progress"
|
||||
export { Public } from "./Public"
|
||||
export { RecoverySource } from "./RecoverySource"
|
||||
|
||||
Reference in New Issue
Block a user