Compare commits

...

1 commit

Author SHA1 Message Date
Nicolas Meienberger
e40ffd121d WIP: Test continuous logs during install 2022-05-23 19:42:22 +00:00
3 changed files with 14 additions and 5 deletions

View file

@ -103,7 +103,10 @@ const installApp = async (req: Request, res: Response, next: NextFunction) => {
throw new Error('App name is required'); throw new Error('App name is required');
} }
await AppsService.installApp(id, form); await AppsService.installApp(id, form, (data: string) => {
console.log('Stream:', data);
res.write(data);
});
res.status(200).json({ message: 'App installed successfully' }); res.status(200).json({ message: 'App installed successfully' });
} catch (e) { } catch (e) {

View file

@ -75,15 +75,21 @@ export const checkAppExists = (appName: string) => {
} }
}; };
export const runAppScript = (params: string[]): Promise<void> => { export const runAppScript = (params: string[], processClbk?: (data: string) => void): Promise<void> => {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
runScript('/scripts/app.sh', [...params, config.ROOT_FOLDER_HOST], (err: string) => { const process = runScript('/scripts/app.sh', [...params, config.ROOT_FOLDER_HOST], (err: string) => {
if (err) { if (err) {
reject(err); reject(err);
} }
resolve(); resolve();
}); });
if (processClbk) {
process.stdout?.on('data', (data: string) => {
processClbk?.(data);
});
}
}); });
}; };

View file

@ -17,7 +17,7 @@ const startApp = async (appName: string): Promise<void> => {
ensureAppState(appName, true); ensureAppState(appName, true);
}; };
const installApp = async (id: string, form: Record<string, string>): Promise<void> => { const installApp = async (id: string, form: Record<string, string>, stdout?: (data: string) => void): Promise<void> => {
const appExists = fileExists(`/app-data/${id}`); const appExists = fileExists(`/app-data/${id}`);
if (appExists) { if (appExists) {
@ -37,7 +37,7 @@ const installApp = async (id: string, form: Record<string, string>): Promise<voi
ensureAppState(id, true); ensureAppState(id, true);
// Run script // Run script
await runAppScript(['install', id]); await runAppScript(['install', id], stdout);
} }
return Promise.resolve(); return Promise.resolve();