Merge branch 'cchalop1-feat/restart-app-after-update' into develop

This commit is contained in:
Nicolas Meienberger 2023-11-27 07:42:43 +01:00
commit 203db0160a
2 changed files with 20 additions and 4 deletions

View file

@ -477,7 +477,7 @@ describe('Update app', () => {
it('Should correctly update app', async () => {
// arrange
const appConfig = createAppConfig({});
await insertApp({ version: 12, config: { TEST_FIELD: 'test' } }, appConfig, db);
await insertApp({ version: 12, status: 'running', config: { TEST_FIELD: 'test' } }, appConfig, db);
// act
await updateApp(appConfig.id, { version: 0 }, db);
@ -487,7 +487,7 @@ describe('Update app', () => {
expect(app).toBeDefined();
expect(app?.config).toStrictEqual({ TEST_FIELD: 'test' });
expect(app?.version).toBe(appConfig.tipi_version);
expect(app?.status).toBe('stopped');
expect(app?.status).toBe('running');
});
it("Should throw if app doesn't exist", async () => {
@ -505,6 +505,16 @@ describe('Update app', () => {
const app = await getAppById(appConfig.id, db);
expect(app?.status).toBe('stopped');
});
it('Should comme back to the previous status before the update of the app', async () => {
// arrange
const appConfig = createAppConfig({});
await insertApp({ status: 'stopped' }, appConfig, db);
// act & assert
await updateApp(appConfig.id, { version: 0 }, db);
const app = await getAppById(appConfig.id, db);
expect(app?.status).toBe('stopped');
});
});
describe('installedApps', () => {

View file

@ -341,6 +341,7 @@ export class AppServiceClass {
*/
public updateApp = async (id: string) => {
const app = await this.queries.getApp(id);
const appStatusBeforeUpdate = app?.status;
if (!app) {
throw new TranslatedError('server-messages.errors.app-not-found', { id });
@ -355,14 +356,19 @@ export class AppServiceClass {
if (success) {
const appInfo = getAppInfo(app.id, app.status);
await this.queries.updateApp(id, { status: 'running', version: appInfo?.tipi_version });
await this.queries.updateApp(id, { version: appInfo?.tipi_version });
if (appStatusBeforeUpdate === 'running') {
await this.startApp(id);
} else {
await this.queries.updateApp(id, { status: appStatusBeforeUpdate });
}
} else {
await this.queries.updateApp(id, { status: 'stopped' });
Logger.error(`Failed to update app ${id}: ${stdout}`);
throw new TranslatedError('server-messages.errors.app-failed-to-update', { id });
}
const updatedApp = await this.queries.updateApp(id, { status: 'stopped' });
const updatedApp = await this.getApp(id);
return updatedApp;
};