mirror of
https://github.com/pockethost/pockethost.git
synced 2025-11-28 16:13:29 +00:00
instance idle ttl support
This commit is contained in:
parent
8f382dce79
commit
2d2ce8c309
5
.changeset/light-laws-peel.md
Normal file
5
.changeset/light-laws-peel.md
Normal file
@ -0,0 +1,5 @@
|
||||
---
|
||||
'pockethost': minor
|
||||
---
|
||||
|
||||
Enh: Added custom instance idle TTL support
|
||||
@ -33,6 +33,7 @@ export type InstanceFields<TExtra = {}> = BaseFields & {
|
||||
dev: boolean
|
||||
cname_active: boolean
|
||||
notifyMaintenanceMode: boolean
|
||||
idleTtl: number
|
||||
} & TExtra
|
||||
|
||||
export type WithUser<TUser = UserFields> = {
|
||||
|
||||
@ -0,0 +1,31 @@
|
||||
/// <reference path="../pb_data/types.d.ts" />
|
||||
migrate((db) => {
|
||||
const dao = new Dao(db)
|
||||
const collection = dao.findCollectionByNameOrId("etae8tuiaxl6xfv")
|
||||
|
||||
// add
|
||||
collection.schema.addField(new SchemaField({
|
||||
"system": false,
|
||||
"id": "gbfsfi0g",
|
||||
"name": "idleTtl",
|
||||
"type": "number",
|
||||
"required": false,
|
||||
"presentable": false,
|
||||
"unique": false,
|
||||
"options": {
|
||||
"min": null,
|
||||
"max": null,
|
||||
"noDecimal": false
|
||||
}
|
||||
}))
|
||||
|
||||
return dao.saveCollection(collection)
|
||||
}, (db) => {
|
||||
const dao = new Dao(db)
|
||||
const collection = dao.findCollectionByNameOrId("etae8tuiaxl6xfv")
|
||||
|
||||
// remove
|
||||
collection.schema.removeField("gbfsfi0g")
|
||||
|
||||
return dao.saveCollection(collection)
|
||||
})
|
||||
@ -181,13 +181,14 @@ export const instanceService = mkSingleton(
|
||||
})
|
||||
|
||||
/** Idle check */
|
||||
const idleTtl = instance.idleTtl || DAEMON_PB_IDLE_TTL()
|
||||
const idleTid = setInterval(() => {
|
||||
const lastRequestAge = now() - lastRequest
|
||||
dbg(
|
||||
`idle check: ${openRequestCount} open requests, ${lastRequestAge}ms since last request`,
|
||||
)
|
||||
if (openRequestCount === 0 && lastRequestAge > DAEMON_PB_IDLE_TTL()) {
|
||||
info(`idle for ${DAEMON_PB_IDLE_TTL()}, shutting down`)
|
||||
if (openRequestCount === 0 && lastRequestAge > idleTtl) {
|
||||
info(`idle for ${idleTtl}, shutting down`)
|
||||
userInstanceLogger.info(
|
||||
`Instance has been idle for ${DAEMON_PB_IDLE_TTL()}ms. Hibernating to conserve resources.`,
|
||||
)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user