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
+1 -1
View File
@@ -229,7 +229,7 @@
* alert on unit captured or destroyed 12/20/2024
* only check islands/clusters when being attacked DONE 12/10/2024
* only calculate name if tile changes DONE 12/10/2024
* store in BigQuery
* store in BigQuery DONE 12/10/2024
* allow longer names and allow them to be displayed in the Rank UI not be cut
* make boats work on lakes (& oceania)
* record game winner
+2
View File
@@ -53,6 +53,8 @@ export class LocalServer {
console.log('local server ending game')
clearInterval(this.endTurnIntervalID)
const record = CreateGameRecord(this.gameID, this.gameConfig, this.turns, this.startedAt, Date.now())
// Clear turns because beacon only supports up to 64kb
record.turns = []
// For unload events, sendBeacon is the only reliable method
const blob = new Blob([JSON.stringify(GameRecordSchema.parse(record))], {
type: 'application/json'
+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}`)
}
}