   (:use [circle.logging :only (add-file-appender)])
   (:use [circle.util.except :only (throw-if throw-if-not)])
   (:use [clojure.tools.logging :only (with-logs error infof errorf)]))
+
+;; Clojure has queues, they're not very well documented. They work
+;; like other standard clojure structures, and support peek, pop,
+;; conj.
+
+(def queue (ref clojure.lang.PersistentQueue/EMPTY))
+
+(def in-progress (ref #{}))
+(def max-in-progress 5)
+(def run-agent (agent nil))
+
+(declare run-first)
 
 (defn start* [build]
   (dosync

     (when (and (-> @b :failed?) cleanup-on-failure) 
       (cleanup-nodes b)))))



(defn log-result [b]
  (if (build/successful? b)
    (do
      (println "Build successful" (build/build-name b))
      (infof "Build %s successful" (build/build-name b)))
    (errorf "Build %s failed" (build/build-name b))))

(defn finished [b]
  (dosync
   (infof "removing build %s from in-progress" (build/build-name b))
   (alter in-progress disj b))
  (run-first))

(defn run-build [b & {:keys [cleanup-on-failure]
                          :or {cleanup-on-failure true}}]
