stream-consumer.js
function postFinaliseBatch(batch, context) {
  const task = this;
  // const finalisingTask = task.parent;

  // Look up the actual function to be used to do the post-finalise batch logic (if any)
  const postFinaliseBatchFn = Settings.getPostFinaliseBatchFunction(context);

  if (!postFinaliseBatchFn) {
    if (context.traceEnabled) context.trace(`Skipping post-finalise of ${batch.describe()}, since no postFinaliseBatch function configured`);
    return Promise.resolve(undefined);
  }

  // Create a task to be used to execute and track the configured postFinaliseBatch function
  const fnName = isNotBlank(postFinaliseBatchFn.name) ? postFinaliseBatchFn.name : 'postFinaliseBatch';
  const postFinaliseBatchTask = task.createSubTask(fnName, postFinaliseBatchFn, batchSettings, finaliseTaskOpts);

  // Pre-finalise the batch
  const p = postFinaliseBatchTask.execute(batch, context);
  return whenDone(postFinaliseBatchTask, p, undefined, context).then(
    // return Promises.try(() => preFinaliseBatchTask.execute(batch, context)).then(
    () => {
      context.debug(`Post-finalised ${batch.describe()}`);
      return batch;
    },
    err => {
      context.error(`Failed to post-finalise ${batch.describe()}`, err);
      throw err;
    }
  );
}
function postFinaliseBatch(batch, context) {
  const task = this;
  // const finalisingTask = task.parent;

  // Look up the actual function to be used to do the post-finalise batch logic (if any)
  const postFinaliseBatchFn = Settings.getPostFinaliseBatchFunction(context);

  if (!postFinaliseBatchFn) {
    if (context.traceEnabled) context.trace(`Skipping post-finalise of ${batch.describe()}, since no postFinaliseBatch function configured`);
    return Promise.resolve(undefined);
  }

  // Create a task to be used to execute and track the configured postFinaliseBatch function
  const fnName = isNotBlank(postFinaliseBatchFn.name) ? postFinaliseBatchFn.name : 'postFinaliseBatch';
  const postFinaliseBatchTask = task.createSubTask(fnName, postFinaliseBatchFn, batchSettings, finaliseTaskOpts);

  // Pre-finalise the batch
  const p = postFinaliseBatchTask.execute(batch, context);
  return whenDone(postFinaliseBatchTask, p, undefined, context).then(
    // return Promises.try(() => preFinaliseBatchTask.execute(batch, context)).then(
    () => {
      context.debug(`Post-finalised ${batch.describe()}`);
      return batch;
    },
    err => {
      context.error(`Failed to post-finalise ${batch.describe()}`, err);
      throw err;
    }
  );
}
function postFinaliseBatch ( batch , context ) { const task = this ; // const finalisingTask = task.parent; // Look up the actual function to be used to do the post-finalise batch logic (if any) const postFinaliseBatchFn = Settings . getPostFinaliseBatchFunction ( context ) ; if ( ! postFinaliseBatchFn ) { if ( context . traceEnabled ) context . trace ( ` ${ batch . describe ( ) } ` ) ; return Promise . resolve ( undefined ) ; } // Create a task to be used to execute and track the configured postFinaliseBatch function const fnName = isNotBlank ( postFinaliseBatchFn . name ) ? postFinaliseBatchFn . name : 'postFinaliseBatch' ; const postFinaliseBatchTask = task . createSubTask ( fnName , postFinaliseBatchFn , batchSettings , finaliseTaskOpts ) ; // Pre-finalise the batch const p = postFinaliseBatchTask . execute ( batch , context ) ; return whenDone ( postFinaliseBatchTask , p , undefined , context ) . then ( // return Promises.try(() => preFinaliseBatchTask.execute(batch, context)).then( ( ) => { context . debug ( ` ${ batch . describe ( ) } ` ) ; return batch ; } , err => { context . error ( ` ${ batch . describe ( ) } ` , err ) ; throw err ; } ) ; }
Provides a hook for an optional post-finalise batch function to be invoked after the batch has been successfully
finalised.
@param {Batch} batch
@param {StreamConsumerContext} context
@param {PostFinaliseBatch} [context.postFinaliseBatch] - an optional post-finalise batch function to execute
@returns {Promise.<Batch|undefined>}
Provides a hook for an optional post - finalise batch function to be invoked after the batch has been successfully finalised .