omni_chat: consume receiver.flow and persist inbound telegram
This commit is contained in:
@@ -1,15 +1,20 @@
|
||||
import { createServer } from "node:http";
|
||||
import { closeReceiverWorker, RECEIVER_FLOW_QUEUE_NAME, receiverQueue, startReceiverWorker } from "./worker";
|
||||
|
||||
const port = Number(process.env.PORT || 8090);
|
||||
const service = "omni_chat";
|
||||
|
||||
const server = createServer((req, res) => {
|
||||
const server = createServer(async (req, res) => {
|
||||
if (req.method === "GET" && req.url === "/health") {
|
||||
const q = receiverQueue();
|
||||
const counts = await q.getJobCounts("wait", "active", "failed", "completed", "delayed");
|
||||
await q.close();
|
||||
const payload = JSON.stringify({
|
||||
ok: true,
|
||||
service,
|
||||
receiverFlow: process.env.RECEIVER_FLOW_QUEUE_NAME || "receiver.flow",
|
||||
receiverFlow: RECEIVER_FLOW_QUEUE_NAME,
|
||||
senderFlow: process.env.SENDER_FLOW_QUEUE_NAME || "sender.flow",
|
||||
queue: counts,
|
||||
now: new Date().toISOString(),
|
||||
});
|
||||
res.statusCode = 200;
|
||||
@@ -23,14 +28,25 @@ const server = createServer((req, res) => {
|
||||
res.end(JSON.stringify({ ok: false, error: "not_found" }));
|
||||
});
|
||||
|
||||
startReceiverWorker();
|
||||
|
||||
server.listen(port, "0.0.0.0", () => {
|
||||
console.log(`[omni_chat] listening on :${port}`);
|
||||
console.log(`[omni_chat] receiver worker started for queue ${RECEIVER_FLOW_QUEUE_NAME}`);
|
||||
});
|
||||
|
||||
function shutdown(signal: string) {
|
||||
async function shutdown(signal: string) {
|
||||
console.log(`[omni_chat] shutting down by ${signal}`);
|
||||
server.close(() => process.exit(0));
|
||||
try {
|
||||
await closeReceiverWorker();
|
||||
} finally {
|
||||
server.close(() => process.exit(0));
|
||||
}
|
||||
}
|
||||
|
||||
process.on("SIGINT", () => shutdown("SIGINT"));
|
||||
process.on("SIGTERM", () => shutdown("SIGTERM"));
|
||||
process.on("SIGINT", () => {
|
||||
void shutdown("SIGINT");
|
||||
});
|
||||
process.on("SIGTERM", () => {
|
||||
void shutdown("SIGTERM");
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user