Skip to content

Commit

Permalink
chore: use sentinel
Browse files Browse the repository at this point in the history
  • Loading branch information
Timeraa committed Dec 27, 2023
1 parent 4ca09ec commit 0a3d8cb
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
4 changes: 3 additions & 1 deletion apps/master/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ export const redis = createClient({
}),
mainLog = debug("API-Master");

redis.on("error", err => console.log(err.message));
redis.on("error", err => {
throw err;
});

debug.enable("API-Master*");

Expand Down
12 changes: 10 additions & 2 deletions apps/worker/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import { resolvers as v4Resolvers } from "./v4/resolvers";
import { typeDefs as v4TypeDefs } from "./v4/typeDefinition";

if (process.env.NODE_ENV !== "production")
require("dotenv").config({ path: "../../.env" });
require("dotenv").config({ path: "../../../.env" });

if (process.env.SENTRY_DSN)
Sentry.init({
Expand All @@ -45,7 +45,15 @@ if (process.env.SENTRY_DSN)
export const mongodb = new MongoClient(process.env.MONGO_URL!, {
appName: "PreMiD-API-Worker"
}),
redis = new Redis(process.env.REDIS_URL || "localhost"),
redis = new Redis({
sentinels: [
{
host: process.env.REDIS_HOST || "localhost",
port: parseInt(process.env.REDIS_PORT || "26379")
}
],
name: "mymaster"
}),
baseRedisCache = new BaseRedisCache({
//@ts-ignore
client: redis
Expand Down
5 changes: 3 additions & 2 deletions apps/worker/src/util/dataSources.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Db } from "mongodb";

import { mongodb } from "..";
import { mongodb, redis } from "..";
import { FFUpdates } from "../generic/ffUpdates";
import { Benefits } from "../v3/fields/benefits";
import { BetaUsers } from "../v3/fields/betaUsers";
Expand All @@ -15,14 +15,15 @@ import { Sponsors } from "../v3/fields/sponsors";
import { Usage } from "../v3/fields/usage";
import { Versions } from "../v3/fields/versions";
import { Strings } from "../v4/fields/strings";
import KeyvRedis from "@keyv/redis";

export let pmdDb: Db, dSources: ReturnType<typeof dataSources>;

export default function dataSources() {
pmdDb = mongodb.db("PreMiD");

const keyvDefaultOptions = {
uri: process.env.REDIS_URL || "redis://localhost:6379",
store: new KeyvRedis(redis),
ttl: 60 * 1000
};

Expand Down

0 comments on commit 0a3d8cb

Please sign in to comment.