Skip to content

Commit 7b457df

Browse files
committed
Add invalidation to manifest script and adjust resign and timeout functions to call applyMove functions if game isn't over.
1 parent 188ca3c commit 7b457df

File tree

4 files changed

+25
-137
lines changed

4 files changed

+25
-137
lines changed

api/abstractplay.ts

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3397,12 +3397,9 @@ function resign(userid: any, engine: GameBase, game: FullGame) {
33973397
const flags = gameinfo.get(game.metaGame).flags;
33983398
const simultaneous = flags !== undefined && flags.includes('simultaneous');
33993399
if (simultaneous) {
3400-
game.toMove = game.players.map((p, i) => ! (engine as GameBaseSimultaneous).isEliminated(i + 1));
3400+
applySimultaneousMove(userid, "resign", engine as GameBaseSimultaneous, game);
34013401
} else {
3402-
if ( (! ("currplayer" in engine)) || (engine.currplayer === undefined) || (engine.currplayer === null) || (typeof engine.currplayer !== "number") ) {
3403-
throw new Error("The engine must provide a current player for `applyMove()` to be able to function.");
3404-
}
3405-
game.toMove = `${engine.currplayer - 1}`;
3402+
applyMove(userid, "resign", engine, game, flags);
34063403
}
34073404
}
34083405
}
@@ -3443,12 +3440,9 @@ function timeout(userid: string, engine: GameBase|GameBaseSimultaneous, game: Fu
34433440
const flags = gameinfo.get(game.metaGame).flags;
34443441
const simultaneous = flags !== undefined && flags.includes('simultaneous');
34453442
if (simultaneous) {
3446-
game.toMove = game.players.map((p, i) => ! (engine as GameBaseSimultaneous).isEliminated(i + 1));
3443+
applySimultaneousMove(userid, "timeout", engine as GameBaseSimultaneous, game);
34473444
} else {
3448-
if ( (! ("currplayer" in engine)) || (engine.currplayer === undefined) || (engine.currplayer === null) || (typeof engine.currplayer !== "number") ) {
3449-
throw new Error("The engine must provide a current player for `applyMove()` to be able to function.");
3450-
}
3451-
game.toMove = `${engine.currplayer - 1}`;
3445+
applyMove(userid, "timeout", engine, game, flags);
34523446
}
34533447
}
34543448
}

utils/records-manifest.ts

Lines changed: 21 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,79 +1,13 @@
11
'use strict';
22

3-
import { S3Client, GetObjectCommand, ListObjectsV2Command, PutObjectCommand, type _Object } from "@aws-sdk/client-s3";
3+
import { S3Client, ListObjectsV2Command, PutObjectCommand, type _Object } from "@aws-sdk/client-s3";
4+
import { CloudFrontClient, CreateInvalidationCommand, type CreateInvalidationCommandInput } from "@aws-sdk/client-cloudfront";
45
import { Handler } from "aws-lambda";
5-
import { GameFactory } from '@abstractplay/gameslib';
6-
import { type APGameRecord } from '@abstractplay/recranks';
7-
import { gunzipSync, strFromU8 } from "fflate";
8-
import { load } from "ion-js";
96

107
const REGION = "us-east-1";
118
const s3 = new S3Client({region: REGION});
12-
const DUMP_BUCKET = "abstractplay-db-dump";
139
const REC_BUCKET = "records.abstractplay.com";
14-
15-
type BasicRec = {
16-
Item: {
17-
pk: string;
18-
sk: string;
19-
[key: string]: any;
20-
}
21-
}
22-
23-
type GameRec = {
24-
pk: string;
25-
sk: string;
26-
id: string;
27-
metaGame: string;
28-
state: string;
29-
pieInvoked?: boolean;
30-
players: {
31-
name: string;
32-
id: string;
33-
time: number;
34-
}[];
35-
tournament?: string;
36-
event?: string;
37-
[key: string]: any;
38-
}
39-
40-
type Tournament = {
41-
pk: string;
42-
sk: string;
43-
id: string;
44-
metaGame: string;
45-
variants: string[];
46-
number: number;
47-
started: boolean;
48-
dateCreated: number;
49-
datePreviousEnded: number; // 0 means either the first tournament or a restart of the series (after it stopped because not enough participants), 3000000000000 means previous tournament still running.
50-
[key: string]: any;
51-
};
52-
53-
type OrgEvent = {
54-
pk: "ORGEVENT";
55-
sk: string; // <eventid>
56-
name: string;
57-
description: string;
58-
organizer: string;
59-
dateStart: number;
60-
dateEnd?: number;
61-
winner?: string[];
62-
visible: boolean;
63-
}
64-
65-
type OrgEventGame = {
66-
pk: "ORGEVENTGAME";
67-
sk: string; // <eventid>#<gameid>
68-
metaGame: string;
69-
variants?: string[];
70-
round: number;
71-
gameid: string;
72-
player1: string;
73-
player2: string;
74-
winner?: number[];
75-
arbitrated?: boolean;
76-
};
10+
const cloudfront = new CloudFrontClient({region: REGION});
7711

7812
export const handler: Handler = async (event: any, context?: any) => {
7913
// generate file listing
@@ -109,5 +43,23 @@ export const handler: Handler = async (event: any, context?: any) => {
10943
}
11044
console.log("Manifest generated");
11145

46+
// invalidate CloudFront distribution
47+
const cfParams: CreateInvalidationCommandInput = {
48+
DistributionId: "EM4FVU08T5188",
49+
InvalidationBatch: {
50+
CallerReference: Date.now().toString(),
51+
Paths: {
52+
Quantity: 1,
53+
Items: ["/*"],
54+
},
55+
},
56+
};
57+
const cfCmd = new CreateInvalidationCommand(cfParams);
58+
const cfResponse = await cloudfront.send(cfCmd);
59+
if (cfResponse["$metadata"].httpStatusCode !== 200) {
60+
console.log(cfResponse);
61+
}
62+
console.log("Invalidation sent");
63+
11264
console.log("ALL DONE");
11365
};

utils/records-ttm.ts

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -36,44 +36,6 @@ type GameRec = {
3636
[key: string]: any;
3737
}
3838

39-
type Tournament = {
40-
pk: string;
41-
sk: string;
42-
id: string;
43-
metaGame: string;
44-
variants: string[];
45-
number: number;
46-
started: boolean;
47-
dateCreated: number;
48-
datePreviousEnded: number; // 0 means either the first tournament or a restart of the series (after it stopped because not enough participants), 3000000000000 means previous tournament still running.
49-
[key: string]: any;
50-
};
51-
52-
type OrgEvent = {
53-
pk: "ORGEVENT";
54-
sk: string; // <eventid>
55-
name: string;
56-
description: string;
57-
organizer: string;
58-
dateStart: number;
59-
dateEnd?: number;
60-
winner?: string[];
61-
visible: boolean;
62-
}
63-
64-
type OrgEventGame = {
65-
pk: "ORGEVENTGAME";
66-
sk: string; // <eventid>#<gameid>
67-
metaGame: string;
68-
variants?: string[];
69-
round: number;
70-
gameid: string;
71-
player1: string;
72-
player2: string;
73-
winner?: number[];
74-
arbitrated?: boolean;
75-
};
76-
7739
export const handler: Handler = async (event: any, context?: any) => {
7840
// scan bucket for data folder
7941
const command = new ListObjectsV2Command({

utils/summarize.ts

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// tslint:disable: no-console
22
import { S3Client, GetObjectCommand, PutObjectCommand } from "@aws-sdk/client-s3";
3-
import { CloudFrontClient, CreateInvalidationCommand, type CreateInvalidationCommandInput } from "@aws-sdk/client-cloudfront";
43
import { DynamoDBClient } from '@aws-sdk/client-dynamodb';
54
import { DynamoDBDocumentClient, QueryCommand } from '@aws-sdk/lib-dynamodb';
65
import { isoToCountryCode } from "../lib/isoToCountryCode";
@@ -11,7 +10,6 @@ import { replacer } from "@abstractplay/gameslib/build/src/common";
1110

1211
const REGION = "us-east-1";
1312
const s3 = new S3Client({region: REGION});
14-
const cloudfront = new CloudFrontClient({region: REGION});
1513
const REC_BUCKET = "records.abstractplay.com";
1614
const clnt = new DynamoDBClient({ region: REGION });
1715
const marshallOptions = {
@@ -728,23 +726,5 @@ export const handler: Handler = async (event: any, context?: any) => {
728726
}
729727

730728
console.log("Analysis complete");
731-
732-
// invalidate CloudFront distribution
733-
const cfParams: CreateInvalidationCommandInput = {
734-
DistributionId: "EM4FVU08T5188",
735-
InvalidationBatch: {
736-
CallerReference: Date.now().toString(),
737-
Paths: {
738-
Quantity: 1,
739-
Items: ["/*"],
740-
},
741-
},
742-
};
743-
const cfCmd = new CreateInvalidationCommand(cfParams);
744-
const cfResponse = await cloudfront.send(cfCmd);
745-
if (cfResponse["$metadata"].httpStatusCode !== 200) {
746-
console.log(cfResponse);
747-
}
748-
console.log("Invalidation sent");
749729
}
750730
}

0 commit comments

Comments
 (0)