Fix error when Mantis key isn't set.
This commit is contained in:
parent
8ad2c6ef53
commit
c1cff132b3
2 changed files with 31 additions and 9 deletions
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue