code: func (ar *AgentReconciler) calculateTasksForUnits(dState *AgentState, cState unitStates) []task {
  	jobs := pkg.NewUnsafeSet()
  	for cName := range cState {
  		jobs.Add(cName)
  	}
  
  	for dName := range dState.Units {
  		jobs.Add(dName)
  	}
  
  	sorted := sort.StringSlice(jobs.Values())
  	sorted.Sort()
  
  	var tasks []task
  	for _, name := range sorted {
  		tasks = append(tasks, ar.calculateTasksForUnit(dState, cState, name)...)
  	}
  
  	if len(tasks) == 0 {
  		return nil
  	}
  
  	reloadTask := task{typ: taskTypeReloadUnitFiles, reason: taskReasonAlwaysReloadUnitFiles}
  	tasks = append(tasks, reloadTask)
  
  	sort.Sort(sortableTasks(tasks))
  
  	// reload unnecessary if no UnloadUnit/LoadUnit tasks
  	if tasks[0].typ == taskTypeReloadUnitFiles {
  		tasks = tasks[1:]
  	}
  
  	return tasks
  }
docs: // calculateTasksForUnits compares the desired and current state of an Agent.
  // The generated tasks represent what, in order, should be done to make the
  //  desired state match the current state.