   (let [worker-agent (agent worker
                             :error-mode :continue
                             :error-handler (fn [the-agent exception]
-                                             (log/warn "Error with cache worker" @the-agent)
-                                             (log/warn (.getMessage exception))
-                                             (log/warn "=== END EXCEPTION ===")
-                                             (send-off the-agent process-next-job)))]
+                                             (let [job-id (:last-job-id @the-agent)]
+                                               (log/error "Error with cache worker" @the-agent)
+                                               (log/error "Last job ID" job-id)
+                                               (log/error exception)
+                                               (log/error "=== END EXCEPTION ===")
+                                               (reset-job job-id)
+                                               (send-off the-agent process-next-job))))]
     (send worker-agent #(assoc % :kill false))
     (send-off worker-agent process-next-job)))
 

(defn- find-and-claim-unprocessed
  "Find the next unprocessed map-reduce job and claim it.
   Returns job."
  [worker]
  (coll/find-and-modify *work-collection*
                        {:status "unprocessed"}
                        {"$set" {:status "processing"}}
                        :sort {:created 1}))

(defn- work-job
  "Given a map-reduce job, tells Mongo to perform the job.

  [worker]
  (when-not (:kill worker)
    (with-db (get-in worker [:cache :database])
      (if-let [job (find-and-claim-unprocessed)]
        (let [job-id (:_id job)]
          (log/info "Aggregation" job-id "started")
          (send *agent* #(assoc-in % [:last-job-id] job-id))
          (work-job worker job)
          (update-cache worker job)
          (send *agent* #(update-in % [:processed] inc))
          (log/info "Aggregation" job-id "processed"))
        (do
          (clean-cache (:cache worker))
          (Thread/sleep *wait-time*)))
