async function updateState()

in source/routing-configurer/state-updater.ts [151:170]


async function updateState(tableName: string, appId: string, newState: string) {
    const docClient = new AWS.DynamoDB.DocumentClient();
    const updateParams: AWS.DynamoDB.DocumentClient.UpdateItemInput = {
        TableName: tableName,
        Key: { appId: appId },
        UpdateExpression: 'set #STAT = :stat',
        ConditionExpression: 'attribute_not_exists(#AID) OR (attribute_exists(#STAT) AND #STAT <> :stat)',
        ExpressionAttributeNames: { '#STAT': 'state', '#AID': 'appId' },
        ExpressionAttributeValues: { ':stat': newState }
    };

    console.log('Updating State', updateParams);
    await docClient.update(updateParams).promise();

    console.log(`Successfully updated ${tableName} and set appId (${appId}) to ${newState}`);

    if (process.env.SEND_METRICS === 'Yes') {
        await sendMetric({ EventName: 'STATE_UPDATED', EventValue: newState });
    }
}