function upsert()

in wasa/index.js [115:142]


function upsert(metricTypeSet, allMetrics) {
    var firstItem = metricTypeSet[0];
    var ExpireTime = firstItem.EVENTTIMESTAMP + EXPIRE_TIME;
    var metricDetailParams = {
        TableName : METRIC_DETAILS_TABLE,
        Item : {
            MetricType : firstItem.METRICTYPE,
            EventTimestamp : firstItem.EVENTTIMESTAMP,
            ExpireTime : ExpireTime,
            MetricDetails : metricTypeSet
        },
        ConditionExpression : 'attribute_not_exists(MetricType)'
    };

    try {
        docClient.put(metricDetailParams, function (err, data) {
            if (err) {
                if (err.code == "ConditionalCheckFailedException") {
                    amendMetric(metricTypeSet,allMetrics);
                } else {
                    console.error('Error updating metric detail table: ' + JSON.stringify(err,null,2));
                }
            }
        });
    } catch (err) {
        console.error('Unable to save records to DynamoDB: ', err);
    }
};