Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 18 additions & 18 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions pnpm-workspace.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ injectWorkspacePackages: true
catalog:
pino: ^10.3.1
pino-pretty: ^13.1.3
'@qnaplus/scraper': ^3.1.6
'@qnaplus/scraper-strategies': ^3.1.6
'@qnaplus/scraper': ^3.1.7
'@qnaplus/scraper-strategies': ^3.1.7
croner: ^10.0.1
minimumReleaseAgeExclude:
- '@qnaplus/scraper-strategies@3.1.6'
- '@qnaplus/scraper@3.1.6'
- '@qnaplus/scraper-strategies@3.1.7'
- '@qnaplus/scraper@3.1.7'
- ts-curl-impersonate@2.0.0-rc.0
6 changes: 3 additions & 3 deletions scripts/build_images.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/sh
docker build --rm -t battlesquid0101/qnaplus_bot -f ./services/bot/Dockerfile .
docker build --rm -t battlesquid0101/qnaplus_updater -f ./services/updater/Dockerfile .
#!/bin/sh
docker build --rm -t battlesquid0101/qnaplus_bot -f ./services/bot/Dockerfile .
docker build --rm -t battlesquid0101/qnaplus_updater -f ./services/updater/Dockerfile .
4 changes: 2 additions & 2 deletions scripts/push_images.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/sh
docker push battlesquid0101/qnaplus_updater:latest
#!/bin/sh
docker push battlesquid0101/qnaplus_updater:latest
docker push battlesquid0101/qnaplus_bot:latest
24 changes: 19 additions & 5 deletions services/updater/scripts/update_storage.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import { disconnectPgClient, testConnection } from "@qnaplus/store";
import { disconnectPgClient, getAllQuestions, getMetadata, testConnection } from "@qnaplus/store";
import pino from "pino";
import { updateStorage } from "../src/update_storage";
import { uploadAllToStorage } from "../src/update_storage";
import { initializeEnv } from "@qnaplus/dotenv";

(async () => {
await initializeEnv();

const logger = pino({ errorKey: "error" });
logger.info("Running storage update script.");
logger.info("Testing database connection...");
Expand All @@ -11,8 +14,19 @@ import { updateStorage } from "../src/update_storage";
logger.error({ error }, "Unable to connect to database, exiting.");
return;
}
logger.info("Starting storage update.");
await updateStorage(logger);
logger.info("Storage update completed.");
logger.info("Fetching metadata and all questions from database.");
const [metadataError, metadata] = await getMetadata();
if (metadataError || !metadata) {
logger.error({ error: metadataError }, "Unable to fetch metadata from database, exiting.");
return;
}
const [questionsError, questions] = await getAllQuestions();
if (questionsError) {
logger.error({ error: questionsError }, "Unable to fetch questions from database, exiting.");
return;
}
logger.info(`Fetched ${questions.length} questions. Starting storage upload.`);
await uploadAllToStorage(questions, metadata, logger);
logger.info("Storage upload completed.");
await disconnectPgClient();
})();
22 changes: 22 additions & 0 deletions services/updater/src/update_storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,28 @@ const get = async (key: string, logger: Logger): Promise<Question[] | null> => {
return parsedData;
};

export const uploadAllToStorage = async (
questions: Question[],
{ currentSeason }: Metadata,
_logger: Logger,
) => {
const logger = _logger.child({ label: "upload_all_to_storage" });
logger.info("Starting full storage upload.");

const ALL_QUESTIONS_KEY = `questions-${getenv("NODE_ENV")}.json`;
const SEASON_QUESTIONS_KEY = `questions-${getenv("NODE_ENV")}-${currentSeason}.json`;

const seasonQuestions = questions
.filter((q) => q.season === currentSeason)
.toSorted((a, b) => Number.parseInt(b.id) - Number.parseInt(a.id));
await update(logger, seasonQuestions, SEASON_QUESTIONS_KEY);

const sortedAll = questions.toSorted((a, b) => Number.parseInt(b.id) - Number.parseInt(a.id));
await update(logger, sortedAll, ALL_QUESTIONS_KEY);

logger.info("Completed full storage upload.");
};

export const updateStorage = async (
updates: Question[],
{ currentSeason }: Metadata,
Expand Down
Loading