Tests
This commit is contained in:
@@ -489,15 +489,20 @@ async function stopManagedInstance(ctx, id) {
|
|||||||
logLine(ctx, `managed: stopped ${id}`)
|
logLine(ctx, `managed: stopped ${id}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Yield one tick so `bare-os-www` (and other writers) can finish persisting `~/.holesail/state.json`. */
|
||||||
|
function yieldForStateCoalescence() {
|
||||||
|
return new Promise((resolve) => {
|
||||||
|
if (typeof globalThis.setImmediate === 'function') globalThis.setImmediate(resolve)
|
||||||
|
else queueMicrotask(resolve)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Start every enabled connection from a fresh read of disk (used for initial start + reconcile pass).
|
||||||
* @param {Record<string, unknown>} ctx
|
* @param {Record<string, unknown>} ctx
|
||||||
* @param {Record<string, string | undefined>} env
|
* @param {Record<string, string | undefined>} env
|
||||||
*/
|
*/
|
||||||
export async function bareHolesailManagedStartService(ctx, env) {
|
async function startManagedConnectionsFromDisk(ctx, env) {
|
||||||
if (managedServiceRunning) return
|
|
||||||
|
|
||||||
managedServiceRunning = true
|
|
||||||
|
|
||||||
const { state } = await bareHolesailManagedReadState(ctx, env)
|
const { state } = await bareHolesailManagedReadState(ctx, env)
|
||||||
const idsSorted = Object.keys(state.connections).sort()
|
const idsSorted = Object.keys(state.connections).sort()
|
||||||
for (const id of idsSorted) {
|
for (const id of idsSorted) {
|
||||||
@@ -518,6 +523,20 @@ export async function bareHolesailManagedStartService(ctx, env) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {Record<string, unknown>} ctx
|
||||||
|
* @param {Record<string, string | undefined>} env
|
||||||
|
*/
|
||||||
|
export async function bareHolesailManagedStartService(ctx, env) {
|
||||||
|
if (managedServiceRunning) return
|
||||||
|
|
||||||
|
managedServiceRunning = true
|
||||||
|
|
||||||
|
await startManagedConnectionsFromDisk(ctx, env)
|
||||||
|
await yieldForStateCoalescence()
|
||||||
|
await startManagedConnectionsFromDisk(ctx, env)
|
||||||
|
|
||||||
managedHookUnsubs.push(
|
managedHookUnsubs.push(
|
||||||
ctx.bareOsRegisterSuspendHook(async () => {
|
ctx.bareOsRegisterSuspendHook(async () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user