Skip to content

Commit

Permalink
Fix bug in colorDecider util, update backoff mechanism
Browse files Browse the repository at this point in the history
  • Loading branch information
peterMuriuki committed Sep 18, 2023
1 parent 53dd2ec commit 0ca967a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
5 changes: 3 additions & 2 deletions packages/core/src/helpers/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,12 @@ export const colorDeciderFactory = (symbolConfig: SymbologyConfig, logger?: LogF
const symbologyConfigByPriorityLevel = keyBy(orderedSymbologyConfig, 'priorityLevel');
const symbologyConfig = symbologyConfigByPriorityLevel[thisFacilityPriority];
// TODO - when priority_level is unrecognized. - do we need to also report facilities affected by this errors
if(symbolConfig === undefined){
logger?.(createWarnLog("Unrecognized priority level"))
if(symbologyConfig === undefined){
logger?.(createWarnLog(`facility _id: ${submission._id} as priority_level ${thisFacilityPriority}: Unrecognized priority level`))
return Result.fail("Unrecognized priority level", UNRECOGNIZED_PRIORITY_LEVEL)
}


const overflowsConfig = symbologyConfig.symbologyOnOverflow;
let colorChoice = overflowsConfig[overflowsConfig.length - 1].color;

Expand Down
12 changes: 6 additions & 6 deletions packages/core/src/services/onaApi/services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export const customFetch = async (input: RequestInfo, init?: RequestInit, logger
// The exponential backoff strategy can be hardcoded, should it be left to the calling function.
// post requests are not idempotent
const numOfRetries = 10;
const delayConstant = 500; //ms
const delayConstant = 15000; //ms
const requestOptionsWithRetry: RequestInitWithRetry = {
...init,
retries: numOfRetries,
Expand All @@ -36,23 +36,23 @@ export const customFetch = async (input: RequestInfo, init?: RequestInit, logger
if (response) {
const status = response?.status;
// retry on all server side error http codes.
retry = status >= 500 && status < 600;
retry = (status >= 500 && status < 600) || ([429].includes(status));
}

if (retry) {
const msg = response
? `Retrying request; request respondend with status: ${response?.status}`
: 'Retrying request, Request does not have a response';
? `Retrying request ${input}; request respondend with status: ${response?.status}`
: `Retrying request ${input}, Request does not have a response`;
logger?.(createVerboseLog(msg));
}
return retry;
},
retryDelay: function (attempt) {
return Math.pow(2, attempt) * delayConstant;
return attempt * delayConstant;
}
};
const response = await persistentFetch(input, requestOptionsWithRetry).catch((err) => {
throw Error(`${err.name}: ${err.message}.`);
throw Error(`${response.status}: ${err.name}: ${err.message}.`);
});
if (response?.ok) {
return response;
Expand Down

0 comments on commit 0ca967a

Please sign in to comment.