store metadata in bigquery

This commit is contained in:
Evan
2024-12-10 20:27:30 -08:00
parent 1a9170d10b
commit dfe2f27ba8
3 changed files with 12 additions and 8 deletions
+9 -7
View File
@@ -8,12 +8,6 @@ const bigquery = new BigQuery();
export async function archive(gameRecord: GameRecord) {
try {
console.log(`writing game ${gameRecord.id} to gcs`)
const bucket = storage.bucket("openfront-games");
const file = bucket.file(gameRecord.id);
await file.save(JSON.stringify(GameRecordSchema.parse(gameRecord)), {
contentType: 'application/json'
});
// Save metadata to BigQuery
const row = {
id: gameRecord.id,
@@ -34,7 +28,15 @@ export async function archive(gameRecord: GameRecord) {
.insert([row]);
console.log(`wrote game metadata to BigQuery: ${gameRecord.id}`);
if (gameRecord.turns.length > 0) {
console.log(`writing game ${gameRecord.id} to gcs`)
const bucket = storage.bucket("openfront-games");
const file = bucket.file(gameRecord.id);
await file.save(JSON.stringify(GameRecordSchema.parse(gameRecord)), {
contentType: 'application/json'
});
}
} catch (error) {
console.log(`error writing to gcs: ${error}`)
console.log(`error archiving game record: ${error}`)
}
}