               (recur)))))))
 
 
-(defn run-jobs []
-  ;; we read the job queue at a moment in time.  Anything added after this will
-  ;; have to wait for the next run.
-  (let [jobs (filter #(= (:status @%) :not-started)
-                     @job-queue)
-        files (into {} (map (fn [job]
+
+(def job-runner (agent []))
+
+(defn run-jobs [jobs]
+  (let [files (into {} (map (fn [job]
                               (let [outfile (file output-dir (str (:id @job) ".txt"))
                                     outfh (MarcXmlWriter.
                                            (FileOutputStream. outfile))]

             :file-ready? true)

      ;; Mark jobs as completed
      (swap! job assoc :status :completed)))
  "OK")




                                      :fh outfh}]))
                            jobs))]

    (let [queue (LinkedBlockingQueue. 512)
          workers (doall
                   (map #(run-worker % jobs files queue)
