fix: upgrade sub app (#4246)

This commit is contained in:
ChengLei Shao 2024-04-30 15:38:32 +08:00 committed by GitHub
parent e5152af4c2
commit d15eab2294
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 42 additions and 7 deletions

View File

@ -13,7 +13,7 @@ describe('multiple apps', () => {
beforeEach(async () => {
app = await createMockServer({
plugins: ['multi-app-manager'],
plugins: ['nocobase', 'multi-app-manager'],
});
db = app.db;
});
@ -94,6 +94,43 @@ describe('multiple apps', () => {
expect(subAppStatus).toEqual('running');
});
it('should upgrade sub app', async () => {
await db.getRepository('applications').create({
values: {
name: 'test1',
options: {
plugins: ['nocobase'],
},
},
context: {
waitSubAppInstall: true,
},
});
await db.getRepository('applications').create({
values: {
name: 'test2',
options: {
plugins: ['nocobase'],
},
},
context: {
waitSubAppInstall: true,
},
});
await app.runCommand('restart');
await app.runCommand('upgrade');
// const subAppStatus = AppSupervisor.getInstance().getAppStatus(name);
// expect(subAppStatus).toEqual('running');
//
// const subApp = await AppSupervisor.getInstance().getApp(name);
// await subApp.runCommand('upgrade');
//
// await AppSupervisor.getInstance().removeApp(name);
// expect(await db.getRepository('applications').count()).toBe(1);
});
it('should list application with status', async () => {
const sub1 = `td_${uid()}`;
await db.getRepository('applications').create({

View File

@ -36,11 +36,8 @@ const defaultSubAppUpgradeHandle: SubAppUpgradeHandler = async (mainApp: Applica
upgrading: true,
});
console.log({ beforeSubAppStatus });
try {
mainApp.setMaintainingMessage(`upgrading sub app ${instance.name}...`);
console.log(`${instance.name}: upgrading...`);
await subApp.runAsCLI(['upgrade'], { from: 'user' });
if (!beforeSubAppStatus && AppSupervisor.getInstance().getAppStatus(instance.name) === 'initialized') {
await AppSupervisor.getInstance().removeApp(instance.name);
@ -204,7 +201,8 @@ export class PluginMultiAppManagerServer extends Plugin {
return;
}
const applicationRecord = (await self.app.db.getRepository('applications').findOne({
const mainApp = await appSupervisor.getApp('main');
const applicationRecord = (await mainApp.db.getRepository('applications').findOne({
filter: {
name,
},
@ -224,7 +222,7 @@ export class PluginMultiAppManagerServer extends Plugin {
return;
}
const subApp = applicationRecord.registerToSupervisor(self.app, {
const subApp = applicationRecord.registerToSupervisor(mainApp, {
appOptionsFactory: self.appOptionsFactory,
});
@ -234,7 +232,7 @@ export class PluginMultiAppManagerServer extends Plugin {
}
}
AppSupervisor.getInstance().setAppBootstrapper(LazyLoadApplication);
AppSupervisor.getInstance().setAppBootstrapper(LazyLoadApplication.bind(this));
Gateway.getInstance().addAppSelectorMiddleware(async (ctx, next) => {
const { req } = ctx;