request queue process modified

main
Bukxara 2 months ago
parent 652c7e3609
commit 1d8b875bf3

@ -1,5 +1,5 @@
import axios from "axios";
import express, { json, query } from "express";
import express, { json } from "express";
import Queue from "bull";
import Bottleneck from "bottleneck";
@ -8,9 +8,9 @@ app.use(json());
const requestQueue = new Queue("request-queue", {
redis: {
host: '127.0.0.1',
port: 6379
}
host: "127.0.0.1",
port: 6379,
},
});
const limiter = new Bottleneck({
@ -41,8 +41,7 @@ async function sendRequest(data) {
requestQueue.process(async (job) => {
try {
const result = await limiter.schedule(() => sendRequest(job.data));
return result;
await limiter.schedule(() => sendRequest(job.data));
} catch (error) {
throw new Error(`Request failed: ${error.message}`);
}
@ -89,7 +88,6 @@ app.get("/bot:token/*", async (req, res) => {
});
app.post("/bot:token/*", async (req, res) => {
const url = req.url;
const botTokenEndIndex = url.indexOf("/", 1);
const botToken = url.substring(4, botTokenEndIndex);
@ -112,7 +110,6 @@ app.post("/bot:token/*", async (req, res) => {
}
});
app.listen(3000, () => {
console.log("Microservice listening on port 3000");
});

Loading…
Cancel
Save