code: func (r *Orchestrator) setTasksDesiredState(ctx context.Context, batch *store.Batch, slots []orchestrator.Slot, newDesiredState api.TaskState) {
  	for _, slot := range slots {
  		for _, t := range slot {
  			err := batch.Update(func(tx store.Tx) error {
  				// time travel is not allowed. if the current desired state is
  				// above the one we're trying to go to we can't go backwards.
  				// we have nothing to do and we should skip to the next task
  				if t.DesiredState > newDesiredState {
  					// log a warning, though. we shouln't be trying to rewrite
  					// a state to an earlier state
  					log.G(ctx).Warnf(
  						"cannot update task %v in desired state %v to an earlier desired state %v",
  						t.ID, t.DesiredState, newDesiredState,
  					)
  					return nil
  				}
  				// update desired state
  				t.DesiredState = newDesiredState
  
  				return store.UpdateTask(tx, t)
  			})
  
  			// log an error if we get one
  			if err != nil {
  				log.G(ctx).WithError(err).Errorf("failed to update task to %v", newDesiredState.String())
  			}
  		}
  	}
  }
docs: // setTasksDesiredState sets the desired state for all tasks for the given slots to the
  // requested state