Skip to content

Commit

Permalink
rotor: bring back redis store when mongo is unavailable
Browse files Browse the repository at this point in the history
  • Loading branch information
absorbb committed Dec 31, 2023
1 parent e08bd1f commit 977c197
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
10 changes: 9 additions & 1 deletion libs/core-functions/src/functions/lib/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,19 @@ export const createOldStore = (namespace: string, redisClient: Redis): Store =>
},
});

export const createTtlStore = (namespace: string, redisClient: Redis, defaultTtlSec: number): Store => ({
export const createTtlStore = (namespace: string, redisClient: Redis, defaultTtlSec: number): TTLStore => ({
get: async (key: string) => {
const res = await redisClient.get(`store:${namespace}:${key}`);
return res ? JSON.parse(res) : undefined;
},
getWithTTL: async (key: string) => {
const res = await redisClient.get(`store:${namespace}:${key}`);
if (!res) {
return undefined;
}
const ttl = await redisClient.ttl(`store:${namespace}:${key}`);
return { value: JSON.parse(res), ttl };
},
set: async (key: string, obj: any, opts?: SetOpts) => {
const ttl = getTtlSec(opts);
if (ttl >= 0) {
Expand Down
10 changes: 5 additions & 5 deletions services/rotor/src/lib/message-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@ import {
mongoAnonymousEventsStore,
parseUserAgent,
SystemContext,
createTtlStore,
} from "@jitsu/core-functions";
import { redisLogger } from "./redis-logger";
import { buildFunctionChain, checkError, runChain } from "./functions-chain";
import { redis } from "@jitsu-internal/console/lib/server/redis";
export const log = getLog("rotor");

const anonymousEventsStore = mongoAnonymousEventsStore();
Expand Down Expand Up @@ -88,11 +90,9 @@ export async function rotorMessageHandler(
connectionId: connection.id,
retries,
};
const store = createMongoStore(
connection.workspaceId,
mongodb(),
fastStoreWorskpaceId.includes(connection.workspaceId)
);
const store = process.env.MONGODB_URL
? createMongoStore(connection.workspaceId, mongodb(), fastStoreWorskpaceId.includes(connection.workspaceId))
: createTtlStore(connection.workspaceId, redis(), defaultTTL);
//system context for builtin functions only
const systemContext: SystemContext = {
$system: {
Expand Down

1 comment on commit 977c197

@vercel
Copy link

@vercel vercel bot commented on 977c197 Dec 31, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

new-jitsu – ./webapps/console

ag.ru
logu.au
ozon.ru
sse.ere
erxes.io
baidu.dom
ilmiya.io
sambla.se
bobsec.com
sambla.com
agro4u.life
bluetick.ai
myilmiya.io
protontv.eu
t.quenti.io
alicesec.com
d.askloan.tw
dev.aclis.io
docs.dh19.de
docs.dh19.eu
joseviso.com
mydomain.dom
t.democo.dev
t.shoppub.io
t2.jitsu.com
timeplus.com
zoopsign.com
*.d.jitsu.com
beta.mitzu.io
d.versatus.io
data.light.so
data.loudy.co
data.schej.it
dog.jitsu.com
imusician.app
imusician.pro
jitsu.logu.au
jitsu.www1.ru
t.thequack.ai
thinkr.com.br
use.jitsu.com
usepolygon.io
www.sambla.se
ajewellers.com
data.uselog.io
gpt.whatfa.com
sidetrekai.com
t.papermark.io
t.saasmonk.app
use2.jitsu.com
w.d2.jitsu.com
www.kellen.top
*.dataspecc.com
app.bluetick.ai
caddy.jitsu.com
data.askloan.tw
enterticket.com
events.mitzu.io
ildar.jitsu.com
jitsu.efeer.com
jitsu.ivve.tech
krestomatio.com
sevenbillion.co
w2.d2.jitsu.com
xrt.webxr.tools
app.jotverse.com
caddy2.jitsu.com
cname2.jitsu.com
data.mysitee.com
data.toptere.com
dev-t.democo.dev
events.quenti.io
utils.doogma.com
worthsystems.com
data.music2me.com
data.timeplus.com
event-gateway.com
https.bluetick.ai
ji.degulesider.dk
jitsu.ivve.health
metabase.erxes.io
t.clickncruise.hu
test.d2.jitsu.com
cloud.yupaopao.com
data.investing.com
data.mycompany.com
data.usepolygon.io
demosite.jitsu.com
dev.driverdeck.app
n8n.paziresh24.com
new.enterticket.es
t-dev.papermark.io
test2.d2.jitsu.com
uniquecafes.com.br
www.sidetrekai.com
colectha.voolu.shop
crm.myguestcare.com
data.sidetrekai.com
data.timeplus.cloud
localhost.jitsu.com

Please sign in to comment.