From ef002ec79bbcc38134b20c1643f86cc24ad1ff2d Mon Sep 17 00:00:00 2001 From: Cameron Redmore Date: Sat, 26 Apr 2025 12:07:42 +0100 Subject: [PATCH] Wrap downloader in a catch --- src-server/services/mantisDownloader.js | 48 +++++++++++++++---------- 1 file changed, 29 insertions(+), 19 deletions(-) diff --git a/src-server/services/mantisDownloader.js b/src-server/services/mantisDownloader.js index 60e9222..1642268 100644 --- a/src-server/services/mantisDownloader.js +++ b/src-server/services/mantisDownloader.js @@ -16,7 +16,10 @@ export async function getMantisSettings() if (!MANTIS_API_ENDPOINT || !MANTIS_API_KEY) { - throw new Error('Mantis API endpoint or key not configured in environment variables.'); + return { + url: null, + headers: null, + }; } const headers = { Authorization: `${MANTIS_API_KEY}`, @@ -210,28 +213,35 @@ const downloadQueue = []; export async function setup() { - // Initialize the download queue - downloadQueue.length = 0; - - // Start the process of checking for new tickets - processNewMantisTickets(); - setInterval(processNewMantisTickets, 5 * 60 * 1000); // Check for new tickets every 5 minutes - setInterval(processTicketsInQueue, 1 * 1000); // Process the queue every 10 seconds - - if(process.env.LOAD_ALL_MANTISES == 'true') + try { - for (let i = 3000; i <= 5100; i++) - { - //Check if the ticket already exists in the database - const existingTicket = await prisma.mantisIssue.findUnique({ - where: { id: i }, - select: { updatedAt: true } // Only select needed field - }); + // Initialize the download queue + downloadQueue.length = 0; - if (!existingTicket) + // Start the process of checking for new tickets + processNewMantisTickets(); + setInterval(processNewMantisTickets, 5 * 60 * 1000); // Check for new tickets every 5 minutes + setInterval(processTicketsInQueue, 1 * 1000); // Process the queue every 10 seconds + + if(process.env.LOAD_ALL_MANTISES == 'true') + { + for (let i = 3000; i <= 5100; i++) { - downloadQueue.push(i); + //Check if the ticket already exists in the database + const existingTicket = await prisma.mantisIssue.findUnique({ + where: { id: i }, + select: { updatedAt: true } // Only select needed field + }); + + if (!existingTicket) + { + downloadQueue.push(i); + } } } } + catch(error) + { + logger.error('Error setting up Mantis downloader:', error); + } } \ No newline at end of file