bonsaif 1.10.8 → 1.10.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/lib/utl.js +46 -1
  2. package/package.json +1 -1
package/lib/utl.js CHANGED
@@ -1359,6 +1359,50 @@ const get_parameter=( queryString, Parameter)=>{
1359
1359
  return value ? value[1] : '';
1360
1360
  }
1361
1361
 
1362
+ const health_check_services=(o)=>{
1363
+ try{
1364
+ const {services=[], pulse=0, user='', pass='', debug=0} = o;
1365
+ let auth = "Basic " + Buffer.from(user + ":" + pass).toString("base64");
1366
+ const timerHelth= new Timer({
1367
+ hearbeat:{pulse, startEvent:true,
1368
+ event:async function(){
1369
+ for (let service of services){
1370
+ let {url='', service_url='', name='', body={}} = service ? service : {};
1371
+ let options = {
1372
+ url:service_url,
1373
+ timeout: 3000,
1374
+ headers: {
1375
+ 'Content-Type': 'application/json',
1376
+ 'authorization': auth
1377
+ },
1378
+ body: JSON.stringify({...body})
1379
+ }
1380
+ let service_apix = await apix({method:'post', options, time:3, retries:2, async:true});
1381
+ if (service_apix.statusCode=='200'){
1382
+ debug ? log(' post :::::>',service_apix.body) : '';
1383
+ apix({method:'post', options:{url, timeout: 3000, headers: {
1384
+ 'Content-Type': 'application/json',
1385
+ 'authorization': auth
1386
+ },
1387
+ body: JSON.stringify({name, user, pulse})
1388
+ },
1389
+ callback:function(o){
1390
+ delete o.res;
1391
+ debug ? log(' post :::::>',JSON.stringify(o)) : '';
1392
+ }
1393
+ });
1394
+ }
1395
+ }
1396
+ }
1397
+ }
1398
+
1399
+ });
1400
+ timerHelth.start()
1401
+ }catch(e){
1402
+ log('health_check_services.err',e);
1403
+ }
1404
+ }
1405
+
1362
1406
  module.exports={
1363
1407
  log,
1364
1408
  addZero,
@@ -1431,5 +1475,6 @@ const get_parameter=( queryString, Parameter)=>{
1431
1475
  json_to_result,
1432
1476
  difference_day,
1433
1477
  date_part,
1434
- get_parameter
1478
+ get_parameter,
1479
+ health_check_services
1435
1480
  }
package/package.json CHANGED
@@ -14,7 +14,7 @@
14
14
  },
15
15
  "name": "bonsaif",
16
16
  "description": "bonsaif is a library to connect to bonsaif apis",
17
- "version": "1.10.8",
17
+ "version": "1.10.9",
18
18
  "main": "index.js",
19
19
  "directories": {
20
20
  "lib": "lib"