chore: Simplify the state into one

This commit is contained in:
J H
2024-03-06 09:38:55 -07:00
parent 88028412bd
commit 093a5d4ddf
8 changed files with 174 additions and 153 deletions

View File

@@ -2,6 +2,7 @@ import { types as T, util, EmVer } from "@start9labs/start-sdk"
import * as fs from "fs/promises"
import { PolyfillEffects } from "./polyfillEffects"
import { Duration, duration } from "../../../Models/Duration"
import { ExecuteResult, System } from "../../../Interfaces/System"
import { matchManifest, Manifest, Procedure } from "./matchManifest"
import { create } from "domain"
@@ -202,7 +203,7 @@ export class SystemForEmbassy implements System {
private async mainStop(
effects: HostSystemStartOs,
options?: { timeout?: number },
): Promise<void> {
): Promise<Duration> {
const { currentRunning } = this
delete this.currentRunning
if (currentRunning) {
@@ -210,6 +211,7 @@ export class SystemForEmbassy implements System {
timeout: options?.timeout || this.manifest.main["sigterm-timeout"],
})
}
return duration(this.manifest.main["sigterm-timeout"], "s")
}
private async createBackup(effects: HostSystemStartOs): Promise<void> {
const backup = this.manifest.backup.create

View File

@@ -4,6 +4,7 @@ import { string } from "ts-matches"
import { HostSystemStartOs } from "../HostSystemStartOs"
import { Effects } from "../../Models/Effects"
import { RpcResult } from "../RpcListener"
import { duration } from "../../Models/Duration"
const LOCATION = "/usr/lib/startos/package/startos"
export class SystemForStartOs implements System {
private onTerm: (() => Promise<void>) | undefined
@@ -82,7 +83,7 @@ export class SystemForStartOs implements System {
await effects.setMainStatus({ status: "stopped" })
if (this.onTerm) await this.onTerm()
delete this.onTerm
return
return duration(30, "s")
}
case "/config/set": {
const path = `${LOCATION}/procedures/config`

View File

@@ -0,0 +1,6 @@
export type TimeUnit = "d" | "h" | "s" | "ms"
export type Duration = `${number}${TimeUnit}`
export function duration(timeValue: number, timeUnit: TimeUnit = "s") {
return `${timeValue}${timeUnit}` as Duration
}