From baaf859d2d432e20ab59a5d143a7a542944dacda Mon Sep 17 00:00:00 2001 From: Bobby Date: Thu, 17 Jun 2021 15:58:13 +1000 Subject: [PATCH] ft build: subcollection for logs --- ft_build/index.ts | 6 +++--- ft_build/utils.ts | 35 +++++++++++------------------------ 2 files changed, 14 insertions(+), 27 deletions(-) diff --git a/ft_build/index.ts b/ft_build/index.ts index 43a2bec4..5e811f68 100644 --- a/ft_build/index.ts +++ b/ft_build/index.ts @@ -88,8 +88,8 @@ app.post("/", jsonParser, async (req: any, res: any) => { }); } - const streamLogger = createStreamLogger(configPath, Date.now()); - streamLogger("streamLogger created"); + const streamLogger = await createStreamLogger(configPath, Date.now()); + await streamLogger("streamLogger created"); const success = await generateConfig(configPath, user, streamLogger); if (!success) { @@ -100,7 +100,7 @@ app.post("/", jsonParser, async (req: any, res: any) => { }); return; } - streamLogger("generateConfig success"); + await streamLogger("generateConfig success"); let hasEnvError = false; diff --git a/ft_build/utils.ts b/ft_build/utils.ts index c8db993c..a0caef8b 100644 --- a/ft_build/utils.ts +++ b/ft_build/utils.ts @@ -93,39 +93,26 @@ function parseSparksConfig( return "[]"; } -function createStreamLogger( +async function createStreamLogger( tableConfigPath: string, startTimeStamp: number - // emitFn ) { const fullLog: string[] = []; - console.log("socketLogger created"); + const logRef = db + .doc(tableConfigPath) + .collection("ftBuildLogs") + .doc(startTimeStamp.toString()); + await logRef.set({ startTimeStamp }); + console.log( + `streamLogger created. tableConfigPath: ${tableConfigPath}, startTimeStamp: ${startTimeStamp}` + ); return async (log: string) => { console.log(log); fullLog.push(log); - await db.doc(tableConfigPath).update({ - ftBuild: { - log, - tableConfigPath, - startTimeStamp, - fullLog, - }, + await logRef.update({ + fullLog, }); - // if (!emitFn) { - // // await logErrorToDB({ - // // errorDescription: `Invalid socket (${configPath})`, - // // user, - // // }); - // } else { - // fullLog.push(log); - // emitFn("log", { - // log, - // tableConfigPath, - // startTimeStamp, - // fullLog, - // }); - // } }; }