better way of keeping transactions up to date
This commit is contained in:
@@ -68,9 +68,6 @@
|
||||
(def app-routes
|
||||
(routes
|
||||
(wrap-transaction api-routes)
|
||||
(context "/api" [] events/routes)
|
||||
|
||||
|
||||
static-routes))
|
||||
|
||||
(defn wrap-logging [handler]
|
||||
|
||||
@@ -13,24 +13,3 @@
|
||||
[clojure.tools.logging :as log]
|
||||
[unilog.context :as lc])
|
||||
(:import (org.joda.time DateTime)))
|
||||
|
||||
(defroutes routes
|
||||
(context "/events" []
|
||||
|
||||
(POST "/yodlee-import" {:keys [query-params headers body] :as x}
|
||||
(lc/with-context {:source "Import yodlee transactions"}
|
||||
(let [notification-type (get headers "x-amz-sns-message-type")]
|
||||
(log/info "Received notification " notification-type)
|
||||
(if (= "SubscriptionConfirmation" notification-type)
|
||||
(do
|
||||
(log/info "Responding to confirmation" )
|
||||
(let [json (json/read-str (slurp body))]
|
||||
(log/info json)
|
||||
(http/get (get json "SubscribeURL"))))
|
||||
(do
|
||||
(log/info "importing from yodlee")
|
||||
(yodlee-import/do-import)))))
|
||||
|
||||
{:status 200
|
||||
:body "{}"
|
||||
:headers {"Content-Type" "application/edn"}})))
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
[auto-ap.background.invoices]
|
||||
[auto-ap.square.core]
|
||||
[auto-ap.datomic.migrate]
|
||||
[auto-ap.yodlee.import]
|
||||
[nrepl.server :refer [start-server stop-server]]
|
||||
[config.core :refer [env]]
|
||||
[ring.adapter.jetty :refer [run-jetty]]
|
||||
|
||||
@@ -194,8 +194,17 @@
|
||||
([]
|
||||
(do-import (client/get-transactions)))
|
||||
([transactions]
|
||||
(let [all-bank-accounts (get-all-bank-accounts)
|
||||
transaction->bank-account (comp (by :bank-account/yodlee-account-id all-bank-accounts) :accountId)
|
||||
all-rules (tr/get-all)]
|
||||
(batch-transact (transactions->txs transactions transaction->bank-account (rm/rule-applying-fn all-rules) (get-existing))))))
|
||||
(lc/with-context {:source "Import yodlee transactions"}
|
||||
(do
|
||||
(log/info "importing from yodlee")
|
||||
(let [all-bank-accounts (get-all-bank-accounts)
|
||||
transaction->bank-account (comp (by :bank-account/yodlee-account-id all-bank-accounts) :accountId)
|
||||
all-rules (tr/get-all)]
|
||||
(batch-transact (transactions->txs transactions transaction->bank-account (rm/rule-applying-fn all-rules) (get-existing))))))))
|
||||
|
||||
|
||||
|
||||
|
||||
(mount/defstate import-transaction-worker
|
||||
:start (scheduler/every (* 1000 60 60 4) do-import)
|
||||
:stop (scheduler/stop import-transactions-cleared-against))
|
||||
|
||||
Reference in New Issue
Block a user