ft build: subcollection for logs

This commit is contained in:
Bobby
2021-06-17 15:58:13 +10:00
parent af58f53b29
commit baaf859d2d
2 changed files with 14 additions and 27 deletions

View File

@@ -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;

View File

@@ -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,
// });
// }
};
}