Update job-priority.ts

This commit is contained in:
Nicolas 2024-08-27 16:58:28 -03:00
parent 080240e040
commit f0dfcd6a49

View File

@ -37,48 +37,55 @@ export async function getJobPriority({
team_id: string; team_id: string;
basePriority?: number; basePriority?: number;
}): Promise<number> { }): Promise<number> {
const setKey = SET_KEY_PREFIX + team_id; try {
const setKey = SET_KEY_PREFIX + team_id;
// Get the length of the set // Get the length of the set
const setLength = await redisConnection.scard(setKey); const setLength = await redisConnection.scard(setKey);
// Determine the priority based on the plan and set length // Determine the priority based on the plan and set length
let planModifier = 1; let planModifier = 1;
let bucketLimit = 0; let bucketLimit = 0;
switch (plan) { switch (plan) {
case "free": case "free":
bucketLimit = 25; bucketLimit = 25;
planModifier = 0.5; planModifier = 0.5;
break; break;
case "hobby": case "hobby":
bucketLimit = 50; bucketLimit = 50;
planModifier = 0.3; planModifier = 0.3;
break; break;
case "standard": case "standard":
case "standardnew": case "standardnew":
bucketLimit = 100; bucketLimit = 100;
planModifier = 0.2; planModifier = 0.2;
break; break;
case "growth": case "growth":
case "growthdouble": case "growthdouble":
bucketLimit = 200; bucketLimit = 200;
planModifier = 0.2; planModifier = 0.2;
break; break;
default: default:
bucketLimit = 25; bucketLimit = 25;
planModifier = 1; planModifier = 1;
break; break;
} }
// if length set is smaller than set, just return base priority // if length set is smaller than set, just return base priority
if (setLength <= bucketLimit) { if (setLength <= bucketLimit) {
return basePriority; return basePriority;
} else { } else {
// If not, we keep base priority + planModifier // If not, we keep base priority + planModifier
return Math.ceil( return Math.ceil(
basePriority + Math.ceil((setLength - bucketLimit) * planModifier) basePriority + Math.ceil((setLength - bucketLimit) * planModifier)
);
}
} catch (e) {
Logger.error(
`Get job priority failed: ${team_id}, ${plan}, ${basePriority}`
); );
return basePriority;
} }
} }