<commit_before>(ns buyme-aggregation-backend.sources
  (:require [buyme-aggregation-backend.db :as db]
            [clojure.core.async :refer [chan go-loop <! alt!]]
            [chime :refer [chime-ch]]
            [clj-time.core :as t]
            [clj-time.periodic :refer [periodic-seq]]
            [mount.core :refer [defstate]]
            [taoensso.timbre :refer [info]]))

(def sources (atom {}))

(defn get-source-settings []
  (db/get-all-sources))

(defn start-source []
  (let [command-ch (chan)
        fetch-timer-ch (chime-ch (rest (periodic-seq (t/now) (-> 5 t/seconds))))]
    (go-loop
      [state :stopped]
      (let [new-state
            (case state
              :shutdown (do
                          (print "shutting down...")
                          :stopped)
              :stopped (let [command (<! command-ch)]
                         (condp = command
                           :start :running
                           :default :stopped))
              :running (alt!
                         command-ch ([command] (condp = command
                                                 :stop :shutdown
                                                 :default :running))
                         fetch-timer-ch (do
                                          (println "got a chime")
                                          :running)))]
        (recur new-state)))
    command-ch))

(defn stop-all-sources []
  (println "stopping"))

(defstate sources
          :start (->> (get-source-settings) (map start-source))
          :stop (stop-all-sources))
<commit_msg>defaults do not work that way<commit_after>(ns buyme-aggregation-backend.sources
  (:require [buyme-aggregation-backend.db :as db]
            [clojure.core.async :refer [chan go-loop <! alt!]]
            [chime :refer [chime-ch]]
            [clj-time.core :as t]
            [clj-time.periodic :refer [periodic-seq]]
            [mount.core :refer [defstate]]
            [taoensso.timbre :refer [info]]))

(def sources (atom {}))

(defn get-source-settings []
  (db/get-all-sources))

(defn start-source []
  (let [command-ch (chan)
        fetch-timer-ch (chime-ch (rest (periodic-seq (t/now) (-> 5 t/seconds))))]
    (go-loop
      [state :stopped]
      (let [new-state
            (case state
              :shutdown (do
                          (print "shutting down...")
                          :stopped)
              :stopped (let [command (<! command-ch)]
                         (condp = command
                           :start :running
                           :stopped))
              :running (alt!
                         command-ch ([command] (condp = command
                                                 :stop :shutdown
                                                 :running))
                         fetch-timer-ch (do
                                          (println "got a chime")
                                          :running)))]
        (recur new-state)))
    command-ch))

(defn stop-all-sources []
  (println "stopping"))

(defstate sources
          :start (->> (get-source-settings) (map start-source))
          :stop (stop-all-sources))

{'fraction_non_alphanumeric': 0.1286072772898369, 'fraction_numerical': 0.0006273525721455458, 'mean_word_length': 1.217663421418637, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 16, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6427191', 'n_tokens_mistral': 878, 'n_tokens_neox': 863, 'n_words': 201}