<commit_before>(ns mdr2.repair.async
  (:require
   [clojure.core.async :refer [<! close! go-loop]]
   [mdr2.repair.core :as archive]
   [mdr2.queues :as queues]
   [mount.core :refer [defstate]]
   [mdr2.repair.core :as repair]
   [failjure.core :as fail]
   [clojure.tools.logging :as log]))

(defstate repair-consumer
  :start (go-loop []
           (when-let [production (<! queues/repair)]
             (let [p (repair/repair production)]
               (when (fail/failed? p)
                 (log/errorf "Failed to repair %s" production)))
             (recur)))

  :stop (when repair-consumer
          (close! repair-consumer)))<commit_msg>Log also the cause of a failure when logging<commit_after>(ns mdr2.repair.async
  (:require
   [clojure.core.async :refer [<! close! go-loop]]
   [mdr2.repair.core :as archive]
   [mdr2.queues :as queues]
   [mount.core :refer [defstate]]
   [mdr2.repair.core :as repair]
   [failjure.core :as fail]
   [clojure.tools.logging :as log]))

(defstate repair-consumer
  :start (go-loop []
           (when-let [production (<! queues/repair)]
             (fail/when-let-failed? [cause (repair/repair production)]
               (log/errorf "Failed to repair %s because %s" production cause))
             (recur)))

  :stop (when repair-consumer
          (close! repair-consumer)))
{'fraction_non_alphanumeric': 0.146948003014318, 'fraction_numerical': 0.006028636021100226, 'mean_word_length': 2.6685082872928176, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5190982', 'n_tokens_mistral': 466, 'n_tokens_neox': 454, 'n_words': 109}