Files
mostlymatter/vendor/github.com/splitio/go-split-commons/v2/tasks/eventsync.go
Christopher Speller 1aadd36644 MM-28859 Add feature flag managment system using split.io and remove viper. (#15954)
* Add feature flag managment system using split.io and remove viper.

* Fixing tests.

* Attempt to fix postgres tests.

* Fix watch filepath for advanced logging.

* Review fixes.

* Some error wrapping.

* Remove unessisary store interface.

* Desanitize SplitKey

* Simplify.

* Review feedback.

* Rename split mlog adatper to split logger.

* fsInner

* Style.

* Restore oldcfg test.

* Downgrading non-actionable feature flag errors to warnings.

Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
2020-10-29 15:54:39 -07:00

53 строки
1.4 KiB
Go

package tasks
import (
"fmt"
"sync"
"github.com/splitio/go-split-commons/v2/synchronizer/worker/event"
"github.com/splitio/go-toolkit/v3/asynctask"
"github.com/splitio/go-toolkit/v3/logging"
)
// NewRecordEventsTask creates a new events recording task
func NewRecordEventsTask(
synchronizer event.EventRecorder,
bulkSize int64,
period int,
logger logging.LoggerInterface,
) Task {
record := func(logger logging.LoggerInterface) error {
return synchronizer.SynchronizeEvents(bulkSize)
}
onStop := func(logger logging.LoggerInterface) {
// All this function does is flush events which will clear the storage
synchronizer.FlushEvents(bulkSize)
}
return asynctask.NewAsyncTask("SubmitEvents", record, period, nil, onStop, logger)
}
// NewRecordEventsTasks creates a new splits fetching and storing task
func NewRecordEventsTasks(
recorder event.EventRecorder,
bulkSize int64,
period int,
logger logging.LoggerInterface,
totalTasks int) Task {
record := func(logger logging.LoggerInterface) error {
return recorder.SynchronizeEvents(bulkSize)
}
tasks := make([]Task, 0, totalTasks)
for i := 0; i < totalTasks; i++ {
logger.Info(fmt.Sprintf("Creating SubmitEvents_%d", i))
tasks = append(tasks, asynctask.NewAsyncTask(fmt.Sprintf("SubmitEvents_%d", i), record, period, nil, nil, logger))
}
return MultipleTask{
logger: logger,
tasks: tasks,
wg: &sync.WaitGroup{},
}
}