          git-ref  :ref
          script   :script}  (read-body message)
 
-        workspace-path      (join "/" [(config :workspaces-path)
+        workspace-path      (join "/" [(global-config/config :workspaces-path)
                                        job-name
                                        "workspace"])
 
-        existing-log        (io/get-key (config :log-key))
+        existing-log        (io/get-key (global-config/config :log-key))
 
         repo                (git/fresh-clone git-url workspace-path git-ref)
         build               (runner/run! workspace-path script)

    (println "superset?" completed-job-names upstream-job-names)
    (doto (superset? completed-job-names upstream-job-names) println)))

(comment
  (let [config {:bucket "cu-test"
                :aws-credentials
                {:access-key "AKIAINNOTL4KCMANKE5Q"
                 :secret-key "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"}}
        prefix ""]
    ; (dorun (map io/delete
    (io/ls prefix)
    ; ))
    ))

(defn deleting-consumer
  [client f]
  (fn [message]
    (let [ret (f message)]
      (println "--------------------------------------")
      (println "Ran:" f)
      (println "Return value:" ret)
      (println "Deleting message:" message)
      (println (sqs/delete client message))
      ret)))

(defn -main [command & args]
  (case command

    "parser"
    (let [client (sqs-client)
          q (sqs-queue client "cu-pushes")]
      (println "Starting parser")
      (dorun
        (map (deleting-consumer client (partial process-push-message client))
             (sqs/polling-receive client q
                                  :max-wait (config :queue-max-wait)
                                  :period (config :queue-period)
                                  :limit 10))))

    "worker"
    (let [client (sqs-client)
          q (sqs-queue client "cu-builds")]
      (println "Starting worker")
      (dorun
        (map (deleting-consumer client
                                (runner/decide-whether-to
                                  run-job-from-message
                                  upstream-all-passed?))
             (filter no-pending-upstream-jobs?
                     (sqs/polling-receive client q
                                          :max-wait (config :queue-max-wait)
                                          :period (config :queue-period)
                                          :limit 10)))))

    nil))

    )
  (:gen-class))

(defn- sqs-client [credentials] (apply sqs/create-client credentials))
(defn- sqs-queue [client queue-name] (sqs/create-queue client queue-name))

(defn- workspace-dir [basedir url]
  (join "/" [basedir (last (split url #"/")) "workspace"]))

(defn process-push-message [client workspaces-path {payload :body}]
  (when-let [url (payload/clone-target-url payload)]
    (let [repo (git/fresh-clone url
                                (workspace-dir workspaces-path url)
                                "master")
          uuid (str (java.util.UUID/randomUUID))]
      (println "Iterating over jobs for" url)
