     (files/guess-mime-type-by-content (:response_body_bytes download))))
 
 (defmethod mime-type-dispatch "application/pdf" [download]
-  (counter "MIME types" "PDF")
+  (h/counter "MIME types" "PDF")
   (debug "mime-type-dispatch got PDF from " (:request_uri download))
   (handle-pdf download))
 
 (defmethod mime-type-dispatch "text/html" [download]
-  (counter "MIME types" "HTML")
+  (h/counter "MIME types" "HTML")
   (debug "mime-type-dispatch got HTML from " (:request_uri download))
   (run-scrapers download))
 
 (defmethod mime-type-dispatch :default [download]
-  (counter "MIME types" "unknown")
+  (h/counter "MIME types" "unknown")
   (warn "mime-type-dispatch found no handler for " (:request_uri download)))
 
 
 ;;; Step 1: dispatch on Status code of the download
 
 (defn status-code-dispatch [download]
-  (counter "Status codes" (str (:response_status_code download)))
+  (h/counter "Status codes" (str (:response_status_code download)))
   (if (= 200 (:response_status_code download))
     (mime-type-dispatch download)
     (warn "status-code-dispatch saw "


;; Step 3 (for HTML): Run scrapers

(defn handle-scraped [record]
  [101 (pr-str record)])

(defn handle-scraper-output [output]
  (filter identity
          (map (fn [line]
                 (when (seq (.trim line))
                   (handle-scraped (read-json-string line))))
               (.split output "\n"))))

(defn run-scrapers [download]
  (handle-scraper-output
   (with-out-str
     (.setWriter *ruby-context* *out*)
     (.setReader *ruby-context* (StringReader. *raw-input*))
     (.eval *ruby* "$runner.parse_all_from_stream($stdin)"))))


;;; Step 4 (for PDFs): convert to HTML

;;; Step 3 (for PDFs): dispatch on presence of Docid

(defn handle-pdf [download]
  (if-let [docid (ids/get-docid "altcrawl" (:request_uri download))]
    (do (debug "handle-pdf got docid " docid " for " (:request_uri download))
        (h/counter "PDF files" "with docid")
        (convert-pdf docid download))
    (do (warn "handle-pdf found no docid for " (:request_uri download))
        (h/counter "PDF files" "no docid"))))


;;; Step 2: dispatch on MIME type of the download
