in source/microservices/lib/simulationManager.js [233:279]
async getDeviceType(simId, attributes) {
const BATCH_GET_MAX = 100;
let sim = await this.getSimulation(simId);
let keys = sim.devices.map((device) => ({ typeId: device.typeId }));
let keySubset = keys.splice(0, BATCH_GET_MAX);
let processedResults = [];
let data;
const retryMax = 5;
try {
while (keySubset.length > 0) {
let retryCount = 0;
let params = {
RequestItems: {
[process.env.DEVICE_TYPES_TBL]: {
Keys: keySubset,
ProjectionExpression: attributes
}
}
};
data = await docClient.batchGet(params).promise();
processedResults.push(...data.Responses[process.env.DEVICE_TYPES_TBL]);
let unprocessedKeys = data.UnprocessedKeys;
while (unprocessedKeys && Object.keys(unprocessedKeys).length > 0 && retryCount <= retryMax) {
await wait(2 ** retryCount * 25);
params.RequestItems = unprocessedKeys;
data = await docClient.batchGet(params).promise();
processedResults.push(...data.Responses[process.env.DEVICE_TYPES_TBL]);
unprocessedKeys = data.UnprocessedKeys;
retryCount++;
}
keySubset = keys.splice(0, BATCH_GET_MAX);
}
if (processedResults.length > 0) {
return (processedResults);
} else {
let error = new Error();
error.code = 400;
error.error = 'MissingDeviceType';
error.message = `The device types do not exist.`;
throw (error);
}
} catch (err) {
console.error(err);
console.error(`Error occurred while attempting to get Device Types for simulation ${simId}.`);
throw (err);
}
}