hunk.code_window:       - openldap
         - elasticsearch
         - prometheus
         - grafana
       command: postgres:5432 mysql:3306 minio:9000 inbucket:10080 openldap:389 elasticsearch:9200 prometheus:9090 grafana:3000
     leader:
       build:
         context: .
  
hunk.labels: keep keep keep keep replace keep keep keep keep
hunk.after_edit:     command: postgres:5432 mysql:3306 minio:9000 inbucket:9001 openldap:389 elasticsearch:9200 prometheus:9090 grafana:3000
  
hunk.file_path: docker-compose.yaml
hunk.type: replace
file: package tasks
  
  import (
  	"fmt"
  
  	"github.com/splitio/go-split-commons/v3/synchronizer/worker/impression"
  	"github.com/splitio/go-toolkit/v4/asynctask"
  	"github.com/splitio/go-toolkit/v4/logging"
  )
  
  // NewRecordImpressionsTask creates a new splits fetching and storing task
  func NewRecordImpressionsTask(
  	recorder impression.ImpressionRecorder,
  	period int,
  	logger logging.LoggerInterface,
  	bulkSize int64,
  ) Task {
  	record := func(logger logging.LoggerInterface) error {
  		return recorder.SynchronizeImpressions(bulkSize)
  	}
  
  	onStop := func(logger logging.LoggerInterface) {
  		// All this function does is flush impressions which will clear the storage
  		recorder.FlushImpressions(bulkSize)
  	}
  
  	return asynctask.NewAsyncTask("SubmitImpressions", record, period, nil, onStop, logger)
  }
  
  // NewRecordImpressionsTasks creates a new splits fetching and storing task
  func NewRecordImpressionsTasks(
  	recorder impression.ImpressionRecorder,
  	period int,
  	logger logging.LoggerInterface,
  	bulkSize int64,
  	totalTasks int) Task {
  	record := func(logger logging.LoggerInterface) error {
  		return recorder.SynchronizeImpressions(bulkSize)
  	}
  
  	tasks := make([]Task, 0, totalTasks)
  	for i := 0; i < totalTasks; i++ {
  		logger.Info(fmt.Sprintf("Creating SubmitImpressions_%d", i))
  		tasks = append(tasks, asynctask.NewAsyncTask(fmt.Sprintf("SubmitImpressions_%d", i), record, period, nil, nil, logger))
  	}
  	return MultipleTask{
  		logger: logger,
  		tasks:  tasks,
  	}
  }
  