starts logging in the event of an issue.

This commit is contained in:
2023-03-30 11:11:17 -07:00
parent 744c4b60f7
commit c8ada656c8
3 changed files with 28 additions and 38 deletions

View File

@@ -1,7 +1,7 @@
(ns auto-ap.jobs.restore-from-backup
(:require
[amazonica.aws.s3 :as s3]
[auto-ap.datomic]
[auto-ap.datomic :refer [transact-with-backoff]]
[auto-ap.ledger]
[auto-ap.jobs.core :refer [execute]]
[clojure.edn :as edn]
@@ -43,32 +43,11 @@
(def loaded (atom #{}))
(defn backoff [n]
(let [base-timeout 500
max-timeout 300000 ; 5 minutes
max-retries 10
backoff-time (* base-timeout (Math/pow 2 (min n max-retries)))]
(min (+ backoff-time (rand-int base-timeout)) max-timeout)))
(defn upsert-batch-impl
([batch ] (upsert-batch-impl batch 0))
([batch attempt]
(try
(dc/transact auto-ap.datomic/conn {:tx-data batch})
batch
(catch Exception e
(if (< attempt 10)
(do
(Thread/sleep (backoff attempt))
(upsert-batch-impl batch (inc attempt)))
(throw e))))))
(defn upsert-batch
[batch]
(de/future-with request-pool
(upsert-batch-impl batch)))
(transact-with-backoff batch)
batch))
(defn pull-file [backup which]
(mu/log ::pulling-file