Greatly simplified background processes

This commit is contained in:
Bryce Covert
2020-07-31 23:15:43 -07:00
parent be9c789003
commit 49f98522c0
6 changed files with 116 additions and 96 deletions

View File

@@ -3,7 +3,9 @@
[auto-ap.utils :refer [by]]
[cemerick.url :as u]
[clojure.data.json :as json]
[config.core :refer [env]]))
[config.core :refer [env]]
[mount.core :as mount]
[yang.scheduler :as scheduler]))
(defn auth-header
([cob-session] (str "{cobSession=" cob-session "}"))
@@ -253,20 +255,20 @@
(update-in provider-accounts [(:providerAccountId a) :accounts] conj a)) provider-accounts)
vals)))
(defonce in-memory-cache (atom []))
(mount/defstate in-memory-cache
:start (doto (atom (get-provider-accounts-with-accounts)) println))
(defonce break? (atom false))
(defn refresh-in-memory-cache []
(try
(println "Refreshing Yodlee in memory cache")
(reset! in-memory-cache (get-provider-accounts-with-accounts))
(catch Exception e
(println e))))
(mount/defstate in-memory-cache-worker
:start (scheduler/every (* 5 60 1000) refresh-in-memory-cache)
:stop (scheduler/stop in-memory-cache-worker))
(defn load-in-memory-cache []
(future
(loop []
(try
(reset! in-memory-cache (get-provider-accounts-with-accounts))
(catch Exception e
(println e)))
(Thread/sleep (* 30 1000 5))
(when-not @break?
(recur)))))
(defn refresh-provider-account [id]
(swap! in-memory-cache