Skip to content

Commit

Permalink
Ensure coil/suspect caches are synced across processes
Browse files Browse the repository at this point in the history
  • Loading branch information
mia-pi-git committed Oct 22, 2024
1 parent 792e493 commit 1a73f75
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* By Mia
* @author mia-pi-git
*/
import {promises as fs, readFileSync} from 'fs';
import {promises as fs, readFileSync, watchFile} from 'fs';
import * as pathModule from 'path';
import * as crypto from 'crypto';
import * as url from 'url';
Expand Down Expand Up @@ -57,6 +57,16 @@ type SuspectReqs = Partial<{elo: number, gxe: number, coil: number}>;
const suspects: Record<string, {startDate: number, reqs: SuspectReqs}> = loadData(Config.suspectpath);
const coil: Record<string, number> = loadData(Config.coilpath);

if (Config.suspectpath) {
watchFile(Config.suspectpath,
() => Object.assign(suspects, loadData(Config.suspectpath))
);

Check failure on line 63 in src/actions.ts

View workflow job for this annotation

GitHub Actions / build (16.x)

Unexpected newline before ')'

Check failure on line 63 in src/actions.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

Unexpected newline before ')'
}
if (Config.coilpath) {
watchFile(Config.coilpath, () => Object.assign(coil, loadData(Config.coilpath)));
}


export const actions: {[k: string]: QueryHandler} = {
async register(params) {
this.verifyCrossDomainRequest();
Expand Down Expand Up @@ -1023,6 +1033,7 @@ export const actions: {[k: string]: QueryHandler} = {
if (!(reqs.gxe || reqs.elo || reqs.coil) || Object.values(reqs).some(x => typeof x !== 'number')) {
throw new ActionError("Invalid reqs sent.");
}
const suspects = loadData(Config.suspectpath);

Check failure on line 1036 in src/actions.ts

View workflow job for this annotation

GitHub Actions / build (16.x)

'suspects' is already declared in the upper scope on line 57 column 7

Check failure on line 1036 in src/actions.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

'suspects' is already declared in the upper scope on line 57 column 7
suspects[id] = {
startDate: time(),
reqs,
Expand Down

0 comments on commit 1a73f75

Please sign in to comment.