Merge branch 'next/minor' of github.com:Start9Labs/start-os into rebase/feat/domains

This commit is contained in:
Matt Hill
2024-03-30 21:14:53 -06:00
191 changed files with 1789 additions and 1316 deletions

View File

@@ -112,8 +112,9 @@ export class MainLoop {
])
if (executed.exitCode === 59) {
await effects.setHealth({
name: healthId,
status: "disabled",
id: healthId,
name: value.name,
result: "disabled",
message:
executed.stderr.toString() || executed.stdout.toString(),
})
@@ -121,8 +122,9 @@ export class MainLoop {
}
if (executed.exitCode === 60) {
await effects.setHealth({
name: healthId,
status: "starting",
id: healthId,
name: value.name,
result: "starting",
message:
executed.stderr.toString() || executed.stdout.toString(),
})
@@ -130,8 +132,9 @@ export class MainLoop {
}
if (executed.exitCode === 61) {
await effects.setHealth({
name: healthId,
status: "warning",
id: healthId,
name: value.name,
result: "loading",
message:
executed.stderr.toString() || executed.stdout.toString(),
})
@@ -141,15 +144,17 @@ export class MainLoop {
const message = executed.stdout.toString()
if (!!errorMessage) {
await effects.setHealth({
name: healthId,
status: "failure",
id: healthId,
name: value.name,
result: "failure",
message: errorMessage,
})
return
}
await effects.setHealth({
name: healthId,
status: "passing",
id: healthId,
name: value.name,
result: "success",
message,
})
return
@@ -159,9 +164,10 @@ export class MainLoop {
const method = moduleCode.health?.[healthId]
if (!method) {
await effects.setHealth({
name: healthId,
status: "failure",
message: `Expecting that thejs health check ${healthId} exists`,
id: healthId,
name: value.name,
result: "failure",
message: `Expecting that the js health check ${healthId} exists`,
})
return
}
@@ -173,24 +179,27 @@ export class MainLoop {
if ("result" in result) {
await effects.setHealth({
id: healthId,
name: value.name,
result: "success",
message: null,
name: healthId,
status: "passing",
})
return
}
if ("error" in result) {
await effects.setHealth({
name: healthId,
status: "failure",
id: healthId,
name: value.name,
result: "failure",
message: result.error,
})
return
}
if (!("error-code" in result)) {
await effects.setHealth({
name: healthId,
status: "failure",
id: healthId,
name: value.name,
result: "failure",
message: `Unknown error type ${JSON.stringify(result)}`,
})
return
@@ -198,32 +207,36 @@ export class MainLoop {
const [code, message] = result["error-code"]
if (code === 59) {
await effects.setHealth({
name: healthId,
status: "disabled",
id: healthId,
name: value.name,
result: "disabled",
message,
})
return
}
if (code === 60) {
await effects.setHealth({
name: healthId,
status: "starting",
id: healthId,
name: value.name,
result: "starting",
message,
})
return
}
if (code === 61) {
await effects.setHealth({
name: healthId,
status: "warning",
id: healthId,
name: value.name,
result: "loading",
message,
})
return
}
await effects.setHealth({
name: healthId,
status: "failure",
id: healthId,
name: value.name,
result: "failure",
message: `${result["error-code"][0]}: ${result["error-code"][1]}`,
})
return

View File

@@ -29,6 +29,7 @@ import {
import { HostSystemStartOs } from "../../HostSystemStartOs"
import { JsonPath, unNestPath } from "../../../Models/JsonPath"
import { RpcResult, matchRpcResult } from "../../RpcListener"
import { InputSpec } from "@start9labs/start-sdk/cjs/sdk/lib/config/configTypes"
type Optional<A> = A | undefined | null
function todo(): never {
@@ -259,6 +260,35 @@ export class SystemForEmbassy implements System {
): Promise<void> {
if (previousVersion) await this.migration(effects, previousVersion)
await effects.setMainStatus({ status: "stopped" })
await this.exportActions(effects)
}
async exportActions(effects: HostSystemStartOs) {
const manifest = this.manifest
if (!manifest.actions) return
for (const [actionId, action] of Object.entries(manifest.actions)) {
const hasRunning = !!action["allowed-statuses"].find(
(x) => x === "running",
)
const hasStopped = !!action["allowed-statuses"].find(
(x) => x === "stopped",
)
// prettier-ignore
const allowedStatuses = hasRunning && hasStopped ? "any":
hasRunning ? "onlyRunning" :
"onlyStopped"
await effects.exportAction({
id: actionId,
metadata: {
name: action.name,
description: action.description,
warning: action.warning || null,
input: action["input-spec"] as InputSpec,
disabled: false,
allowedStatuses,
group: null,
},
})
}
}
private async uninit(
effects: HostSystemStartOs,

View File

@@ -15,10 +15,10 @@ export function unNestPath<A extends string>(a: A): UnNestPaths<A> {
function isNestedPath(path: string): path is NestedPaths {
const paths = path.split("/")
if (paths.length !== 4) return false
if (paths[1] === "action" && (paths[3] === "run" || paths[3] === "get"))
if (paths[1] === "actions" && (paths[3] === "run" || paths[3] === "get"))
return true
if (
paths[1] === "dependencyConfig" &&
paths[1] === "dependencies" &&
(paths[3] === "query" || paths[3] === "update")
)
return true