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:
J M
2022-06-16 11:58:55 -06:00
committed by GitHub
parent 75a2b2d2ab
commit 27bc493884
3 changed files with 81 additions and 45 deletions

View File

@@ -22,6 +22,7 @@ pub use js_engine::JsError;
enum ErrorValue {
Error(String),
ErrorCode((i32, String)),
Result(serde_json::Value),
}
@@ -81,7 +82,7 @@ impl JsProcedure {
Ok(output)
}
.await
.map_err(|(error, message)| (error as i32, message)))
.map_err(|(error, message)| (error.as_code_num(), message)))
}
#[instrument(skip(ctx, input))]
@@ -115,7 +116,7 @@ impl JsProcedure {
Ok(output)
}
.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)> {
match error_value {
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()) {
Ok(a) => Ok(a),
Err(err) => {

View File

@@ -12,6 +12,18 @@ export namespace ExpectedExports {
export type properties = (
effects: Effects,
) => 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 */
@@ -50,6 +62,10 @@ export type Effects = {
is_sandboxed(): boolean;
};
export type MigrationRes = {
configured: boolean;
};
export type ActionResult = {
version: "0";
message: string;
@@ -260,52 +276,54 @@ export type ValueSpecList =
WithDescription<WithDefault<ListSpec<ValueSpecUnion>, string[]>>
>;
export type ValueSpecEnum = {
values: string[],
values: string[];
"value-names": { [key: string]: string };
}
};
export type SetResult = {
/** These are the unix process signals */
signal:
| "SIGTERM"
| "SIGHUP"
| "SIGINT"
| "SIGQUIT"
| "SIGILL"
| "SIGTRAP"
| "SIGABRT"
| "SIGBUS"
| "SIGFPE"
| "SIGKILL"
| "SIGUSR1"
| "SIGSEGV"
| "SIGUSR2"
| "SIGPIPE"
| "SIGALRM"
| "SIGSTKFLT"
| "SIGCHLD"
| "SIGCONT"
| "SIGSTOP"
| "SIGTSTP"
| "SIGTTIN"
| "SIGTTOU"
| "SIGURG"
| "SIGXCPU"
| "SIGXFSZ"
| "SIGVTALRM"
| "SIGPROF"
| "SIGWINCH"
| "SIGIO"
| "SIGPWR"
| "SIGSYS"
| "SIGEMT"
| "SIGINFO";
| "SIGTERM"
| "SIGHUP"
| "SIGINT"
| "SIGQUIT"
| "SIGILL"
| "SIGTRAP"
| "SIGABRT"
| "SIGBUS"
| "SIGFPE"
| "SIGKILL"
| "SIGUSR1"
| "SIGSEGV"
| "SIGUSR2"
| "SIGPIPE"
| "SIGALRM"
| "SIGSTKFLT"
| "SIGCHLD"
| "SIGCONT"
| "SIGSTOP"
| "SIGTSTP"
| "SIGTTIN"
| "SIGTTOU"
| "SIGURG"
| "SIGXCPU"
| "SIGXFSZ"
| "SIGVTALRM"
| "SIGPROF"
| "SIGWINCH"
| "SIGIO"
| "SIGPWR"
| "SIGSYS"
| "SIGEMT"
| "SIGINFO";
"depends-on": {
[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 PackagePropertiesV2 = {

View File

@@ -35,13 +35,29 @@ pub struct JsCode(String);
#[derive(Debug, Clone, Copy)]
pub enum JsError {
Unknown = 1,
Javascript = 2,
Engine = 3,
BoundryLayerSerDe = 4,
Tokio = 5,
FileSystem = 6,
Timeout = 143,
Unknown,
Javascript,
Engine,
BoundryLayerSerDe,
Tokio,
FileSystem,
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")]