stream-consumer.js
function preFinaliseBatch(batch, context) {
  const task = this;

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

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

  // Create a task to be used to execute and track the configured preFinaliseBatch function
  const fnName = isNotBlank(preFinaliseBatchFn.name) ? preFinaliseBatchFn.name : 'preFinaliseBatch';
  const preFinaliseBatchTask = task.createSubTask(fnName, preFinaliseBatchFn, batchSettings, processTaskOpts);

  // Pre-finalise the batch
  const p = preFinaliseBatchTask.execute(batch, context);
  return whenDone(preFinaliseBatchTask, p, undefined, context).then(
    () => {
      if (context.traceEnabled) context.trace(`Pre-finalised ${batch.describe(false)}`);
      return batch;
    },
    err => {
      context.error(`Failed to pre-finalise ${batch.describe(false)}`, err);
      throw err;
    }
  );
}
function preFinaliseBatch(batch, context) {
  const task = this;

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

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

  // Create a task to be used to execute and track the configured preFinaliseBatch function
  const fnName = isNotBlank(preFinaliseBatchFn.name) ? preFinaliseBatchFn.name : 'preFinaliseBatch';
  const preFinaliseBatchTask = task.createSubTask(fnName, preFinaliseBatchFn, batchSettings, processTaskOpts);

  // Pre-finalise the batch
  const p = preFinaliseBatchTask.execute(batch, context);
  return whenDone(preFinaliseBatchTask, p, undefined, context).then(
    () => {
      if (context.traceEnabled) context.trace(`Pre-finalised ${batch.describe(false)}`);
      return batch;
    },
    err => {
      context.error(`Failed to pre-finalise ${batch.describe(false)}`, err);
      throw err;
    }
  );
}
function preFinaliseBatch ( batch , context ) { const task = this ; // Look up the actual function to be used to do the pre-finalise batch logic (if any) const preFinaliseBatchFn = Settings . getPreFinaliseBatchFunction ( context ) ; if ( ! preFinaliseBatchFn ) { if ( context . traceEnabled ) context . trace ( ` ${ batch . describe ( false ) } ` ) ; return Promise . resolve ( undefined ) ; } // Create a task to be used to execute and track the configured preFinaliseBatch function const fnName = isNotBlank ( preFinaliseBatchFn . name ) ? preFinaliseBatchFn . name : 'preFinaliseBatch' ; const preFinaliseBatchTask = task . createSubTask ( fnName , preFinaliseBatchFn , batchSettings , processTaskOpts ) ; // Pre-finalise the batch const p = preFinaliseBatchTask . execute ( batch , context ) ; return whenDone ( preFinaliseBatchTask , p , undefined , context ) . then ( ( ) => { if ( context . traceEnabled ) context . trace ( ` ${ batch . describe ( false ) } ` ) ; return batch ; } , err => { context . error ( ` ${ batch . describe ( false ) } ` , err ) ; throw err ; } ) ; }
Provides a hook for an optional pre-finalise batch function to be invoked after the batch has been successfully
processed and before the batch is finalised.
@param {Batch} batch
@param {StreamConsumerContext} context
@param {PreFinaliseBatch} [context.preFinaliseBatch] - an optional pre-finalise batch function to execute
@returns {Promise.<Batch|undefined>}
Provides a hook for an optional pre - finalise batch function to be invoked after the batch has been successfully processed and before the batch is finalised .