I am facing an issue with my onScheduledEvent handler not completing the entirety of my code I have written. I am trying to cache a pull of a product catalog that I get from Dell after extracting the data I care about. I can confirm that this pull is successful for both end points and is not too big to be saved using the data method and will complete if it is just CA or US, but not both. It does take a little longer than usual to receive a response from the endpoints call, but I am using async methods. This was also tested before rolled out and confirmed to be working as expected. This is causing downtime for my customer. I need help resolving this issue. Please find my code below:
onScheduledEventHandler: async function(args) {
var key, options, orderDataCA, orderDataUS;
console.log("Logging arguments from onScheduledEventHandler: " + JSON.stringify(args))
var tokeca= await getToken(caform);
catoken = tokeca['access_token']
var tokeus = await getToken(usform);
ustoken = tokeus['access_token']
// await sleep(2000);
var cacatalog = await getCatalogCA(catoken);
console.log(`Canada catalog length is ${cacatalog.length} items long.`);
tempOptions = buildOptions(cacatalog)
var options = []
for (var item of tempOptions){
options[item['manu_id']] =item
}
key = "CA-Catalog-s";
console.log("Deleting old databased CA catalog...")
await deleteDB(key)
console.log("Setting new databased CA catalog...")
await setDB(key, options[undefined]);
var uscatalog = await getCatalogUS(ustoken);
console.log(`US catalog length is ${uscatalog.length} items long.`);
tempOptions = buildOptions(uscatalog)
var options = []
for (var item of tempOptions){
options[item['manu_id']] =item
}
key = "US-Catalog-s";
console.log("Deleting old databased US catalog...")
await deleteDB(key)
console.log("Setting new databased US catalog...")
await setDB(key, options[undefined]);
var allStatusesUS = await getDB("ordersWithStatusUSsand");
var allStatusesCA = await getDB("ordersWithStatusCAsand");
orderDataUS = await getDB("ordersUSsand");
orderDataCA = await getDB("ordersCAsand");
console.log("US orders: ", orderDataUS['poNums'])
console.log("CA orders: ", orderDataCA['poNums'])
var orderhash = {}
}