         (update-in [:deployment :jobs] remove-dead-peer id)) 
     state))
 
-(defmethod msg-controller :job/completed-task [[_ {:keys [peer-id job-id task] :as msg}] state]
+(defmethod msg-controller :job/completed-task 
+  [[_ {:keys [peer-id job-id task] :as msg}] state]
   ;(println "Completed task " msg)
   (if (is-tracking? msg state)
     (update-in state [:deployment :jobs job-id :tasks] dissoc peer-id) 
     state))
 
-(defmethod msg-controller :deployment/kill-job [[_ {:keys [id] :as msg}] state]
+(defmethod msg-controller :deployment/kill-job 
+  [[_ {:keys [id] :as msg}] state]
   ;; Managed to create a kill-job entry with a nil job. Should fix this upstream
   ;; {:entry {:args {:job nil}, :fn :kill-job, :message-id 63, :created-at 1423218732944}}}
   (if (and (is-tracking? msg state) id)


(defmulti msg-controller (fn [[type _] _] type))

(defmethod msg-controller :deployment/listing [[_ msg] state]
  (assoc-in state [:deployments] msg))

(defn is-tracking? [msg state]
  (= (:tracking-id msg)
     (get-in state [:deployment :tracking-id])))

(defmethod msg-controller :deployment/up-to-date [[_ {:keys [tracking-id last-id] :as msg}] state]
  (if (and (is-tracking? msg state)
           (= last-id (:message-id-max (:deployment state))))
    (assoc-in state [:deployment :up-to-date?] true)
    state))

(defmethod msg-controller :deployment/submitted-job [[_ {:keys [id] :as msg}] state]
  (if (is-tracking? msg state)
    (assoc-in state [:deployment :jobs id] (assoc msg :status :submitted)) 
    state))

(defmethod msg-controller :job/peer-assigned [[_ {:keys [peer-id task job-id] :as msg}] state]
  ;(println "Peer assigned " msg)
  (if (is-tracking? msg state)
    (assoc-in state [:deployment :jobs job-id :tasks peer-id] task)
    state))

(defmethod msg-controller :deployment/peer-joined [[_ {:keys [id] :as msg}] state]
  ;(println "Peer joined " msg)
  (if (is-tracking? msg state)
    (update-in state [:deployment :peers] union #{id}) 

;     (update-in state [:deployment :peers] union #{id}) 
;     state))

(defmethod msg-controller :deployment/peer-notify-joined-accepted 
  [[_ {:keys [id] :as msg}] state]
  ;(println "Peer immediate notify joined " msg)
  (if (is-tracking? msg state)
    (update-in state [:deployment :peers] union #{id}) 
