grist-data-gateway/data_worker.js
2025-09-07 15:03:07 +00:00

30 lines
766 B
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

const Redis = require("ioredis");
// Verbindung zu Redis herstellen
const redis = new Redis({
host: "data_jobs", // Dein Redis-Containername
port: 6379
});
// Endlosschleife: Immer auf neue Jobs warten
async function startWorker() {
console.log("Worker gestartet warte auf Jobs...");
while (true) {
// BLPOP = Warte auf Job in der Queue "grist:jobs"
const job = await redis.blpop("grist:jobs", 0);
const payload = job[1]; // [0] = Queue-Name, [1] = Daten
console.log("Job empfangen:", payload);
// Ergebnis vorbereiten
const result = `Bearbeitet: ${payload}`;
// Ergebnis in andere Queue schreiben
await redis.rpush("grist:results", result);
console.log("Ergebnis gespeichert:", result);
}
}
startWorker();