Makes new square loading much faster, parallel.
This commit is contained in:
@@ -637,59 +637,59 @@
|
||||
|
||||
(defn upsert-all [ & clients]
|
||||
(capture-context->lc
|
||||
(->> (apply get-square-clients clients)
|
||||
(s/->source)
|
||||
(s/filter (fn [client]
|
||||
(seq (filter :square-location/client-location (:client/square-locations client)))))
|
||||
(s/map (fn [client]
|
||||
(with-context-as (merge lc {:client (:client/code client)}) lc
|
||||
(log/info ::import-started)
|
||||
(mark-integration-status client {:integration-status/last-attempt (coerce/to-date (time/now))})
|
||||
(log/info ::starting-upsert)
|
||||
(->> (apply get-square-clients clients)
|
||||
(s/->source)
|
||||
(s/filter (fn [client]
|
||||
(seq (filter :square-location/client-location (:client/square-locations client)))))
|
||||
(s/map (fn [client]
|
||||
(with-context-as (merge lc {:client (:client/code client)}) lc
|
||||
(log/info ::import-started)
|
||||
(mark-integration-status client {:integration-status/last-attempt (coerce/to-date (time/now))})
|
||||
|
||||
(->
|
||||
(de/chain (upsert-locations client)
|
||||
(fn [_]
|
||||
(mu/with-context lc
|
||||
(log/info ::upsert-orders-started)
|
||||
(upsert client)))
|
||||
(fn [_]
|
||||
(mu/with-context lc
|
||||
(log/info ::upsert-settlements-started)
|
||||
(upsert-settlements client)))
|
||||
(fn [_]
|
||||
(mu/with-context lc
|
||||
(log/info ::upsert-refunds-started)
|
||||
(upsert-refunds client)))
|
||||
(fn [_]
|
||||
(mu/with-context lc
|
||||
(log/info ::upsert-done))
|
||||
(mark-integration-status client {:integration-status/state :integration-state/success
|
||||
:integration-status/last-updated (coerce/to-date (time/now))})))
|
||||
(de/catch (fn [e]
|
||||
(mu/with-context lc
|
||||
(let [data (ex-data e)]
|
||||
(log/info ::upsert-all-failed
|
||||
:severity :warn
|
||||
:exception e)
|
||||
(cond (= (:status data) 401)
|
||||
(mark-integration-status client {:integration-status/state :integration-state/unauthorized
|
||||
:integration-status/message (-> data :body str)})
|
||||
(->
|
||||
(de/chain (upsert-locations client)
|
||||
(fn [_]
|
||||
(mu/with-context lc
|
||||
(log/info ::upsert-orders-started)
|
||||
(upsert client)))
|
||||
(fn [_]
|
||||
(mu/with-context lc
|
||||
(log/info ::upsert-settlements-started)
|
||||
(upsert-settlements client)))
|
||||
(fn [_]
|
||||
(mu/with-context lc
|
||||
(log/info ::upsert-refunds-started)
|
||||
(upsert-refunds client)))
|
||||
(fn [_]
|
||||
(mu/with-context lc
|
||||
(log/info ::upsert-done))
|
||||
(mark-integration-status client {:integration-status/state :integration-state/success
|
||||
:integration-status/last-updated (coerce/to-date (time/now))})))
|
||||
(de/catch (fn [e]
|
||||
(mu/with-context lc
|
||||
(let [data (ex-data e)]
|
||||
(log/info ::upsert-all-failed
|
||||
:severity :warn
|
||||
:exception e)
|
||||
(cond (= (:status data) 401)
|
||||
(mark-integration-status client {:integration-status/state :integration-state/unauthorized
|
||||
:integration-status/message (-> data :body str)})
|
||||
|
||||
(= (:status data) 503)
|
||||
(mark-integration-status client {:integration-status/state :integration-state/failed
|
||||
:integration-status/message (-> data :body str)})
|
||||
:else
|
||||
(mark-integration-status client {:integration-status/state :integration-state/failed
|
||||
:integration-status/message (or (ex-message e)
|
||||
(str e))}))))))))))
|
||||
(s/buffer 5)
|
||||
(s/realize-each)
|
||||
(s/reduce conj []))))
|
||||
(= (:status data) 503)
|
||||
(mark-integration-status client {:integration-status/state :integration-state/failed
|
||||
:integration-status/message (-> data :body str)})
|
||||
:else
|
||||
(mark-integration-status client {:integration-status/state :integration-state/failed
|
||||
:integration-status/message (or (ex-message e)
|
||||
(str e))}))))))))))
|
||||
(s/buffer 5)
|
||||
(s/realize-each)
|
||||
(s/reduce conj []))))
|
||||
|
||||
(defn do-upsert-all [& clients]
|
||||
(mu/with-context {:background-job "Square 3"}
|
||||
(mu/trace
|
||||
::upsert-all
|
||||
[:clients clients]
|
||||
@(apply upsert-all clients))))
|
||||
(mu/trace
|
||||
::upsert-all
|
||||
[:clients clients]
|
||||
@(apply upsert-all clients)))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user