|
/* |
|
Hit 'ctrl + d' or 'cmd + d' to run the code, view console for results |
|
*/ |
|
import { sp } from "@pnp/sp/presets/all"; |
|
|
|
( async () => { |
|
console.clear(); |
|
const itemId = 89; |
|
|
|
const RetryHttpCall = async (fnToCall: () => Promise<any>, label: string, delayStart: number, maxTryCount: number): Promise<any> => { |
|
return new Promise( (resolve, reject) => { |
|
setTimeout( async () => { |
|
|
|
let tryCount = 1; |
|
while (true && (tryCount < 99)) { |
|
try { |
|
console.log(`Start update attempt: ${label}... (${tryCount})`); |
|
const response = await fnToCall(); |
|
console.log(`After update attempt: ${label}... (${tryCount}) response::>`, JSON.stringify(response)); |
|
resolve({ |
|
label: `Update ${label}`, |
|
response: response |
|
}); |
|
break; |
|
} catch (error) { |
|
/** |
|
* error = { "response": HttpRequest, "status": number, "statusText": string, "message": string; "isHttpRequestError": boolean } |
|
*/ |
|
window["pnperror"] = error; |
|
console.error(`Error update attempt: ${label}... (${tryCount})`, error.status); |
|
console.error(`Error update attempt: ${label}... (${tryCount})`, error); |
|
if ((tryCount >= maxTryCount) || ( (error.status !== 500) && (error.status !== 409) && (error.status !== 429) ) ) { |
|
reject(error); |
|
break; |
|
} |
|
tryCount++; |
|
} |
|
} |
|
}, delayStart); |
|
}); |
|
}; |
|
|
|
const call1 = () => sp.web.getList("/sites/eelhrportaldev/Lists/StaffUserPermissions").items.getById(itemId).update({ "eelhrPermissionstatusEES": `Pending` }); |
|
const call2 = () => sp.web.getList("/sites/eelhrportaldev/Lists/StaffUserPermissions").items.getById(itemId).update({ "eelhrPermissionstatusCH": `Pending` }); |
|
try { |
|
const updateResponses = await Promise.all([ |
|
RetryHttpCall(call1, "eelhrPermissionstatusEES", 0, 3), |
|
RetryHttpCall(call2, "eelhrPermissionstatusCH", 0, 3), |
|
]); |
|
console.log("Promises.all response::>", updateResponses); |
|
} catch (error) { |
|
console.log("error.status (1) ::> ", error.status); |
|
console.log(error); |
|
} |
|
|
|
} )().catch( (error) => { |
|
console.log("error.status (2) ::> ", error.status); |
|
console.log(error); |
|
}); |
|
|
|
|