From 181e423e84ef3798b6a27d9fa8acdf7ddf58f6b2 Mon Sep 17 00:00:00 2001 From: Timo Kramer <4785848+TimoKramer@users.noreply.github.com> Date: Tue, 26 Apr 2022 07:41:01 +0200 Subject: [PATCH] ci: retry release with backoff (#518) - This should resolve the problem with releasing on CircleCI - Added an exponential backoff to the release function --- build.clj | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/build.clj b/build.clj index 5ee975ae1..d901430de 100644 --- a/build.clj +++ b/build.clj @@ -42,15 +42,33 @@ (dd/deploy {:installer :remote :artifact jar-file :pom-file (b/pom-path {:lib lib :class-dir class-dir})})) +(defn fib [a b] + (lazy-seq (cons a (fib b (+ a b))))) + +(defn fib-backoff [exec-fn test-fn] + (loop [retries (take 10 (fib 1 2))] + (let [result (exec-fn)] + (if (test-fn result) + result + (when-let [sleep-ms (first retries)] + (println "Retrying with remaining retries: " retries) + (println "Request returned: " result) + (Thread/sleep (* 1000 sleep-ms)) + (recur (rest retries))))))) + +(defn try-release [] + (try (gh/overwrite-asset {:org "replikativ" + :repo (name lib) + :tag version + :commit current-commit + :file jar-file + :content-type "application/java-archive"}) + (catch clojure.lang.ExceptionInfo e + (:status (ex-data e))))) + (defn release [_] - (Thread/sleep 1000) - (-> (gh/overwrite-asset {:org "replikativ" - :repo (name lib) - :tag version - :commit current-commit - :file jar-file - :content-type "application/java-archive"}) + (-> (fib-backoff try-release #(>= 400 %)) :url println))