Add Flush function to send remaining achievements and call it in saveAchievements
This commit is contained in:
17
dbwriter.go
17
dbwriter.go
@@ -111,6 +111,23 @@ func Save(message NSQMessage) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Flush sends any remaining achievements in the buffer
|
||||
func Flush() error {
|
||||
batchMutex.Lock()
|
||||
if len(batchBuffer) == 0 {
|
||||
batchMutex.Unlock()
|
||||
return nil
|
||||
}
|
||||
|
||||
batch := make([]NSQMessage, len(batchBuffer))
|
||||
copy(batch, batchBuffer)
|
||||
batchBuffer = batchBuffer[:0]
|
||||
batchMutex.Unlock()
|
||||
|
||||
logger.Info("Flushing final batch of %d achievements to %s", len(batch), backendEndpoint)
|
||||
return sendBatch(batch)
|
||||
}
|
||||
|
||||
func sendBatch(batch []NSQMessage) error {
|
||||
logger.Debug("Preparing to send batch of %d achievements", len(batch))
|
||||
|
||||
|
Reference in New Issue
Block a user