Software: Apache/2.4.41 (Ubuntu). PHP/8.0.30 uname -a: Linux apirnd 5.4.0-204-generic #224-Ubuntu SMP Thu Dec 5 13:38:28 UTC 2024 x86_64 uid=33(www-data) gid=33(www-data) groups=33(www-data) Safe-mode: OFF (not secure) /var/www/html/instagram/src/openAi/queue/ drwxr-xr-x | |
| Viewing file: Select action/file-type: // const redis = require("../../config/redisClient");
const path = require("path");
const redis = require(path.resolve(process.cwd(), "config", "redisClient"));
const { chatQueue } = require("./index");
// processor.js
chatQueue.process(1, async (job) => {
const { userId, text } = job.data;
try {
await redis.set(`user:${userId}:busy`, 'true');
console.log(`Processing for ${userId}: ${text}`);
// 🔹 simulate OpenAI or processing delay
await new Promise(r => setTimeout(r, 2000));
console.log(`✅ Processed: ${text}`);
// 🔹 After processing, check if there are new pending messages
const nextMessage = await redis.lpop(`user:${userId}:pending`);
if (nextMessage) {
console.log(`Found pending message for ${userId}, re-queuing...`);
await chatQueue.add({ userId, text: nextMessage });
} else {
console.log(`No pending messages for ${userId}`);
await redis.del(`user:${userId}:busy`);
}
} catch (err) {
console.error('Job failed', err);
throw err; // Bull will retry
}
});
// Retry failed jobs automatically
messageQueue.on('failed', (job, err) => {
console.error(`Job failed for user ${job.data.userId}, retrying...`, err.message);
});
|
:: Command execute :: | |
--[ c99shell v. 2.5 [PHP 8 Update] [24.05.2025] | Generation time: 0.0241 ]-- |