From 52752899426c8af2a99e58b818d7a9d474165337 Mon Sep 17 00:00:00 2001 From: Tengku Yusof Date: Sat, 31 May 2025 10:07:32 +0800 Subject: [PATCH] first commit --- .node-version | 1 + pages/BF-PRF/AS/QUEUE/index.vue | 183 +++++++++++++++++++ server/api/queue/asnaf-analysis/index.get.js | 45 +++++ 3 files changed, 229 insertions(+) create mode 100644 .node-version create mode 100644 pages/BF-PRF/AS/QUEUE/index.vue create mode 100644 server/api/queue/asnaf-analysis/index.get.js diff --git a/.node-version b/.node-version new file mode 100644 index 0000000..2dbbe00 --- /dev/null +++ b/.node-version @@ -0,0 +1 @@ +20.11.1 diff --git a/pages/BF-PRF/AS/QUEUE/index.vue b/pages/BF-PRF/AS/QUEUE/index.vue new file mode 100644 index 0000000..493767f --- /dev/null +++ b/pages/BF-PRF/AS/QUEUE/index.vue @@ -0,0 +1,183 @@ + + + \ No newline at end of file diff --git a/server/api/queue/asnaf-analysis/index.get.js b/server/api/queue/asnaf-analysis/index.get.js new file mode 100644 index 0000000..53f552d --- /dev/null +++ b/server/api/queue/asnaf-analysis/index.get.js @@ -0,0 +1,45 @@ +import Queue from 'bull'; + +// Create a Bull queue instance +const asnafAnalysisQueue = new Queue('asnaf-analysis', { + redis: { + host: process.env.REDIS_HOST || 'localhost', + port: process.env.REDIS_PORT || 6379, + password: process.env.REDIS_PASSWORD + } +}); + +export default defineEventHandler(async (event) => { + try { + // Get all jobs from different states + const [waiting, active, completed, failed] = await Promise.all([ + asnafAnalysisQueue.getWaiting(), + asnafAnalysisQueue.getActive(), + asnafAnalysisQueue.getCompleted(), + asnafAnalysisQueue.getFailed() + ]); + + // Combine all jobs and format them + const allJobs = [...waiting, ...active, ...completed, ...failed] + .map(job => ({ + id: job.id, + status: job.finishedOn ? 'completed' : + job.failedReason ? 'failed' : + job.processedOn ? 'active' : 'waiting', + data: job.data, + timestamp: job.timestamp, + processedOn: job.processedOn, + finishedOn: job.finishedOn, + failedReason: job.failedReason + })) + .sort((a, b) => b.timestamp - a.timestamp); // Sort by timestamp, newest first + + return allJobs; + } catch (error) { + console.error('Error fetching queue data:', error); + throw createError({ + statusCode: 500, + statusMessage: 'Failed to fetch queue data' + }); + } +}); \ No newline at end of file