diff --git a/.env.example b/.env.example index f48d858..bff5684 100644 --- a/.env.example +++ b/.env.example @@ -1,5 +1,5 @@ -# Add your environment variables here -GOOGLE_API_KEY=GOOGLE_API_KEY -MANTIS_API_KEY=MANTIS_API_KEY -MANTIS_API_ENDPOINT=https://styletech.mantishub.io/api/rest -DATABASE_URL="postgresql://sts-sls-utility:MY_SECURE_PASSWORD@localhost:5432/sts-sls-utility?schema=public" \ No newline at end of file +RP_ID=localhost +RP_NAME=StylePoint +ORIGIN=http://localhost:9100 +DATABASE_URL="postgresql://sts-sls-utility:MY_SECURE_PASSWORD@localhost:5432/sts-sls-utility?schema=public" +SESSION_SECRET=MY_SECURE_SESSION_SECRET \ No newline at end of file diff --git a/src-server/services/mantisDownloader.js b/src-server/services/mantisDownloader.js index 02bc4d2..60e9222 100644 --- a/src-server/services/mantisDownloader.js +++ b/src-server/services/mantisDownloader.js @@ -39,7 +39,7 @@ export async function getLatestMantisTickets() catch (error) { logger.error('Error fetching tickets data:', error); - throw new Error('Failed to fetch tickets data from Mantis.'); + return []; } } @@ -184,8 +184,13 @@ async function processTicketsInQueue() logger.info('No tickets to process.'); return; } + logger.info(`Processing tickets in queue: ${downloadQueue.length} tickets remaining.`); - const ticketId = downloadQueue.shift(); + // const ticketId = downloadQueue.shift(); + //Pick a random ticket from the queue + const randomIndex = Math.floor(Math.random() * downloadQueue.length); + const ticketId = downloadQueue[randomIndex]; + downloadQueue.splice(randomIndex, 1); try { logger.info(`Processing ticket ${ticketId}...`); @@ -203,7 +208,7 @@ async function processTicketsInQueue() const downloadQueue = []; -export function setup() +export async function setup() { // Initialize the download queue downloadQueue.length = 0; @@ -211,5 +216,22 @@ export function setup() // Start the process of checking for new tickets processNewMantisTickets(); setInterval(processNewMantisTickets, 5 * 60 * 1000); // Check for new tickets every 5 minutes - setInterval(processTicketsInQueue, 10 * 1000); // Process the queue every 10 seconds + setInterval(processTicketsInQueue, 1 * 1000); // Process the queue every 10 seconds + + if(process.env.LOAD_ALL_MANTISES == 'true') + { + 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 + }); + + if (!existingTicket) + { + downloadQueue.push(i); + } + } + } } \ No newline at end of file