   (let [query '[:find ?task :in $ ?job ?task :where
                 [?job :job/task ?task]
                 [?peer :peer/task ?task]]]
-    (into #{} (mapcat #(first (d/q query db (:db/id %))) job-id tasks))))
+    (into #{} (mapcat #(first (d/q query db job-id (:db/id %))) tasks))))
 
 (defn sort-tasks-by-phase [db tasks]
   (sort-by :task/phase (map (fn [[t]] (d/entity db t)) tasks)))

  (let [db (d/db (:conn log))
        job-seq (job-candidate-seq (all-active-jobs-ids db)
                                   (last-offered-job db))
        candidates (map (partial next-essential-task db) job-seq)]
    (first (filter identity candidates))))

(defn select-nodes [ent]
  (select-keys ent [:node/peer :node/payload :node/ack

       (first)))

(defn job-candidate-seq [job-seq last-offered]
  (if (nil? last-offered)
    job-seq
    (->> (cycle job-seq)
         (drop (inc (.indexOf job-seq last-offered)))
         (take (count job-seq)))))

(defmethod extensions/mark-peer-born Datomic
  [log place]
