dexador icon indicating copy to clipboard operation
dexador copied to clipboard

Retry on typical errors solution

Open gibsonf1 opened this issue 2 years ago • 0 comments

With an increasingly complex systems environment with high parallelism, dex would fail. This code solved all these issues by retrying up to 3 times to work through any temporary network or parallel issues:

(defmethod reliable-dex-post ((repository string)(headers cons)(content t) &key stream)
  (if (or (pathnamep content)
	  (stringp content)
	  (listp content)
	  )
      (let ((retry 0))
	(multiple-value-bind (result http-status response-hash uri st)
	    (restart-case
		(handler-bind (((or type-error usocket:ns-try-again-condition
				    sb-sys:io-timeout usocket:timeout-error
				    dexador.error:http-request-internal-server-error
				    )
				 #'(lambda (c)
				     (incf retry)
				     (if (< retry 4)
					 (progn
					   (verbose:warn :reliable-dex "RETRY from error ~A repository ~A" c repository)
					   (invoke-restart 'dex-restart repository headers content stream))
					 (process-error c))))
			       (error #'(lambda (c)
					  (print content)
					  (process-error c)))
			       )
		  (dex:post
		   repository
		   :headers headers
		   :content content
		   :want-stream stream
		   ))
	      (dex-restart (&optional repository headers content stream)
		(dex:post repository
			  :headers headers
			  :content content
			  :want-stream stream
			  ))
	      )
	  (unless stream
	    (close st))
	  (values result http-status response-hash uri st)))
      (verbose:error :reliable-dex-post "Bad Content ~A for repository ~A with headers ~A"
		     content repository headers)))

gibsonf1 avatar Dec 03 '22 13:12 gibsonf1