1
0
Fork 0
mirror of synced 2024-06-13 16:05:06 +12:00

Startup fixes

This commit is contained in:
Rory Powell 2022-10-25 13:37:26 +01:00
parent 2e52f378c7
commit 5c80b2ca06
6 changed files with 19 additions and 6 deletions

View file

@ -55,7 +55,12 @@ export const doWithLock = async (opts: LockOptions, task: any) => {
let lock
try {
// aquire lock
let name: string = `${tenancy.getTenantId()}_${opts.name}`
let name: string
if (opts.systemLock) {
name = opts.name
} else {
name = `${tenancy.getTenantId()}_${opts.name}`
}
if (opts.nameSuffix) {
name = name + `_${opts.nameSuffix}`
}

View file

@ -122,7 +122,6 @@ module.exports = server.listen(env.PORT || 0, async () => {
eventEmitter.emitPort(env.PORT)
fileSystem.init()
await redis.init()
await initPro()
// run migrations on startup if not done via http
// not recommended in a clustered environment
@ -180,8 +179,11 @@ module.exports = server.listen(env.PORT || 0, async () => {
// check for version updates
await installation.checkInstallVersion()
// done last - this will never complete
await automations.init()
// done last - these will never complete
let promises = []
promises.push(automations.init())
promises.push(initPro())
await Promise.all(promises)
})
const shutdown = () => {

View file

@ -116,8 +116,8 @@ exports.externalTrigger = async function (
exports.rebootTrigger = async () => {
// reboot cron option is only available on the main thread at
// startup and only usable in self host
if (env.isInThread() || !env.SELF_HOSTED) {
// startup and only usable in self host and single tenant environments
if (env.isInThread() || !env.SELF_HOSTED || env.MULTI_TENANCY) {
return
}
// iterate through all production apps, find the reboot crons

View file

@ -97,6 +97,7 @@ const migrateWithLock = async (options?: MigrationOptions) => {
type: LockType.TRY_ONCE,
name: LockName.MIGRATIONS,
ttl: 1000 * 60 * 15, // auto expire the migration lock after 15 minutes
systemLock: true,
},
async () => {
await migrations.runMigrations(MIGRATIONS, options)

View file

@ -28,4 +28,8 @@ export interface LockOptions {
* The suffix to add to the lock name for additional uniqueness
*/
nameSuffix?: string
/**
* This is a system-wide lock - don't use tenancy in lock key
*/
systemLock?: boolean
}

View file

@ -53,6 +53,7 @@ const migrateWithLock = async (options?: MigrationOptions) => {
type: LockType.TRY_ONCE,
name: LockName.MIGRATIONS,
ttl: 1000 * 60 * 15, // auto expire the migration lock after 15 minutes
systemLock: true,
},
async () => {
await migrations.runMigrations(MIGRATIONS, options)