<commit_before>(ns staircase.app
  (:use [clojure.tools.logging :only (debug info error)]
        [environ.core :only (env)]
        [staircase.config :only (db-options app-options secrets)]
        staircase.resources.services
        staircase.resources.histories
        staircase.resources.steps)
  (:require [staircase.assets :as assets]
            [staircase.handler :as routing]
            [com.stuartsierra.component :as component]
            [staircase.sessions :as sessions]
            [staircase.data :as data]))

(declare system)

;; Inject dependencies and build up the system.
(defn build-app [options]
  (. (Runtime/getRuntime)
     (addShutdownHook (Thread. (fn [] (component/stop @system)))))
  (component/start
    (let [db (db-options options)]
      (-> (component/system-map
            :asset-pipeline (assets/pipeline :js-dir "/js"
                                             :css-dir "/css"
                                             :engine :v8
                                             :max-age (:web-max-age options)
                                             :as-resource "tools"
                                             :coffee "src/coffee"
                                             :ls     "src/ls"
                                             :less   "src/less")
            :config (app-options options)
            :secrets (secrets options)
            :session-store (sessions/new-pg-session-store)
            :db (data/new-pooled-db db)
            :histories (new-history-resource)
            :services (new-services-resource)
            :steps (new-steps-resource)
            :router (routing/new-router))
          (component/system-using
            {:router [:config :secrets :session-store :services :histories :steps :asset-pipeline]
             :session-store [:db :config]
             :services [:db]
             :steps [:db]
             :histories [:db]})))))

(def system
  (delay
    (info "Building system with settings: " env)<commit_msg>Note to self<commit_after>(ns staircase.app
  (:use [clojure.tools.logging :only (debug info error)]
        [environ.core :only (env)]
        [staircase.config :only (db-options app-options secrets)]
        staircase.resources.services
        staircase.resources.histories
        staircase.resources.steps)
  (:require [staircase.assets :as assets]
            [staircase.handler :as routing]
            [com.stuartsierra.component :as component]
            [staircase.sessions :as sessions]
            [staircase.data :as data]))

(declare system)

;; Inject dependencies and build up the system.
(defn build-app [options]
  (. (Runtime/getRuntime)
     (addShutdownHook (Thread. (fn [] (component/stop @system)))))
  (component/start
    (let [db (db-options options)]
      (-> (component/system-map
            :asset-pipeline (assets/pipeline :js-dir "/js"
                                             :css-dir "/css"
                                             :engine :v8
                                             :max-age (:web-max-age options)
                                             :as-resource "tools"
                                             :coffee "src/coffee"
                                             :ls     "src/ls"
                                             :less   "src/less")
            :config (app-options options)
            :secrets (secrets options)
            :session-store (sessions/new-pg-session-store)
            :db (data/new-pooled-db db)
            :histories (new-history-resource)
            :services (new-services-resource)
            :steps (new-steps-resource)
            :router (routing/new-router))
          (component/system-using
            {:router [:config :secrets :session-store :services :histories :steps :asset-pipeline]
             :session-store [:db :config]
             :services [:db]
             :steps [:db]
             :histories [:db]})))))

;; Todo - should be possible to have multiple instances.
(def system
  (delay
    (info "Building system with settings: " env)
{'fraction_non_alphanumeric': 0.11404796867351934, 'fraction_numerical': 0.0004894762604013706, 'mean_word_length': 1.4814814814814814, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 28, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '336043', 'n_tokens_mistral': 1068, 'n_tokens_neox': 1056, 'n_words': 257}