Calling a 'fire and forget' webhook from trpc without waiting

I would like to call a webhook from a trpc endpoint. Right now I simply call the webhooks without awaiting them so I can get on with returning the response immediately. The problem is that the serverless endpoint is killed as soon as the trpc endpoint returns so sometimes the webhook doesnt run. I want to send a response and THEN process the webhooks so the client isnt waiting. Is there a way to do that?
5 Replies
Tom
Tom•14mo ago
sad bump 😦
Keef
Keef•14mo ago
Lots of ways to do this but you are going to have to get something else involved. Generally with this kind of work I use a work queue and just create a new job since the goal is to avoid waiting in the scope of the request handler. Dispatching a lambda would work too.
Keef
Keef•14mo ago
This used to be recommended in here for a while but I'm not sure if its still the go to https://quirrel.dev/
Job Queueing for Serverless
Quirrel makes job queues simple as cake. Set up in 5 minutes - even works locally!
Keef
Keef•14mo ago
Message queues would also work in this situation if you ever worked w them Before i deleted half of what I wrote I pitched just firing a request to an endpoint that will handle the publishing is that what you are doing now?
Tom
Tom•14mo ago
I tried that. It actually didn’t work Seems that the separate function gets killed if vercel detects that the connection died Which is annoying For now I solved it by using a Google cloud function. My data is going to cloud Firestore anyway and they have a built in way of calling a function when the data gets updated It works but functions are wayyyy less ergonomic than anything vercel offers Tbh it’s remarkable how much they’ve simplified most things. It’s just the weird stuff where you run into problems like this
Want results from more Discord servers?
Add your server
More Posts