diff --git a/src/clj/auto_ap/handler.clj b/src/clj/auto_ap/handler.clj index e19a6fd4..d02f23e1 100644 --- a/src/clj/auto_ap/handler.clj +++ b/src/clj/auto_ap/handler.clj @@ -68,9 +68,6 @@ (def app-routes (routes (wrap-transaction api-routes) - (context "/api" [] events/routes) - - static-routes)) (defn wrap-logging [handler] diff --git a/src/clj/auto_ap/routes/events.clj b/src/clj/auto_ap/routes/events.clj index ad6ca5be..a9707ba6 100644 --- a/src/clj/auto_ap/routes/events.clj +++ b/src/clj/auto_ap/routes/events.clj @@ -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"}}))) diff --git a/src/clj/auto_ap/server.clj b/src/clj/auto_ap/server.clj index c7cacad8..c51b99c6 100644 --- a/src/clj/auto_ap/server.clj +++ b/src/clj/auto_ap/server.clj @@ -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]] diff --git a/src/clj/auto_ap/yodlee/import.clj b/src/clj/auto_ap/yodlee/import.clj index dc3a4552..48bc772f 100644 --- a/src/clj/auto_ap/yodlee/import.clj +++ b/src/clj/auto_ap/yodlee/import.clj @@ -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))