Skip to content

Commit 6e12d8e

Browse files
feature(entitlements): leader election for entitlements client cache update
1 parent 3ec0c67 commit 6e12d8e

26 files changed

Lines changed: 1252 additions & 119 deletions

package-lock.json

Lines changed: 112 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
"axios": "^0.27.2",
2828
"jsonwebtoken": "^9.0.0",
2929
"node-cache": "^5.1.2",
30+
"tiny-typed-emitter": "^2.1.0",
3031
"winston": "^3.8.2"
3132
},
3233
"peerDependencies": {
@@ -46,10 +47,9 @@
4647
"@semantic-release/git": "^10.0.1",
4748
"@types/axios-mock-adapter": "^1.10.0",
4849
"@types/express": "^4.17.14",
49-
"@types/ioredis": "^5.0.0",
5050
"@types/jest": "^29.2.0",
5151
"@types/jsonwebtoken": "^9.0.0",
52-
"@types/node": "^12.20.55",
52+
"@types/node": "^13.13.52",
5353
"@types/sinon": "^10.0.15",
5454
"@typescript-eslint/eslint-plugin": "^5.38.1",
5555
"@typescript-eslint/parser": "^5.38.1",
@@ -68,6 +68,7 @@
6868
"semantic-release": "^21.0.5",
6969
"sinon": "^15.2.0",
7070
"ts-jest": "^28.0.8",
71+
"ts-node": "^10.9.1",
7172
"typescript": "^4.8.4"
7273
}
7374
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { EntitlementsClient } from './entitlements-client';
2+
import { FronteggContext } from '../../components/frontegg-context';
3+
import Logger from '../../components/logger';
4+
5+
const instanceId = process.argv[2] || `rnd-${0 + Math.floor(Math.random() * 100)}`;
6+
7+
Logger.info(`Starting with instance ID: [${instanceId}]`);
8+
9+
FronteggContext.init(
10+
{
11+
FRONTEGG_CLIENT_ID: process.env.FRONTEGG_CLIENT_ID!,
12+
FRONTEGG_API_KEY: process.env.FRONTEGG_API_KEY!,
13+
},
14+
{
15+
cache: {
16+
type: 'redis',
17+
options: {
18+
url: 'redis://localhost:36279',
19+
},
20+
},
21+
},
22+
);
23+
24+
EntitlementsClient.init(undefined, {
25+
instanceId,
26+
leaderElection: {
27+
expireInMs: 10000,
28+
prolongLeadershipIntervalMs: 7000,
29+
key: 'my-app-leadership',
30+
},
31+
}).then((client) => {
32+
process.on('SIGTERM', () => {
33+
Logger.info(`Closing app [${instanceId}]`);
34+
35+
client.destroy();
36+
});
37+
});

src/clients/entitlements/entitlements-client.events.ts renamed to src/clients/entitlements/entitlements-client-events.enum.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export enum EntitlementsClientEvents {
1+
export enum EntitlementsClientEventsEnum {
22
INITIALIZED = 'initialized',
33
SNAPSHOT_UPDATED = 'snapshot-updated',
44
}

0 commit comments

Comments
 (0)