Esempio n. 1
0
func (self *executorBBS) batchCompareAndSwapTasks(tasksToCAS [][]models.Task, logger *gosteno.Logger) {
	done := make(chan struct{}, len(tasksToCAS))

	for _, taskPair := range tasksToCAS {
		originalStoreNode := storeadapter.StoreNode{
			Key:   taskSchemaPath(&taskPair[0]),
			Value: taskPair[0].ToJSON(),
		}

		taskPair[1].UpdatedAt = self.timeProvider.Time().UnixNano()
		newStoreNode := storeadapter.StoreNode{
			Key:   taskSchemaPath(&taskPair[1]),
			Value: taskPair[1].ToJSON(),
		}

		go func() {
			err := self.store.CompareAndSwap(originalStoreNode, newStoreNode)
			if err != nil {
				logger.Errord(map[string]interface{}{
					"error": err.Error(),
				}, "runonce.converge.failed-to-compare-and-swap")
			}
			done <- struct{}{}
		}()
	}

	for _ = range tasksToCAS {
		<-done
	}
}