Support Clickhouse insert without Kafka.

This commit is contained in:
Mike Cao 2024-07-04 20:30:15 -07:00
parent d501410a63
commit 9bf34bd5e4
3 changed files with 23 additions and 4 deletions

View file

@ -1,5 +1,6 @@
import { EVENT_NAME_LENGTH, URL_LENGTH, EVENT_TYPE, PAGE_TITLE_LENGTH } from 'lib/constants';
import { CLICKHOUSE, PRISMA, runQuery } from 'lib/db';
import clickhouse from 'lib/clickhouse';
import kafka from 'lib/kafka';
import prisma from 'lib/prisma';
import { uuid } from 'lib/crypto';
@ -134,6 +135,7 @@ async function clickhouseQuery(data: {
city,
...args
} = data;
const { insert } = clickhouse;
const { getDateFormat, sendMessage } = kafka;
const eventId = uuid();
const createdAt = getDateFormat(new Date());
@ -164,7 +166,11 @@ async function clickhouseQuery(data: {
created_at: createdAt,
};
await sendMessage(message, 'event');
if (kafka.enabled) {
await sendMessage(message, 'event');
} else {
await insert('website_event', [message]);
}
if (eventData) {
await saveEventData({