I am building an application similar to uber so I want to have timeout callbacks, Where when a new request comes in I want to keep track of the order and cancel the order after certain time if no drivers accepts the order. I have planned to use setTimeout in nodejs for now, Is there any better way to do this ?
CodePudding user response:
So I assume the proper solution would be:
- accept the request.
- store it inside the DB with the status
pending
. - return the response to the client.
- in another process or worker search for the requests inside the DB and dispatch them to the drivers, if any driver accepts that request, change the status
accepted
. - in the meanwhile, you need to have another endpoint to return job status and etc, client use this for checking for job status for let's say 1 minute, and pulls the result every 2 seconds.
- Inside the worker just update the request to status
canceled
if they passed the threshold.