Skip to content

Commit 90848bc

Browse files
committed
fix: also push all questions to storage
1 parent 5622dea commit 90848bc

2 files changed

Lines changed: 30 additions & 11 deletions

File tree

‎services/updater/src/index.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { updateForumStatus } from "./update_forum_status";
1010
import { updateStorage } from "./update_storage";
1111

1212
const update = async (client: FetchClient<FetchClientResponse>, logger: Logger) => {
13-
const status = await updateDatabase(client, logger);
13+
await updateDatabase(client, logger);
1414
await updateStorage(logger);
1515
await updateForumStatus(client, logger);
1616
};
Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,40 @@
11
import { getenv } from "@qnaplus/dotenv";
2-
import { getAllSeasonQuestions, getMetadata, upload } from "@qnaplus/store";
2+
import { Question } from "@qnaplus/scraper";
3+
import { getAllQuestions, getAllSeasonQuestions, getMetadata, upload } from "@qnaplus/store";
34
import { trycatch } from "@qnaplus/utils";
45
import type { Logger } from "pino";
56

7+
const update = async (logger: Logger, data: Question[], key: string) => {
8+
const json = JSON.stringify(data);
9+
const buffer = Buffer.from(json, "utf-8");
10+
const [uploadError] = await trycatch(() => upload(key, buffer, logger));
11+
if (uploadError) {
12+
logger?.error({ error: uploadError }, "Error while updating storage json");
13+
return;
14+
}
15+
logger.info("Successfully completed storage update.");
16+
}
17+
618
export const updateStorage = async (_logger: Logger) => {
719
const logger = _logger?.child({ label: "doStorageUpdate" });
820
logger.info("Starting storage update.");
9-
const [questionsError, questions] = await getAllSeasonQuestions();
21+
22+
// push all questions
23+
const [questionsError, questions] = await getAllQuestions();
1024
if (questionsError) {
1125
logger?.error(
1226
{ error: questionsError },
27+
"An error occurred while retreiving all questions from database.",
28+
);
29+
return;
30+
}
31+
await update(logger, questions, `questions-${getenv("NODE_ENV")}.json`);
32+
33+
// push current season questions
34+
const [seasonQuestionsError, seasonQuestions] = await getAllSeasonQuestions();
35+
if (seasonQuestionsError) {
36+
logger?.error(
37+
{ error: seasonQuestionsError },
1338
"An error occurred while retreiving season questions from database.",
1439
);
1540
return;
@@ -22,13 +47,7 @@ export const updateStorage = async (_logger: Logger) => {
2247
);
2348
return;
2449
}
25-
const json = JSON.stringify(questions);
26-
const buffer = Buffer.from(json, "utf-8");
27-
const key = `questions-${getenv("NODE_ENV")}.json`; // TODO: break out by season
28-
const [uploadError] = await trycatch(() => upload(key, buffer, logger));
29-
if (uploadError) {
30-
logger?.error({ error: uploadError }, "Error while updating storage json");
31-
return;
32-
}
50+
await update(logger, seasonQuestions, `questions-${getenv("NODE_ENV")}-${meta.currentSeason}.json`);
51+
3352
logger.info("Successfully completed storage update.");
3453
};

0 commit comments

Comments
 (0)