Commit e22cd964 authored by Eric Timmons's avatar Eric Timmons
Browse files

Retry cloning 3 times

parent 221f2dee
Loading
Loading
Loading
Loading
+20 −12
Original line number Diff line number Diff line
@@ -580,17 +580,24 @@ include it."
    (log:info "Cloning ~A to ~A" uri-string project-cache)
    (multiple-value-bind (prefix env)
        (authenticated-git-command-list (git-project/git-credentials project))
      (multiple-value-bind (output error-output exit-code)
          (apply
           #'uiop:run-program
           `(,@prefix "clone"
                      "--bare"
                      "--verbose"
                      "--mirror"
                      ,uri-string
                      ,(namestring project-cache))
           :input :interactive
       :output :interactive
       :error-output :interactive
       (run-program-augment-env-args env)))))
           :output '(:string :stripped t)
           :error-output '(:string :stripped t)
           :ignore-error-status t
           (run-program-augment-env-args env))
        (unless (zerop exit-code)
          (format *error-output* "~&git exited with code ~S~%stdout: ~S~%stderr: ~S~%"
                  exit-code output error-output)
          (error 'retriable-error))))))

(defun ensure-remote-release-present-in-cache! (release)
  (let* ((project (release/project release))
@@ -600,7 +607,8 @@ include it."
    (cond
      ((not (uiop:probe-file* project-cache))
       ;; The repo does not exist locally. We need to clone it.
       (clone-release! release))
       (with-retries (:max 3 :sleep 1)
         (clone-release! release)))
      ((not (git-release/commit release))
       ;; We do not have a specific commit requested. Need to fetch from origin
       ;; to make sure we have the latest branches and tags.
+24 −1
Original line number Diff line number Diff line
@@ -8,8 +8,10 @@
          #:puri
          #:split-sequence)
  (:export #:*live-script-location*
           #:retriable-error
           #:run-program-augment-env-args
           #:uri-to-string))
           #:uri-to-string
           #:with-retries))

(in-package #:clpm/utils)

@@ -46,3 +48,24 @@ process."
  "Convert a puri URI to a string."
  (with-output-to-string (s)
    (render-uri uri s)))

(define-condition retriable-error (error)
  ())

(defun call-with-retries (thunk &key (max 3) (sleep 1))
  (let ((num-tries 1))
    (block nil
      (tagbody
       top
         (handler-case
             (return (funcall thunk))
           (retriable-error (e)
             (format *error-output* "~&Get error ~S~%" e)
             (when (< num-tries max)
               (incf num-tries)
               (format *error-output* "Sleeping and retrying~%")
               (sleep sleep)
               (go top))))))))

(defmacro with-retries ((&key (max 3) (sleep 1)) &body body)
  `(call-with-retries (lambda () ,@body) :max ,max :sleep ,sleep))