Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
938 views
in Technique[技术] by (71.8m points)

rest - Curl retry mechanism

I have a script I run to deploy 2 web services and a front-end application. The script calls a method that checks to see if the 2 back-end services are up and running. If so, deem the deploy successful, otherwise revert.

The 2 services sometimes take longer than the front-end to start up. Currently I put in a sleep call to delay the web service check. This allows them time to start up.

I want to remove this sleep and add in a retry mechanism so that if a service is down, just retry the check repeatedly until I get a response.

Tp check if the device is up, I use curl. I've read that curl has a retry mechanism but I've never used it.

Have any of you solved this problem before? I want to understand the things I must consider when solving it, e.g. do I retry until i get a HTTP 200 from my service?

Anyone any suggestions how I'd test this? I'd need to find a service that was down.

EDIT: I see that -retry only reacts to transient errors 'Transient error means either: a timeout, an FTP 4xx response code or an HTTP 5xx response code'. My service can return a 404 therefore curl's retry is not my solution.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The following statement will retry 5 times or a maximum of 40 seconds with a connection timeout of 5 seconds, and no exponential backoff policy

curl --connect-timeout 5 
    --max-time 10 
    --retry 5 
    --retry-delay 0 
    --retry-max-time 40 
    'http://your_url'


--max-time 10     (how long each retry will wait)
--retry 5         (it will retry 5 times)
--retry-delay 0   (an exponential backoff algorithm)
--retry-max-time  (total time before it's considered failed)

Note that there is also a --retry-connrefused (since curl 7.52.0) that retries even when the connection is refused and --retry-all-errors (since curl 7.71.0) which "is the sledgehammer of retrying".


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...