mirror of
https://github.com/pockethost/pockethost.git
synced 2025-11-23 22:15:49 +00:00
feat: add timing and logging for Docker container startup in InstanceService and PocketBaseService
This commit is contained in:
parent
6bb396fd24
commit
d8a5db9384
@ -393,6 +393,10 @@ export const instanceService = mkSingleton(
|
|||||||
const start = now()
|
const start = now()
|
||||||
const api = await (instanceApis[instance.id] =
|
const api = await (instanceApis[instance.id] =
|
||||||
instanceApis[instance.id] || createInstanceApi(instance)).catch((e) => {
|
instanceApis[instance.id] || createInstanceApi(instance)).catch((e) => {
|
||||||
|
const end = now()
|
||||||
|
const duration = end - start
|
||||||
|
warn(`Container ${instance.id} failed to launch in ${duration}ms`)
|
||||||
|
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`Could not launch container. Please review your instance logs at https://app.pockethost.io/app/instances/${instance.id} or contact support at https://pockethost.io/support. [${res.locals.requestId}]`,
|
`Could not launch container. Please review your instance logs at https://app.pockethost.io/app/instances/${instance.id} or contact support at https://pockethost.io/support. [${res.locals.requestId}]`,
|
||||||
)
|
)
|
||||||
@ -400,7 +404,7 @@ export const instanceService = mkSingleton(
|
|||||||
const end = now()
|
const end = now()
|
||||||
const duration = end - start
|
const duration = end - start
|
||||||
if (duration > 200) {
|
if (duration > 200) {
|
||||||
console.log(`Container ${instance.id} launch took ${duration}ms`)
|
warn(`Container ${instance.id} launch took ${duration}ms`)
|
||||||
}
|
}
|
||||||
|
|
||||||
const endRequest = api.startRequest()
|
const endRequest = api.startRequest()
|
||||||
|
|||||||
@ -63,7 +63,7 @@ export const createPocketbaseService = async (
|
|||||||
const _spawn = async (cfg: SpawnConfig) => {
|
const _spawn = async (cfg: SpawnConfig) => {
|
||||||
const cm = createCleanupManager()
|
const cm = createCleanupManager()
|
||||||
const logger = LoggerService().create('spawn')
|
const logger = LoggerService().create('spawn')
|
||||||
const { dbg, warn, error } = logger
|
const { dbg, info, warn, error } = logger
|
||||||
|
|
||||||
const _cfg: Required<SpawnConfig> = {
|
const _cfg: Required<SpawnConfig> = {
|
||||||
version: maxVersion,
|
version: maxVersion,
|
||||||
@ -109,6 +109,12 @@ export const createPocketbaseService = async (
|
|||||||
let stopped = false
|
let stopped = false
|
||||||
let stopping = false
|
let stopping = false
|
||||||
|
|
||||||
|
// Add timing for container startup
|
||||||
|
const containerStartTime = Date.now()
|
||||||
|
info(
|
||||||
|
`[${instanceId}] Starting Docker container creation at ${new Date(containerStartTime).toISOString()}`,
|
||||||
|
)
|
||||||
|
|
||||||
const container = await new Promise<{
|
const container = await new Promise<{
|
||||||
on: EventEmitter['on']
|
on: EventEmitter['on']
|
||||||
kill: () => Promise<void>
|
kill: () => Promise<void>
|
||||||
@ -218,6 +224,16 @@ export const createPocketbaseService = async (
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
.on('start', async (container: Container) => {
|
.on('start', async (container: Container) => {
|
||||||
|
const containerReadyTime = Date.now()
|
||||||
|
const startupDuration = containerReadyTime - containerStartTime
|
||||||
|
|
||||||
|
info(
|
||||||
|
`[${instanceId}] Docker container started at ${new Date(containerReadyTime).toISOString()}`,
|
||||||
|
)
|
||||||
|
info(
|
||||||
|
`[${instanceId}] Container startup time: ${startupDuration}ms (${(startupDuration / 1000).toFixed(2)}s)`,
|
||||||
|
)
|
||||||
|
|
||||||
dbg(`Got started container`, container)
|
dbg(`Got started container`, container)
|
||||||
started = true
|
started = true
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user