in source/services/events-processing/lib/event.js [196:232]
async getApplication(applicationId) {
const params = {
TableName: process.env.APPLICATIONS_TABLE,
Key: {
application_id: applicationId
}
};
// first try to fetch from cache
let applicationsCacheResult = global.applicationsCache.get(applicationId);
if (applicationsCacheResult == 'NOT_FOUND') {
// if already marked not found, skip processing. Applications will remain "NOT_FOUND" until the cache refresh
return Promise.resolve(null);
} else if (applicationsCacheResult == undefined) {
// get from DynamoDB and set in Applications cache
const docClient = new AWS.DynamoDB.DocumentClient(this.dynamoConfig);
try {
let data = await docClient.get(params).promise();
if (!_.isEmpty(data)) {
// if found in ddb, set in cache and return it
global.applicationsCache.set(applicationId, data.Item);
return Promise.resolve(data.Item);
} else {
// if application isn't registered in dynamodb, set not found in cache
console.log(`Application ${applicationId} not found in DynamoDB`);
global.applicationsCache.set(applicationId, 'NOT_FOUND');
return Promise.resolve(null);
}
} catch (err) {
console.log(JSON.stringify(err));
return Promise.reject(err);
}
} else {
// if in cache, return it
return Promise.resolve(applicationsCacheResult);
}
}