Fix error when Mantis key isn't set.

This commit is contained in:
Cameron Redmore 2025-04-26 12:02:17 +01:00
parent 8ad2c6ef53
commit c1cff132b3
2 changed files with 31 additions and 9 deletions

View file

@ -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
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

View file

@ -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);
}
}
}
}