aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristopher Baines <mail@cbaines.net>2020-04-27 19:04:56 +0100
committerChristopher Baines <mail@cbaines.net>2020-04-27 19:04:56 +0100
commit200bb753110b0e31ab242085c54cf97df58c1888 (patch)
tree044146808172f3f39fab0bb623cc4d912169e4cc
parent2da92769d3af838bdc5899d3f039e7f441a2ef09 (diff)
downloadbuild-coordinator-200bb753110b0e31ab242085c54cf97df58c1888.tar
build-coordinator-200bb753110b0e31ab242085c54cf97df58c1888.tar.gz
Add a function to retry a thunk a number of times
-rw-r--r--guix-build-coordinator/agent-messaging/http.scm22
1 files changed, 22 insertions, 0 deletions
diff --git a/guix-build-coordinator/agent-messaging/http.scm b/guix-build-coordinator/agent-messaging/http.scm
index 1fd2516..9b8b9ac 100644
--- a/guix-build-coordinator/agent-messaging/http.scm
+++ b/guix-build-coordinator/agent-messaging/http.scm
@@ -330,6 +330,28 @@ port. Also, the port used can be changed by passing the --port option.\n"
agent-path
(string-drop agent-path 1))))))
+(define* (retry-on-error f #:key times delay)
+ (let loop ((attempt 1))
+ (match (with-exception-handler
+ (lambda (exn)
+ (cons #f exn))
+ (lambda ()
+ (cons #t (f)))
+ #:unwind? #t)
+ ((#t . return-value)
+ return-value)
+ ((#f . exn)
+ (if (>= attempt times)
+ (raise-exception exn)
+ (begin
+ (simple-format
+ (current-error-port)
+ "error: ~A, retrying in ~A\n"
+ exn
+ delay)
+ (sleep delay)
+ (loop (+ 1 attempt))))))))
+
(define* (coordinator-http-request coordinator-uri agent-uuid password
path
#:key method body (headers '()))