mirror of
https://github.com/Start9Labs/start-sdk.git
synced 2026-03-26 02:11:56 +00:00
feat: Add in more options in the adding of a daemon
This commit is contained in:
@@ -19,19 +19,36 @@ export function containsAddress(x: string, port: number) {
|
||||
export async function checkPortListening(
|
||||
effects: Effects,
|
||||
port: number,
|
||||
{
|
||||
error = `Port ${port} is not listening`,
|
||||
message = `Port ${port} is available`,
|
||||
} = {},
|
||||
options: {
|
||||
errorMessage: string
|
||||
successMessage: string
|
||||
timeoutMessage?: string
|
||||
timeout?: number
|
||||
},
|
||||
): Promise<CheckResult> {
|
||||
return Promise.race<CheckResult>([
|
||||
Promise.resolve().then(async () => {
|
||||
const hasAddress =
|
||||
containsAddress(await effects.runCommand(`cat /proc/net/tcp`), port) ||
|
||||
containsAddress(await effects.runCommand("cat /proc/net/udp"), port)
|
||||
if (hasAddress) {
|
||||
return { status: "passing", message }
|
||||
return { status: "passing", message: options.successMessage }
|
||||
}
|
||||
return {
|
||||
status: "failing",
|
||||
message: error,
|
||||
message: options.errorMessage,
|
||||
}
|
||||
}),
|
||||
new Promise((resolve) => {
|
||||
setTimeout(
|
||||
() =>
|
||||
resolve({
|
||||
status: "failing",
|
||||
message:
|
||||
options.timeoutMessage || `Timeout trying to check port ${port}`,
|
||||
}),
|
||||
options.timeout ?? 1_000,
|
||||
)
|
||||
}),
|
||||
])
|
||||
}
|
||||
|
||||
@@ -13,10 +13,7 @@ type Daemon<
|
||||
command: ValidIfNoStupidEscape<Command> | [string, ...string[]]
|
||||
|
||||
ready: {
|
||||
display: null | {
|
||||
name: string
|
||||
message: string
|
||||
}
|
||||
display: string | null
|
||||
fn: () => Promise<CheckResult> | CheckResult
|
||||
trigger?: Trigger
|
||||
}
|
||||
|
||||
@@ -73,9 +73,11 @@ export type Utils<WD> = {
|
||||
) => Promise<void>
|
||||
checkPortListening(
|
||||
port: number,
|
||||
options?: {
|
||||
error?: string
|
||||
message?: string
|
||||
options: {
|
||||
errorMessage: string
|
||||
successMessage: string
|
||||
timeoutMessage?: string
|
||||
timeout?: number
|
||||
},
|
||||
): Promise<CheckResult>
|
||||
checkWebUrl(
|
||||
|
||||
Reference in New Issue
Block a user