onSendBatchWithSuccess method

  1. @override
dynamic onSendBatchWithSuccess(
  1. List<Hit> listOfSendedHits,
  2. BatchCachingStrategy strategy
)
override

Implementation

@override
onSendBatchWithSuccess(
    List<Hit> listOfSendedHits, BatchCachingStrategy strategy) {
  // Remove old cache before save a fresh data
  if (strategy == BatchCachingStrategy.BATCH_CONTINUOUS_CACHING) {
    // Refractor later
    List<String> listOfIds = [];
    listOfSendedHits.forEach((element) {
      listOfIds.add(element.id);
    });
    fsCacheHit.flushHits(listOfIds);
  } else if (strategy == BatchCachingStrategy.BATCH_PERIODIC_CACHING) {
    // Clean the pool before save it again, because those hits are sended with success
    listOfSendedHits.forEach((element) {
      fsPool.removeTrackElement(element.id);
    });

    // Flush all hits before cache the new ones
    fsCacheHit.flushAllHits();
    fsCacheHit.cacheHits(FlagshipTools.hitsToMap(fsPool.fsQueue.toList()));
  } else {
    Flagship.logger(
        Level.INFO, "Batching is not implemented on hidden option");
  }
  cronTimer.start();
}