/utils/ping

The ping utility module exports a method to repeat a ping query until a condition is met.

Methods

(inner) ping(params)

The ping utility method executes the pingQuery method which will repeat at a given interval until a condition is met.

The ping method will create a request url for the ping query from the provided queryparams object.

mapp.utils.ping({
  query: 'location_field_value',
  responseType: 'text',
  successCondition: 'ok',
  failCondition: 'failed',
  queryparams: {
    id: true,
    field: 'model_status',
    table: 'location_table',
  },
  interval: 4000,
  callback: (response) => {
    console.log(response);
  },
});
Parameters:
NameTypeDescription
paramsObject

The parameters object.

Properties
NameTypeDescription
params.querystring

The query template for the ping query.

params.queryparamsObject

Parameters for the ping query.

(inner) pingQuery(params) → {Promise}

The pingQuery method will call itself with a timeout until a condition is met.

The method will reject if the response is an error.

The method will resolve if the response matches either the failCondition or the successCondition.

The method will resolve if the callback property is set to false.

If the callback property is a function it will be called with the response and the params object itself as arguments.

Parameters:
NameTypeDescription
paramsObject

The parameters object.

Properties
NameTypeDescription
params.responseTypestring

The expected responseType form the ping query.

params.urlstring

The request url for the ping query.

params.callbackfunction

Method to be executed with the response and params object as arguments.

params.successConditionstring

The expected response for a successful ping query.

params.failConditionstring

The expected response for a failed ping query.

params.intervalnumber

The interval in milliseconds between ping queries.

Returns:

A promise that resolves with the response or rejects with an error.

Type: 
Promise