enormous refactor but simplified much!
This commit is contained in:
45
src/clj/auto_ap/import/yodlee2.clj
Normal file
45
src/clj/auto_ap/import/yodlee2.clj
Normal file
@@ -0,0 +1,45 @@
|
||||
(ns auto-ap.import.yodlee2
|
||||
(:require [auto-ap.datomic :refer [conn]]
|
||||
[auto-ap.import.transactions :as t]
|
||||
[auto-ap.import.yodlee :as y]
|
||||
[auto-ap.utils :refer [allow-once]]
|
||||
[auto-ap.yodlee.core2 :as client2]
|
||||
[datomic.api :as d]
|
||||
[mount.core :as mount]
|
||||
[unilog.context :as lc]
|
||||
[yang.scheduler :as scheduler]))
|
||||
|
||||
(defn import-yodlee2 []
|
||||
(lc/with-context {:source "Import yodlee2 transactions"}
|
||||
(let [import-batch (t/start-import-batch :import-source/yodlee2 "Automated yodlee2 user")]
|
||||
(try
|
||||
(let [account-lookup (d/q '[:find ?ya ?ba ?cd
|
||||
:in $
|
||||
:where
|
||||
[?ba :bank-account/yodlee-account ?y]
|
||||
[?c :client/bank-accounts ?ba]
|
||||
[?c :client/code ?cd]
|
||||
[?y :yodlee-account/id ?ya]]
|
||||
(d/db conn))]
|
||||
(doseq [[yodlee-account bank-account client-code] account-lookup
|
||||
transaction (client2/get-specific-transactions client-code yodlee-account)]
|
||||
(t/import-transaction! import-batch (assoc (y/yodlee->transaction transaction)
|
||||
:transaction/bank-account bank-account
|
||||
:transaction/client [:client/code client-code])))
|
||||
|
||||
(t/finish! import-batch))
|
||||
(catch Exception e
|
||||
(t/fail! import-batch e))))))
|
||||
|
||||
|
||||
|
||||
(def import-yodlee2 (allow-once import-yodlee2))
|
||||
|
||||
|
||||
(mount/defstate import-worker
|
||||
:start (scheduler/every (* 1000 60 60 4) import-yodlee2)
|
||||
:stop (scheduler/stop import-worker))
|
||||
|
||||
(mount/defstate account-worker
|
||||
:start (scheduler/every (* 5 60 1000) client2/upsert-accounts)
|
||||
:stop (scheduler/stop account-worker))
|
||||
Reference in New Issue
Block a user