lib/pushDynamicEntityValues.js
/*
 * Monitor push request until it finishes.
 * Outputs bot ID, entity ID, push request ID.
 * Outputs push request status when job is done.
 * If job isn't done after 50 queries, then ends with check-later message
 *
 * @param botid
 * @param entityId
 * @param pushRequestId
 */
Monitor push request until it finishes.


Monitor push request until it finishes .
async function trackStatus (botId, entityId, pushRequestId) {
  try {
    const max = 50;
    console.log('Bot ID: ' + botId);
    console.log('entity ID: ' + entityId);
    console.log('Push Requst ID: ' + pushRequestId);
    console.log('Checking push request job for completion...');
    var pushRequestStatus = '';
    for (let i = 0; i < max; i++) {
      if (i >= max - 1) {
        return 'Request job still hasn\'t completed. Current status is ' +
          pushRequestStatus +
          '. Check job status later.';
      } else {
        console.log('...');
        await timeout(5000);
        const pushRequestData = await getPushRequest(botId, entityId, pushRequestId);
        pushRequestStatus = pushRequestData.status.toUpperCase();
        if (!ACTIVE_STATUSES.includes(pushRequestStatus)) {
          return 'Push request job has finished. Status = ' + pushRequestStatus + '.';
        }
      };
    };
  } catch (error) {
    failureCallback(error);
  }
}
async function trackStatus ( botId , entityId , pushRequestId ) { try { const max = 50 ; console . log ( 'Bot ID: ' + botId ) ; console . log ( 'entity ID: ' + entityId ) ; console . log ( 'Push Requst ID: ' + pushRequestId ) ; console . log ( 'Checking push request job for completion...' ) ; var pushRequestStatus = '' ; for ( let i = 0 ; i < max ; i ++ ) { if ( i >= max - 1 ) { return 'Request job still hasn\'t completed. Current status is ' + pushRequestStatus + '. Check job status later.' ; } else { console . log ( '...' ) ; await timeout ( 5000 ) ; const pushRequestData = await getPushRequest ( botId , entityId , pushRequestId ) ; pushRequestStatus = pushRequestData . status . toUpperCase ( ) ; if ( ! ACTIVE_STATUSES . includes ( pushRequestStatus ) ) { return 'Push request job has finished. Status = ' + pushRequestStatus + '.' ; } } ; } ; } catch ( error ) { failureCallback ( error ) ; } }
Monitor push request until it finishes.
Monitor push request until it finishes .