connection-lifeguard
v1.1.0
Published
ConnectionLifeguard MicroService on Lambda
Downloads
1
Readme
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
- New Relic