Example #1
0
// The stager calls this when it wants to desire a payload
// stagerBBS will retry this repeatedly if it gets a StoreTimeout error (up to N seconds?)
// If this fails, the stager should bail and run its "this-failed-to-stage" routine
func (s *stagerBBS) DesireTask(task *models.Task) error {
	return retryIndefinitelyOnStoreTimeout(func() error {
		if task.CreatedAt == 0 {
			task.CreatedAt = s.timeProvider.Time().UnixNano()
		}

		task.UpdatedAt = s.timeProvider.Time().UnixNano()
		task.State = models.TaskStatePending

		err := s.store.SetMulti([]storeadapter.StoreNode{
			{
				Key:   taskSchemaPath(task),
				Value: task.ToJSON(),
			},
		})
		if err != nil {
			return err
		}

		s.kicker.Desire(task)

		return nil
	})
}