rewrite consumer + testmode utils

This commit is contained in:
Emily
2025-02-01 15:26:26 +01:00
parent 4da840f2ec
commit 0963201a32
12 changed files with 135 additions and 40 deletions

View File

@@ -17,8 +17,7 @@
"scripts": {
"dev": "node scripts/start_dev.js",
"compile": "tsc",
"build_project": "node ../scripts/build.js",
"build": "npm run compile && npm run build_project",
"build": "npm run compile",
"docker-build": "docker build -t litlyx-producer -f Dockerfile ../",
"docker-inspect": "docker run -it litlyx-producer sh",
"workspace:shared": "ts-node ../scripts/producer/shared.ts",

View File

@@ -16,7 +16,8 @@ router.post('/keep_alive', json(jsonOptions), async (req, res) => {
const sessionHash = createSessionHash(req.body.website, ip, req.body.userAgent);
await RedisStreamService.addToStream(streamName, {
...req.body, _type: 'keep_alive', sessionHash, ip,
instant: req.body.instant + ''
instant: req.body.instant + '',
timestamp: Date.now()
});
return res.sendStatus(200);
} catch (ex: any) {
@@ -38,12 +39,14 @@ router.post('/metrics/push', json(jsonOptions), async (req, res) => {
...req.body, _type: 'visit', sessionHash, ip,
screenWidth: '0',
screenHeight: '0',
type: req.body.type.toString()
type: req.body.type.toString(),
timestamp: Date.now()
});
} else {
await RedisStreamService.addToStream(streamName, {
...req.body, _type: 'event', sessionHash, ip,
type: req.body.type.toString()
type: req.body.type.toString(),
timestamp: Date.now()
});
}

View File

@@ -22,7 +22,8 @@ app.post('/event', express.json(jsonOptions), async (req, res) => {
const sessionHash = createSessionHash(req.body.website, ip, req.body.userAgent);
const flowHash = createFlowSessionHash(req.body.pid, ip, req.body.userAgent);
await RedisStreamService.addToStream(streamName, {
...req.body, _type: 'event', sessionHash, ip, flowHash
...req.body, _type: 'event', sessionHash, ip, flowHash,
timestamp: Date.now()
});
return res.sendStatus(200);
} catch (ex: any) {
@@ -35,7 +36,7 @@ app.post('/visit', express.json(jsonOptions), async (req, res) => {
const ip = getIPFromRequest(req);
const sessionHash = createSessionHash(req.body.website, ip, req.body.userAgent);
const flowHash = createFlowSessionHash(req.body.pid, ip, req.body.userAgent);
await RedisStreamService.addToStream(streamName, { ...req.body, _type: 'visit', sessionHash, ip, flowHash });
await RedisStreamService.addToStream(streamName, { ...req.body, _type: 'visit', sessionHash, ip, flowHash, timestamp: Date.now() });
return res.sendStatus(200);
} catch (ex: any) {
return res.status(500).json({ error: ex.message });
@@ -50,7 +51,7 @@ app.post('/keep_alive', express.json(jsonOptions), async (req, res) => {
await RedisStreamService.addToStream(streamName, {
...req.body, _type: 'keep_alive', sessionHash, ip,
instant: req.body.instant + '',
flowHash
flowHash, timestamp: Date.now()
});
return res.sendStatus(200);
} catch (ex: any) {