                          (get-in result [:min-required-peers job t] 1)))
                    tasks)
          result
-         (update-in result [:allocations] dissoc job))))
+         (remove-job result job))))
    replica
    (:jobs replica)))
 

  [replica]
  (throw (ex-info (format "Job scheduler %s not recognized" (:job-scheduler replica))
                  {:job-scheduler (:job-scheduler replica)})))

(defn current-job-allocations [replica]
  (into {}

   replica
   (:jobs replica)))

(defn remove-job [replica job]
  (let [peers (sort (replica->job-peers replica job))] 
    (-> replica
        (update-in [:allocations] dissoc job)
        (update-in [:peer-state] (fn [peer-state]
                                   (reduce (fn [ps peer] 
                                             (assoc ps peer :idle)) 
                                           peer-state 
                                           peers))))))

(defn deallocate-starved-jobs
  "Strips out allocations from jobs that no longer meet the minimum number
   of peers. This can happen if a peer leaves from a running job."
