From f0dfcd6a4949fbd033e07362f34f0a176a7e3633 Mon Sep 17 00:00:00 2001 From: Nicolas Date: Tue, 27 Aug 2024 16:58:28 -0300 Subject: [PATCH] Update job-priority.ts --- apps/api/src/lib/job-priority.ts | 81 +++++++++++++++++--------------- 1 file changed, 44 insertions(+), 37 deletions(-) diff --git a/apps/api/src/lib/job-priority.ts b/apps/api/src/lib/job-priority.ts index 361c608d..c4744d7b 100644 --- a/apps/api/src/lib/job-priority.ts +++ b/apps/api/src/lib/job-priority.ts @@ -37,48 +37,55 @@ export async function getJobPriority({ team_id: string; basePriority?: number; }): Promise { - const setKey = SET_KEY_PREFIX + team_id; + try { + const setKey = SET_KEY_PREFIX + team_id; - // Get the length of the set - const setLength = await redisConnection.scard(setKey); + // Get the length of the set + const setLength = await redisConnection.scard(setKey); - // Determine the priority based on the plan and set length - let planModifier = 1; - let bucketLimit = 0; + // Determine the priority based on the plan and set length + let planModifier = 1; + let bucketLimit = 0; - switch (plan) { - case "free": - bucketLimit = 25; - planModifier = 0.5; - break; - case "hobby": - bucketLimit = 50; - planModifier = 0.3; - break; - case "standard": - case "standardnew": - bucketLimit = 100; - planModifier = 0.2; - break; - case "growth": - case "growthdouble": - bucketLimit = 200; - planModifier = 0.2; - break; + switch (plan) { + case "free": + bucketLimit = 25; + planModifier = 0.5; + break; + case "hobby": + bucketLimit = 50; + planModifier = 0.3; + break; + case "standard": + case "standardnew": + bucketLimit = 100; + planModifier = 0.2; + break; + case "growth": + case "growthdouble": + bucketLimit = 200; + planModifier = 0.2; + break; - default: - bucketLimit = 25; - planModifier = 1; - break; - } + default: + bucketLimit = 25; + planModifier = 1; + break; + } - // if length set is smaller than set, just return base priority - if (setLength <= bucketLimit) { - return basePriority; - } else { - // If not, we keep base priority + planModifier - return Math.ceil( - basePriority + Math.ceil((setLength - bucketLimit) * planModifier) + // if length set is smaller than set, just return base priority + if (setLength <= bucketLimit) { + return basePriority; + } else { + // If not, we keep base priority + planModifier + return Math.ceil( + basePriority + Math.ceil((setLength - bucketLimit) * planModifier) + ); + } + } catch (e) { + Logger.error( + `Get job priority failed: ${team_id}, ${plan}, ${basePriority}` ); + return basePriority; } }