aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristopher Baines <mail@cbaines.net>2020-04-27 19:09:32 +0100
committerChristopher Baines <mail@cbaines.net>2020-04-27 19:09:32 +0100
commit5251f1f58de2d0786592beaaf1fbed4b052e9283 (patch)
tree54128e4810fda79874dcc605f3bf300f8b5db581
parent200bb753110b0e31ab242085c54cf97df58c1888 (diff)
downloadbuild-coordinator-5251f1f58de2d0786592beaaf1fbed4b052e9283.tar
build-coordinator-5251f1f58de2d0786592beaaf1fbed4b052e9283.tar.gz
Retry requests a few times if they error
This should make agent <-> coordinator communication more failure tolerant.
-rw-r--r--guix-build-coordinator/agent-messaging/http.scm63
1 files changed, 34 insertions, 29 deletions
diff --git a/guix-build-coordinator/agent-messaging/http.scm b/guix-build-coordinator/agent-messaging/http.scm
index 9b8b9ac..6c5bf51 100644
--- a/guix-build-coordinator/agent-messaging/http.scm
+++ b/guix-build-coordinator/agent-messaging/http.scm
@@ -366,35 +366,40 @@ port. Also, the port used can be changed by passing the --port option.\n"
(coordinator-uri-for-path coordinator-uri
path))
- (let-values (((response body)
- (http-request uri
- #:method method
- #:body (scm->json-string body)
- #:decode-body? #f
- #:headers
- `((Authorization . ,auth-value)
- ,@headers))))
- (if (>= (response-code response) 400)
- (begin
- (simple-format
- (current-error-port)
- "error: coordinator-http-request: ~A ~A: ~A\n"
- method path (response-code response))
- (error (catch #t
- (lambda ()
- (if (eq? '(application/json (charset . "utf-8"))
- (response-content-type response))
- (json-string->scm (utf8->string body))
- (utf8->string body)))
- (lambda (key . args)
- (simple-format
- (current-error-port)
- "error decoding body ~A ~A\n"
- key args)
- #f))))
- (values
- (json-string->scm (utf8->string body))
- response))))
+ (define (make-request)
+ (let-values (((response body)
+ (http-request uri
+ #:method method
+ #:body (scm->json-string body)
+ #:decode-body? #f
+ #:headers
+ `((Authorization . ,auth-value)
+ ,@headers))))
+ (if (>= (response-code response) 400)
+ (begin
+ (simple-format
+ (current-error-port)
+ "error: coordinator-http-request: ~A ~A: ~A\n"
+ method path (response-code response))
+ (error (catch #t
+ (lambda ()
+ (if (eq? '(application/json (charset . "utf-8"))
+ (response-content-type response))
+ (json-string->scm (utf8->string body))
+ (utf8->string body)))
+ (lambda (key . args)
+ (simple-format
+ (current-error-port)
+ "error decoding body ~A ~A\n"
+ key args)
+ #f))))
+ (values
+ (json-string->scm (utf8->string body))
+ response))))
+
+ (retry-on-error make-request
+ #:times 3
+ #:delay 10))
(define (submit-status coordinator-uri agent-uuid password
status)