revamped logging!
This commit is contained in:
@@ -5,30 +5,33 @@
|
||||
[auto-ap.time :as time]
|
||||
[clj-time.coerce :as coerce]
|
||||
[mount.core :as mount]
|
||||
[yang.scheduler :as scheduler]))
|
||||
[yang.scheduler :as scheduler]
|
||||
[unilog.context :as lc]
|
||||
[clojure.tools.logging :as log]))
|
||||
|
||||
(defn close-auto-invoices []
|
||||
(try
|
||||
|
||||
(let [invoices-to-close (d/query {:query {:find ['?e]
|
||||
:in ['$ '?today]
|
||||
:where ['[?e :invoice/automatically-paid-when-due true]
|
||||
'[?e :invoice/status :invoice-status/unpaid]
|
||||
'[?e :invoice/due ?d]
|
||||
'[(<= ?d ?today)]]}
|
||||
:args [(d/db conn) (coerce/to-date (time/local-now))]})]
|
||||
(println "Closing " (count invoices-to-close) "automatic invoices")
|
||||
(some->> invoices-to-close
|
||||
seq
|
||||
(lc/with-context {:source "close-auto-invoices"}
|
||||
(try
|
||||
|
||||
(let [invoices-to-close (d/query {:query {:find ['?e]
|
||||
:in ['$ '?today]
|
||||
:where ['[?e :invoice/automatically-paid-when-due true]
|
||||
'[?e :invoice/status :invoice-status/unpaid]
|
||||
'[?e :invoice/due ?d]
|
||||
'[(<= ?d ?today)]]}
|
||||
:args [(d/db conn) (coerce/to-date (time/local-now))]})]
|
||||
(log/info "Closing " (count invoices-to-close) "automatic invoices")
|
||||
(some->> invoices-to-close
|
||||
seq
|
||||
|
||||
(mapv (fn [[i]] {:db/id i
|
||||
:invoice/outstanding-balance 0.0
|
||||
:invoice/status :invoice-status/paid}))
|
||||
(d/transact conn)
|
||||
deref)
|
||||
(println "Closed " (count invoices-to-close) "automatic invoices"))
|
||||
(catch Exception e
|
||||
(println (.toString e)))))
|
||||
(mapv (fn [[i]] {:db/id i
|
||||
:invoice/outstanding-balance 0.0
|
||||
:invoice/status :invoice-status/paid}))
|
||||
(d/transact conn)
|
||||
deref)
|
||||
(log/info "Closed " (count invoices-to-close) "automatic invoices"))
|
||||
(catch Exception e
|
||||
(log/error e)))))
|
||||
|
||||
(mount/defstate close-auto-invoices-worker
|
||||
:start (scheduler/every 60000 close-auto-invoices)
|
||||
|
||||
Reference in New Issue
Block a user