I have two APIs:
triggerAPIResult. When I hit the first one, it would trigger a process which could take a few minutes to return the response. The second API is used to check if the process is successfully finished or not.
Therefore, when the second API returns true, that means now the response from the first API is the desired output. The second API response is very important since when the first API is still processing, it would return meaningless data until actually finished. Another thing is that the
triggerAPIResult API should get triggered every
10 minutes to constantly check the result. How could you I implement this in Python?
The principle is quite simple.
triggerAPIand immediately return a unique operation ID.
is_donevalue tied to it which is set to
True. Store the result of the operation somewhere.
triggerAPIResultand have logic to check the state of the operation. Return the actual processed data when done, otherwise return something like
Note that the actual implementation can be a bit complicated depending on the tech used. I would go for microservices in this scenario to avoid having to use threads or async.