refactor(mothership): improve logging consistency and clarity in instance handlers

This commit is contained in:
Ben Allfree 2025-07-18 18:03:18 -07:00
parent ca0e1f14fe
commit a5fbcb7958
4 changed files with 12 additions and 9 deletions

View File

@ -6,31 +6,31 @@ export const HandleInstanceCreate = (c: echo.Context) => {
const log = mkLog(`POST:instance`)
const authRecord = c.get('authRecord') as models.Record | undefined // empty if not authenticated as regular auth record
log(`***authRecord`, JSON.stringify(authRecord))
log(`authRecord`, JSON.stringify(authRecord))
if (!authRecord) {
throw new Error(`Expected authRecord here`)
}
log(`***TOP OF POST`)
log(`TOP OF POST`)
let data = new DynamicModel({
subdomain: '',
version: versions[0],
region: 'sfo-2',
}) as { subdomain?: string; version?: string; region?: string }
log(`***before bind`)
log(`before bind`)
c.bind(data)
log(`***after bind`)
log(`after bind`)
// This is necessary for destructuring to work correctly
data = JSON.parse(JSON.stringify(data))
const { subdomain, version, region } = data
log(`***vars`, JSON.stringify({ subdomain, region }))
log(`vars`, JSON.stringify({ subdomain, region }))
if (!subdomain) {
throw new BadRequestError(`Subdomain is required when creating an instance.`)

View File

@ -1,7 +1,10 @@
import { mkLog } from '$util/Logger'
/** Migrate version numbers */
export const HandleMigrateRegions = (e: core.BootstrapEvent) => {
const dao = $app.dao()
console.log(`***Migrating regions`)
const log = mkLog(`HandleMigrateRegions`)
log(`Migrating regions`)
dao.db().newQuery(`update instances set region='sfo-1' where region=''`).execute()
log(`Migrated regions`)
}

View File

@ -25,7 +25,7 @@ export const HandleInstanceBeforeUpdate = (e: core.ModelEvent) => {
try {
dao.db().newQuery(`select id from instances where cname='${cname}' and id <> '${id}'`).one(result)
} catch (e) {
// log(`*** cname OK ${cname}`)
// log(` cname OK ${cname}`)
return false
}
return true

View File

@ -3,7 +3,7 @@ import { mkLog } from '$util/Logger'
export const HandleMetaUpdateAtBoot = (c: core.BootstrapEvent) => {
const log = mkLog('HandleMetaUpdateAtBoot')
log(`At top of HandleMetaUpdateAtBoot`)
log(`***app URL`, process.env.APP_URL)
log(`app URL`, process.env.APP_URL)
const form = new SettingsUpsertForm($app)
form.meta = {
...$app.settings().meta,