From dccf02e11d440d96f6a850cefd44d39ab8f9898f Mon Sep 17 00:00:00 2001 From: "Alexander A. Klimov" Date: Fri, 19 Nov 2021 16:28:28 +0100 Subject: [PATCH] Introduce BulkChunkSplitPolicy --- pkg/com/entity_bulker.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/pkg/com/entity_bulker.go b/pkg/com/entity_bulker.go index 1ccb873b..8e151ea3 100644 --- a/pkg/com/entity_bulker.go +++ b/pkg/com/entity_bulker.go @@ -8,6 +8,17 @@ import ( "time" ) +// BulkChunkSplitPolicy is a state machine which tracks the items of a chunk a bulker assembles. +type BulkChunkSplitPolicy interface { + // Track takes an item for the current chunk into account. + // Output true indicates that the state machine was reset first and the bulker + // shall finish the current chunk now (not e.g. once $size is reached) without the given item. + Track(contracts.Entity) bool + + // Reset resets the state machine. + Reset() +} + // EntityBulker reads all entities from a channel and streams them in chunks into a Bulk channel. type EntityBulker struct { ch chan []contracts.Entity