2020-11-08 - Message Config Manager - Functions

From Izara Wiki
Jump to navigation Jump to search

Service - Message Config Manager

Lambda Functions

pullMsgCfgs

/**
 * Connects to an external services Lambda that returns that services msgCfgs, stores these into local table
 * @param {string} event.serviceName - for now handle one service at a time
 *
 * @returns {Object} msgCfgs
 */
module.exports.pullMsgCfgs = async (event) => {

logic

  1. query Config table for event.serviceName record
  2. query #MsgCfg table all msgCfg's for event.serviceName, place into var existingMsgCfgs
  3. do an sync Lambda invocation, Lambda function name concatenate {event.serviceName} + "GetMsgCfgs"
  4. if lambda error throw error "Unable to find service endpoint " + {Lambda function name}
  5. if Config table record not exist, create a record
  6. for each msgCfgs
    1. if not exist in existingMsgCfgs or changed
      1. insert/update record in #MsgCfg table
      2. send a message to OutMsgCfgUpdate queue with new msgCfg details

update 2021-05-10

  • external service returns msgCfg without serviceName set, we add this here before saving to Dynamo etc

getServiceNames

/**
 * Returns all serviceNames managed by this service
 *
 * @returns {Object} serviceNames
 */
module.exports.getServiceNames = async () => {

logic

  1. query Config table and return all configKey = serviceName

getMsgCfgs

/**
 * Returns all msgCfgs for one serviceName
 * @param {string} serviceName - for now return results for one service at a time
 *
 * @returns {Object} msgCfgs
 */
module.exports.getMsgCfgs = async (serviceName) => {

handler

  • passes on serviceName from event object

logic

  1. query MsgCfgs table and return all that match serviceName

getMsgCfg

/**
 * Returns one msgCfg
 * @param {string} serviceName
 * @param {string} topicName
 *
 * @returns {Object} msgCfg
 */
module.exports.getMsgCfg = async (serviceName) => {

HdrInv

  • passes on serviceName and topicName from request

logic

  1. query MsgCfgs table and return matching record
  2. also return current timestamp (maybe create timestamp inside Dynamo query for more accurate snapshot time)