Skip to content

Commit

Permalink
bulk
Browse files Browse the repository at this point in the history
  • Loading branch information
gotham13 committed Apr 8, 2024
1 parent a3a7f03 commit dac20f7
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions src/routes/queue-route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,31 @@ import queue from "../utils/queue-client";
import logstashClient from "../utils/logstash-client";
import queueBatchProcessor from "../utils/queue-batch-processor";

type logType = {
timestamp?: string;
version?: string | number;
service?: string;
application?: string;
environment?: string;
logLevel?: string;
host?: string;
message?: string;
};

setInterval(async () => {
await queueBatchProcessor(queue, logstashClient);
}, 10000);
}, 1000);

router.post("/log", async (req: Request, res: Response) => {
try {
const { log } = req.body;
const job = await queue.add(v4(), log, { removeOnComplete: true });
const { logs } = req.body;
await queue.addBulk(
logs.map((log: logType) => {
v4(), log;
})
);
res.json({
success: true,
jobId: job.id,
});
} catch (err) {
res.json({
Expand Down

0 comments on commit dac20f7

Please sign in to comment.