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
10
.env.example
10
.env.example
|
@ -1,5 +1,5 @@
|
||||||
# Add your environment variables here
|
RP_ID=localhost
|
||||||
GOOGLE_API_KEY=GOOGLE_API_KEY
|
RP_NAME=StylePoint
|
||||||
MANTIS_API_KEY=MANTIS_API_KEY
|
ORIGIN=http://localhost:9100
|
||||||
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"
|
||||||
DATABASE_URL="postgresql://sts-sls-utility:MY_SECURE_PASSWORD@localhost:5432/sts-sls-utility?schema=public"
|
SESSION_SECRET=MY_SECURE_SESSION_SECRET
|
|
@ -39,7 +39,7 @@ export async function getLatestMantisTickets()
|
||||||
catch (error)
|
catch (error)
|
||||||
{
|
{
|
||||||
logger.error('Error fetching tickets data:', 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.');
|
logger.info('No tickets to process.');
|
||||||
return;
|
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
|
try
|
||||||
{
|
{
|
||||||
logger.info(`Processing ticket ${ticketId}...`);
|
logger.info(`Processing ticket ${ticketId}...`);
|
||||||
|
@ -203,7 +208,7 @@ async function processTicketsInQueue()
|
||||||
|
|
||||||
const downloadQueue = [];
|
const downloadQueue = [];
|
||||||
|
|
||||||
export function setup()
|
export async function setup()
|
||||||
{
|
{
|
||||||
// Initialize the download queue
|
// Initialize the download queue
|
||||||
downloadQueue.length = 0;
|
downloadQueue.length = 0;
|
||||||
|
@ -211,5 +216,22 @@ export function setup()
|
||||||
// Start the process of checking for new tickets
|
// Start the process of checking for new tickets
|
||||||
processNewMantisTickets();
|
processNewMantisTickets();
|
||||||
setInterval(processNewMantisTickets, 5 * 60 * 1000); // Check for new tickets every 5 minutes
|
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