Run function after api endpoint is run
Options
Kevin Wasie
Member ✭
A user creates a new record through an api endpoint.
Then, a lot of processing needs to take place.
Right now, I have all of the processing in the endpoint so the user has to wait on the front end for the end point to complete.
But, there is a lot of processing that is irrelevant to the front end user.
Is there a way to return a response to the user, and then continue processing code?
Ive thought about a chron job to take over and check every minute for unprocessed records, but would prefer to find a way to just have code continue either by transferring to a function or something else.
Then, a lot of processing needs to take place.
Right now, I have all of the processing in the endpoint so the user has to wait on the front end for the end point to complete.
But, there is a lot of processing that is irrelevant to the front end user.
Is there a way to return a response to the user, and then continue processing code?
Ive thought about a chron job to take over and check every minute for unprocessed records, but would prefer to find a way to just have code continue either by transferring to a function or something else.
Comments
-
This question comes up a lot. The solution I see most often: kick off a second endpoint using External API function - with a short timeout. Your first endpoint will wait briefly then move on, while the second endpoint happily munches on your data without holding up the show.
-
That's exactly what I needed. Thanks,
-
The best way I see of doing this is with tasks. It does everything it needs to deliver to the front end on the endpoint and then throws information into Redis that then continues to be executed by a background task. I use this logic a lot and it works perfectly.
-
this is similar to what I was trying to explain today
-
it would be great if we could run the function stack just after returning a value.
-
I am using lambda to hit an endpoint instead of an API call with a timeout, but it's the same idea. Just don't need to wait a second, which is a minimum.
Example:
“axios({ method: 'post', url: 'https://....xano.io/api:..../process', data: { api_key: '...', data: $var.myvar1 }});
return "OK";” -
@Radik What is the recommended timeout interval for this?
-
@Kevin Wasie did you mean to tag me in on that? I set the timeout as low as Xano will permit - 1s.
Categories
- All Categories
- 53 ? Announcements
- 47 ? Releases
- 37 ? Welcome
- 983 ? Help! I'm a Noob
- 125 ? No-Code Front-Ends
- 633 ? Working with APIs
- 439 ? Transforming data
- 126 ? Connect Xano to ...
- 50 ?? Find an Expert
- 348 ❓Other questions
- 35 ? Security
- 22 ✂️ Snippets
- 19 ? Showcase
- 7 ?️ Xano Chatter
- 62 ? Video Tutorials
- 171 ? Request a feature
- 229 ? Report a Bug
- 19 ? Templates & Extensions
- 7 ? Feedback