0

I have a REST api that launch a heavy calculation on the serveur (it tikes a few seconds). For that I'm returning 202 (ACCEPTED) http code to the client, which will not expect a returning value. Ok so far.

What will I return for another client how calls this url while the process (launched by the first call) is not terminated ?

This second call will not be processed, it will be ignored and the client must try again later.

2
  • Will the second call be processed later, or are you immediately discarding it? Commented Mar 23, 2020 at 10:55
  • No it will be ignored, the client must retry again. I added this information in the question Commented Mar 23, 2020 at 10:57

1 Answer 1

2

If you insist on the current behavior, then you'll return 503. This tells the (standard compliant) client that your server is temporarily overloaded, and it can retry later (you can even hint when it can on Retry-After header. While standard-compliant, you'll only want to do this if queuing the process requested by the second call later is impossible, perhaps because the internal state will have changed so the second call is invalid. If it's possible to just queue the process with an identical result as when the client manually retry the call, then just return 202.

Sign up to request clarification or add additional context in comments.

2 Comments

what about 423 & 444 ? they can't be used here ?
423 might be applicable if during the calculation, your server need to lock certain rows or files, and allowing the second call will gives invalid result. 444 isn't even supposed to be returned, it's nginx internal extension to tell to just close and shut up (no response at all) because the client is either broken or malicious. So if your app run behind nginx, if it return 444, nginx won't return anything and the client obviously won't even see the 444. It's merely put in nginx log.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.