mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-04-04 14:29:45 +00:00
Feat: Make the js check for health (#1543)
* Feat: Make the js check for health * chore: Add in the migration types * feat: type up the migration
This commit is contained in:
@@ -22,6 +22,7 @@ pub use js_engine::JsError;
|
|||||||
|
|
||||||
enum ErrorValue {
|
enum ErrorValue {
|
||||||
Error(String),
|
Error(String),
|
||||||
|
ErrorCode((i32, String)),
|
||||||
Result(serde_json::Value),
|
Result(serde_json::Value),
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -81,7 +82,7 @@ impl JsProcedure {
|
|||||||
Ok(output)
|
Ok(output)
|
||||||
}
|
}
|
||||||
.await
|
.await
|
||||||
.map_err(|(error, message)| (error as i32, message)))
|
.map_err(|(error, message)| (error.as_code_num(), message)))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[instrument(skip(ctx, input))]
|
#[instrument(skip(ctx, input))]
|
||||||
@@ -115,7 +116,7 @@ impl JsProcedure {
|
|||||||
Ok(output)
|
Ok(output)
|
||||||
}
|
}
|
||||||
.await
|
.await
|
||||||
.map_err(|(error, message)| (error as i32, message)))
|
.map_err(|(error, message)| (error.as_code_num(), message)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -124,6 +125,7 @@ fn unwrap_known_error<O: for<'de> Deserialize<'de>>(
|
|||||||
) -> Result<O, (JsError, String)> {
|
) -> Result<O, (JsError, String)> {
|
||||||
match error_value {
|
match error_value {
|
||||||
ErrorValue::Error(error) => Err((JsError::Javascript, error)),
|
ErrorValue::Error(error) => Err((JsError::Javascript, error)),
|
||||||
|
ErrorValue::ErrorCode((code, message)) => Err((JsError::Code(code), message)),
|
||||||
ErrorValue::Result(ref value) => match serde_json::from_value(value.clone()) {
|
ErrorValue::Result(ref value) => match serde_json::from_value(value.clone()) {
|
||||||
Ok(a) => Ok(a),
|
Ok(a) => Ok(a),
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
|
|||||||
90
libs/artifacts/types.d.ts
vendored
90
libs/artifacts/types.d.ts
vendored
@@ -12,6 +12,18 @@ export namespace ExpectedExports {
|
|||||||
export type properties = (
|
export type properties = (
|
||||||
effects: Effects,
|
effects: Effects,
|
||||||
) => Promise<ResultType<Properties>>;
|
) => Promise<ResultType<Properties>>;
|
||||||
|
|
||||||
|
export type health = {
|
||||||
|
/** Should be the health check id */
|
||||||
|
[id: string]: (
|
||||||
|
effects: Effects,
|
||||||
|
dateMs: number,
|
||||||
|
) => Promise<ResultType<null | void>>;
|
||||||
|
};
|
||||||
|
export type migration = (
|
||||||
|
effects: Effects,
|
||||||
|
version: string,
|
||||||
|
) => Promise<ResultType<MigrationRes>>;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Used to reach out from the pure js runtime */
|
/** Used to reach out from the pure js runtime */
|
||||||
@@ -50,6 +62,10 @@ export type Effects = {
|
|||||||
is_sandboxed(): boolean;
|
is_sandboxed(): boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export type MigrationRes = {
|
||||||
|
configured: boolean;
|
||||||
|
};
|
||||||
|
|
||||||
export type ActionResult = {
|
export type ActionResult = {
|
||||||
version: "0";
|
version: "0";
|
||||||
message: string;
|
message: string;
|
||||||
@@ -260,52 +276,54 @@ export type ValueSpecList =
|
|||||||
WithDescription<WithDefault<ListSpec<ValueSpecUnion>, string[]>>
|
WithDescription<WithDefault<ListSpec<ValueSpecUnion>, string[]>>
|
||||||
>;
|
>;
|
||||||
export type ValueSpecEnum = {
|
export type ValueSpecEnum = {
|
||||||
values: string[],
|
values: string[];
|
||||||
"value-names": { [key: string]: string };
|
"value-names": { [key: string]: string };
|
||||||
}
|
};
|
||||||
|
|
||||||
export type SetResult = {
|
export type SetResult = {
|
||||||
/** These are the unix process signals */
|
/** These are the unix process signals */
|
||||||
signal:
|
signal:
|
||||||
| "SIGTERM"
|
| "SIGTERM"
|
||||||
| "SIGHUP"
|
| "SIGHUP"
|
||||||
| "SIGINT"
|
| "SIGINT"
|
||||||
| "SIGQUIT"
|
| "SIGQUIT"
|
||||||
| "SIGILL"
|
| "SIGILL"
|
||||||
| "SIGTRAP"
|
| "SIGTRAP"
|
||||||
| "SIGABRT"
|
| "SIGABRT"
|
||||||
| "SIGBUS"
|
| "SIGBUS"
|
||||||
| "SIGFPE"
|
| "SIGFPE"
|
||||||
| "SIGKILL"
|
| "SIGKILL"
|
||||||
| "SIGUSR1"
|
| "SIGUSR1"
|
||||||
| "SIGSEGV"
|
| "SIGSEGV"
|
||||||
| "SIGUSR2"
|
| "SIGUSR2"
|
||||||
| "SIGPIPE"
|
| "SIGPIPE"
|
||||||
| "SIGALRM"
|
| "SIGALRM"
|
||||||
| "SIGSTKFLT"
|
| "SIGSTKFLT"
|
||||||
| "SIGCHLD"
|
| "SIGCHLD"
|
||||||
| "SIGCONT"
|
| "SIGCONT"
|
||||||
| "SIGSTOP"
|
| "SIGSTOP"
|
||||||
| "SIGTSTP"
|
| "SIGTSTP"
|
||||||
| "SIGTTIN"
|
| "SIGTTIN"
|
||||||
| "SIGTTOU"
|
| "SIGTTOU"
|
||||||
| "SIGURG"
|
| "SIGURG"
|
||||||
| "SIGXCPU"
|
| "SIGXCPU"
|
||||||
| "SIGXFSZ"
|
| "SIGXFSZ"
|
||||||
| "SIGVTALRM"
|
| "SIGVTALRM"
|
||||||
| "SIGPROF"
|
| "SIGPROF"
|
||||||
| "SIGWINCH"
|
| "SIGWINCH"
|
||||||
| "SIGIO"
|
| "SIGIO"
|
||||||
| "SIGPWR"
|
| "SIGPWR"
|
||||||
| "SIGSYS"
|
| "SIGSYS"
|
||||||
| "SIGEMT"
|
| "SIGEMT"
|
||||||
| "SIGINFO";
|
| "SIGINFO";
|
||||||
"depends-on": {
|
"depends-on": {
|
||||||
[packageId: string]: string[];
|
[packageId: string]: string[];
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
export type KnownError = { error: String };
|
export type KnownError = { error: String } | {
|
||||||
|
"error-code": [number, string] | readonly [number, string];
|
||||||
|
};
|
||||||
export type ResultType<T> = KnownError | { result: T };
|
export type ResultType<T> = KnownError | { result: T };
|
||||||
|
|
||||||
export type PackagePropertiesV2 = {
|
export type PackagePropertiesV2 = {
|
||||||
|
|||||||
@@ -35,13 +35,29 @@ pub struct JsCode(String);
|
|||||||
|
|
||||||
#[derive(Debug, Clone, Copy)]
|
#[derive(Debug, Clone, Copy)]
|
||||||
pub enum JsError {
|
pub enum JsError {
|
||||||
Unknown = 1,
|
Unknown,
|
||||||
Javascript = 2,
|
Javascript,
|
||||||
Engine = 3,
|
Engine,
|
||||||
BoundryLayerSerDe = 4,
|
BoundryLayerSerDe,
|
||||||
Tokio = 5,
|
Tokio,
|
||||||
FileSystem = 6,
|
FileSystem,
|
||||||
Timeout = 143,
|
Code(i32),
|
||||||
|
Timeout,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl JsError {
|
||||||
|
pub fn as_code_num(&self) -> i32 {
|
||||||
|
match self {
|
||||||
|
JsError::Unknown => 1,
|
||||||
|
JsError::Javascript => 2,
|
||||||
|
JsError::Engine => 3,
|
||||||
|
JsError::BoundryLayerSerDe => 4,
|
||||||
|
JsError::Tokio => 5,
|
||||||
|
JsError::FileSystem => 6,
|
||||||
|
JsError::Code(code) => *code,
|
||||||
|
JsError::Timeout => 143,
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(target_arch = "x86_64")]
|
#[cfg(target_arch = "x86_64")]
|
||||||
|
|||||||
Reference in New Issue
Block a user