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

View File

@ -1,7 +1,10 @@
import { mkLog } from '$util/Logger'
/** Migrate version numbers */ /** Migrate version numbers */
export const HandleMigrateRegions = (e: core.BootstrapEvent) => { export const HandleMigrateRegions = (e: core.BootstrapEvent) => {
const dao = $app.dao() const dao = $app.dao()
const log = mkLog(`HandleMigrateRegions`)
console.log(`***Migrating regions`) log(`Migrating regions`)
dao.db().newQuery(`update instances set region='sfo-1' where region=''`).execute() 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 { try {
dao.db().newQuery(`select id from instances where cname='${cname}' and id <> '${id}'`).one(result) dao.db().newQuery(`select id from instances where cname='${cname}' and id <> '${id}'`).one(result)
} catch (e) { } catch (e) {
// log(`*** cname OK ${cname}`) // log(` cname OK ${cname}`)
return false return false
} }
return true return true

View File

@ -3,7 +3,7 @@ import { mkLog } from '$util/Logger'
export const HandleMetaUpdateAtBoot = (c: core.BootstrapEvent) => { export const HandleMetaUpdateAtBoot = (c: core.BootstrapEvent) => {
const log = mkLog('HandleMetaUpdateAtBoot') const log = mkLog('HandleMetaUpdateAtBoot')
log(`At top of 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) const form = new SettingsUpsertForm($app)
form.meta = { form.meta = {
...$app.settings().meta, ...$app.settings().meta,