<commit_before>(ns vignette.util.consul
  (:require [consul.core :as consul]
            [environ.core :refer [env]]))

(def default-consul-hostname "localhost")
(def default-consul-http-port 8500)
(def default-service-query-tag "production")

(def service-query-tag (env :consul-query-tag default-service-query-tag))

(def env-consul-conn {:scheme      :http
                      :server-name (env :consul-hostname default-consul-hostname)
                      :server-port (env :consul-http-port default-consul-http-port)})

(def pick-service-entry-fn rand-nth)

(defn- response->address [response]
  (when (not-empty response)
    (let [entry (pick-service-entry-fn response)]
      (let [address (-> entry :Node :Address)
            port (-> entry :Service :Port)]
        (if (not (or (nil? address) (nil? port)))
          {:address address, :port port})))))

(defprotocol Consul
  (query-service [this service tag]))

(defrecord ConnConsul [consul-conn] Consul
  (query-service [_ service tag]
    (consul/service-health
      consul-conn service :passing? true :tag tag)))

(def create-consul (ConnConsul. env-consul-conn))

(defn find-service
  ([consul service]
   (find-service consul service service-query-tag))
  ([consul service tag]
   (response->address (query-service consul service tag))))

(defn ->uri [service] (str "http://" (service :address) ":" (service :port)))
<commit_msg>use new consul default prod tag<commit_after>(ns vignette.util.consul
  (:require [consul.core :as consul]
            [environ.core :refer [env]]))

(def default-consul-hostname "localhost")
(def default-consul-http-port 8500)
(def default-service-query-tag "prod")

(def service-query-tag (env :consul-query-tag default-service-query-tag))

(def env-consul-conn {:scheme      :http
                      :server-name (env :consul-hostname default-consul-hostname)
                      :server-port (env :consul-http-port default-consul-http-port)})

(def pick-service-entry-fn rand-nth)

(defn- response->address [response]
  (when (not-empty response)
    (let [entry (pick-service-entry-fn response)]
      (let [address (-> entry :Node :Address)
            port (-> entry :Service :Port)]
        (if (not (or (nil? address) (nil? port)))
          {:address address, :port port})))))

(defprotocol Consul
  (query-service [this service tag]))

(defrecord ConnConsul [consul-conn] Consul
  (query-service [_ service tag]
    (consul/service-health
      consul-conn service :passing? true :tag tag)))

(def create-consul (ConnConsul. env-consul-conn))

(defn find-service
  ([consul service]
   (find-service consul service service-query-tag))
  ([consul service tag]
   (response->address (query-service consul service tag))))

(defn ->uri [service] (str "http://" (service :address) ":" (service :port)))

{'fraction_non_alphanumeric': 0.15198863636363635, 'fraction_numerical': 0.002840909090909091, 'mean_word_length': 3.333846153846154, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 13, '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': '5082204', 'n_tokens_mistral': 927, 'n_tokens_neox': 912, 'n_words': 239}