Merge branch 'master' of github.com:Budibase/budibase into fix/some-potential-app-migration-issues
This commit is contained in:
commit
a40baf5111
4 changed files with 42 additions and 19 deletions
|
@ -1,4 +1,4 @@
|
||||||
import queue from "./queue"
|
import { getAppMigrationQueue } from "./queue"
|
||||||
import { Next } from "koa"
|
import { Next } from "koa"
|
||||||
import { getAppMigrationVersion } from "./appMigrationMetadata"
|
import { getAppMigrationVersion } from "./appMigrationMetadata"
|
||||||
import { MIGRATIONS } from "./migrations"
|
import { MIGRATIONS } from "./migrations"
|
||||||
|
@ -40,8 +40,10 @@ export async function checkMissingMigrations(
|
||||||
) {
|
) {
|
||||||
const currentVersion = await getAppMigrationVersion(appId)
|
const currentVersion = await getAppMigrationVersion(appId)
|
||||||
const latestMigration = getLatestEnabledMigrationId()
|
const latestMigration = getLatestEnabledMigrationId()
|
||||||
|
const queue = getAppMigrationQueue()
|
||||||
|
|
||||||
if (
|
if (
|
||||||
|
queue &&
|
||||||
latestMigration &&
|
latestMigration &&
|
||||||
getTimestamp(currentVersion) < getTimestamp(latestMigration)
|
getTimestamp(currentVersion) < getTimestamp(latestMigration)
|
||||||
) {
|
) {
|
||||||
|
|
|
@ -4,9 +4,22 @@ import { MIGRATIONS } from "./migrations"
|
||||||
import { processMigrations } from "./migrationsProcessor"
|
import { processMigrations } from "./migrationsProcessor"
|
||||||
import { apiEnabled } from "../features"
|
import { apiEnabled } from "../features"
|
||||||
|
|
||||||
const MAX_ATTEMPTS = 3
|
const MAX_ATTEMPTS = 1
|
||||||
|
|
||||||
const appMigrationQueue = queue.createQueue(queue.JobQueue.APP_MIGRATION, {
|
export type AppMigrationJob = {
|
||||||
|
appId: string
|
||||||
|
}
|
||||||
|
|
||||||
|
let appMigrationQueue: queue.Queue<AppMigrationJob> | undefined
|
||||||
|
|
||||||
|
export function init() {
|
||||||
|
// only run app migrations in main API services
|
||||||
|
if (!apiEnabled()) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
appMigrationQueue = queue.createQueue<AppMigrationJob>(
|
||||||
|
queue.JobQueue.APP_MIGRATION,
|
||||||
|
{
|
||||||
jobOptions: {
|
jobOptions: {
|
||||||
attempts: MAX_ATTEMPTS,
|
attempts: MAX_ATTEMPTS,
|
||||||
removeOnComplete: true,
|
removeOnComplete: true,
|
||||||
|
@ -18,11 +31,10 @@ const appMigrationQueue = queue.createQueue(queue.JobQueue.APP_MIGRATION, {
|
||||||
`App migration failed, queue job ID: ${job.id} - reason: ${job.failedReason}`
|
`App migration failed, queue job ID: ${job.id} - reason: ${job.failedReason}`
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
})
|
}
|
||||||
|
)
|
||||||
|
|
||||||
// only run app migrations in main API services
|
return appMigrationQueue.process(processMessage)
|
||||||
if (apiEnabled()) {
|
|
||||||
appMigrationQueue.process(processMessage)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function processMessage(job: Job) {
|
async function processMessage(job: Job) {
|
||||||
|
@ -31,4 +43,6 @@ async function processMessage(job: Job) {
|
||||||
await processMigrations(appId, MIGRATIONS)
|
await processMigrations(appId, MIGRATIONS)
|
||||||
}
|
}
|
||||||
|
|
||||||
export default appMigrationQueue
|
export function getAppMigrationQueue() {
|
||||||
|
return appMigrationQueue
|
||||||
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@ import { KoaAdapter } from "@bull-board/koa"
|
||||||
import { queue } from "@budibase/backend-core"
|
import { queue } from "@budibase/backend-core"
|
||||||
import * as automation from "../threads/automation"
|
import * as automation from "../threads/automation"
|
||||||
import { backups } from "@budibase/pro"
|
import { backups } from "@budibase/pro"
|
||||||
|
import { getAppMigrationQueue } from "../appMigrations/queue"
|
||||||
import { createBullBoard } from "@bull-board/api"
|
import { createBullBoard } from "@bull-board/api"
|
||||||
import BullQueue from "bull"
|
import BullQueue from "bull"
|
||||||
|
|
||||||
|
@ -16,10 +17,14 @@ const PATH_PREFIX = "/bulladmin"
|
||||||
export async function init() {
|
export async function init() {
|
||||||
// Set up queues for bull board admin
|
// Set up queues for bull board admin
|
||||||
const backupQueue = backups.getBackupQueue()
|
const backupQueue = backups.getBackupQueue()
|
||||||
|
const appMigrationQueue = getAppMigrationQueue()
|
||||||
const queues = [automationQueue]
|
const queues = [automationQueue]
|
||||||
if (backupQueue) {
|
if (backupQueue) {
|
||||||
queues.push(backupQueue)
|
queues.push(backupQueue)
|
||||||
}
|
}
|
||||||
|
if (appMigrationQueue) {
|
||||||
|
queues.push(appMigrationQueue)
|
||||||
|
}
|
||||||
const adapters = []
|
const adapters = []
|
||||||
const serverAdapter: any = new KoaAdapter()
|
const serverAdapter: any = new KoaAdapter()
|
||||||
for (let queue of queues) {
|
for (let queue of queues) {
|
||||||
|
|
|
@ -15,6 +15,7 @@ import * as fileSystem from "../utilities/fileSystem"
|
||||||
import { default as eventEmitter, init as eventInit } from "../events"
|
import { default as eventEmitter, init as eventInit } from "../events"
|
||||||
import * as migrations from "../migrations"
|
import * as migrations from "../migrations"
|
||||||
import * as bullboard from "../automations/bullboard"
|
import * as bullboard from "../automations/bullboard"
|
||||||
|
import * as appMigrations from "../appMigrations/queue"
|
||||||
import * as pro from "@budibase/pro"
|
import * as pro from "@budibase/pro"
|
||||||
import * as api from "../api"
|
import * as api from "../api"
|
||||||
import sdk from "../sdk"
|
import sdk from "../sdk"
|
||||||
|
@ -114,6 +115,7 @@ export async function startup(
|
||||||
// configure events to use the pro audit log write
|
// configure events to use the pro audit log write
|
||||||
// can't integrate directly into backend-core due to cyclic issues
|
// can't integrate directly into backend-core due to cyclic issues
|
||||||
queuePromises.push(events.processors.init(pro.sdk.auditLogs.write))
|
queuePromises.push(events.processors.init(pro.sdk.auditLogs.write))
|
||||||
|
queuePromises.push(appMigrations.init())
|
||||||
if (automationsEnabled()) {
|
if (automationsEnabled()) {
|
||||||
queuePromises.push(automations.init())
|
queuePromises.push(automations.init())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue