Skip to content

Commit b9330e1

Browse files
committed
make mongodb optional again
1 parent e5db1d8 commit b9330e1

File tree

6 files changed

+12
-7
lines changed

6 files changed

+12
-7
lines changed

libs/core-functions/src/functions/lib/store.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import type { Redis } from "ioredis";
33
import parse from "parse-duration";
44
import { MongoClient, ReadPreference, Collection } from "mongodb";
55
import { RetryError } from "@jitsu/functions-lib";
6+
import { Singleton } from "juava";
67

78
export const defaultTTL = 60 * 60 * 24 * 31; // 31 days
89
export const maxAllowedTTL = 2147483647; // max allowed value for ttl in redis (68years)
@@ -64,7 +65,7 @@ const MongoCreatedCollections: Record<string, Collection<StoreValue>> = {};
6465

6566
export const createMongoStore = (
6667
namespace: string,
67-
mongo: MongoClient,
68+
mongo: Singleton<MongoClient>,
6869
useLocalCache: boolean,
6970
fast: boolean
7071
): TTLStore => {
@@ -87,7 +88,7 @@ export const createMongoStore = (
8788
return collection;
8889
}
8990
try {
90-
const db = mongo.db(dbName);
91+
const db = mongo().db(dbName);
9192

9293
const col = db.collection<StoreValue>(namespace);
9394
const collStatus = await col

services/profiles/src/lib/functions-chain.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ export function buildFunctionChain(
6262
fetchTimeoutMs: number = 2000
6363
): FuncChain {
6464
const pbLongId = `${profileBuilder.workspaceId}-${profileBuilder.id}-v${profileBuilder.version}`;
65-
const store = createMongoStore(profileBuilder.workspaceId, mongodb(), false, true);
65+
const store = createMongoStore(profileBuilder.workspaceId, mongodb, false, true);
6666

6767
const chainCtx: FunctionChainContext = {
6868
fetch: makeFetch(profileBuilder.id, eventsLogger, "info", fetchTimeoutMs),

services/rotor/src/http/profiles-udf.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const log = getLog("profile-udf-run");
66
export const ProfileUDFRunHandler = async (req, res) => {
77
const body = req.body as ProfileUDFTestRequest;
88
log.atInfo().log(`Running profile func: ${body?.id} workspace: ${body?.workspaceId}`, JSON.stringify(body));
9-
body.store = createMongoStore(body?.workspaceId, mongodb(), true, false);
9+
body.store = createMongoStore(body?.workspaceId, mongodb, true, false);
1010
const result = await ProfileUDFTestRun(body);
1111
if (result.error) {
1212
log

services/rotor/src/http/udf.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const log = getLog("udf_run");
66
export const UDFRunHandler = async (req, res) => {
77
const body = req.body as UDFTestRequest;
88
log.atInfo().log(`Running function: ${body?.functionId} workspace: ${body?.workspaceId}`, JSON.stringify(body));
9-
body.store = createMongoStore(body?.workspaceId, mongodb(), true, false);
9+
body.store = createMongoStore(body?.workspaceId, mongodb, true, false);
1010
const result = await UDFTestRun(body);
1111
if (result.error) {
1212
log

services/rotor/src/index.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,11 @@ async function main() {
5656
let redisClient: Redis | undefined;
5757
try {
5858
Prometheus.collectDefaultMetrics();
59-
await mongodb.waitInit();
59+
try {
60+
await mongodb.waitInit();
61+
} catch (e: any) {
62+
log.atWarn().log("Failed to connect to mongodb. Functions Persistent Store won't work: " + e.message);
63+
}
6064
if (process.env.CLICKHOUSE_HOST || process.env.CLICKHOUSE_URL) {
6165
eventsLogger = createClickhouseLogger();
6266
} else {

services/rotor/src/lib/functions-chain.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ export function buildFunctionChain(
137137
if (!store) {
138138
store = createMongoStore(
139139
connection.workspaceId,
140-
mongodb(),
140+
mongodb,
141141
false,
142142
fastStoreWorkspaceId.includes(connection.workspaceId)
143143
);

0 commit comments

Comments
 (0)