connection-lifeguard

1.1.0 • Public • Published

ConnectionLifeguard Service

Overview

ConnectionLifegaurd is used to determine when a client is allowed to obtain a connection with a database.

See also ABOUT

Example Usage

const { axios } = require('@nuskin/axios-util')
const baseUrl = 'https://devapi.cloud.nuskin.com/connection-lifeguard/v1'

const main = async () => {
  const pool = 'lambdaName'
  let uuid
  let approved
  try {
    let count = 0
    do {
      count++
      const response = await axios.get(`${baseUrl}/${pool}`)
      approved = response.data.approved
      if(approved){
        uuid = response.data.uuid
        // you're allowed to get a db connection now.
        // do your processing here onse.data.uuid
      }
    } while(!approved && count<4) // attempt to get approval 4 times
  } catch(error) {
      console.error("We got an error: ",error)
  } finally {
    // Close your connection with the database here.
    // Tell the connection lifeguard you are done and don't 
    // need your connection anymore
    await axios.delete(`${baseUrl}/${pool}/${uuid}`)
  }
}

main()

Example Response

{
  "approved": true,
  "count": 7,
  "uuid": "N3ZCSMAUs2DGs1PA2ItxxX"
}

Resources

License

MIT

Readme

Keywords

none

Package Sidebar

Install

npm i connection-lifeguard

Weekly Downloads

1

Version

1.1.0

License

MIT

Unpacked Size

79.3 kB

Total Files

39

Last publish

Collaborators

  • brycesheffield