Support for asynchronous function stack statements

Options

Hello,

Would it possible to provide an example of how to run statements in parallel through Lambda Promises?

For my usecase, I'm trying to respond an immediate 200 OK response to the Slack API (must be within 3 seconds) before continuing the rest of my function (that takes about 10 seconds).

Without the immediate 200 OK response, I receive an error from Slack - and app is potentially banded after too many errors.

There was a comment in the roadmap mentioning this was possible, as well as a previous post called: "Async execution: send endpoint reply immediately after receiving webhook and execute the rest"

https://xano.nolt.io/46

Tagged:

Answers

  • Ray Deck
    Ray Deck Trusted Xano Expert ✭✭✭
    edited March 2023
    Options

    Two main ways to do this in Xano:
    1) Have your endpoint call another endpoint with a timeout of 1sandled and the payload of work you want h. This will not wait for the second endpoint, which can do the slow work, and the first endpoint can just return.
    2) Save the data from Slack to a table and have a background task running frequently (e.g. every minute or faster) pick up new records from that table to process asynchronously.

    We've worked on both these patterns in our daily office hours and forum on State Change Pro (https://statechange.ai), where we focus on the hardest 5% of low-code projects.

  • WMcCartney
    WMcCartney Member
    Options

    Thanks @Ray Deck.

    For #1 - I implemented a simple GET request to another Xano endpoint and set the timeout to 1 second. Unfortunately, I am still running into the same "operation_timeout" error in Slack that results when an acknowledgemnt is not received in <3 seconds. The endpoint needs to return an "empty HTTP 200 response", but I am not sure how to do that in Xano.

    For #2 - I built a solution that works based on your recommendation. However, it looks like the highest run frequency is "Every Minute" - is it possible to set this to a shorter frequency? Say "Every 10 seconds"?

    Thanks again for your help.

  • Ray Deck
    Ray Deck Trusted Xano Expert ✭✭✭
    Options
    1. To get the blank result, set the response (the #3 section in the function stack) to blank - no variable or text listed at all. After making that change, it will show in the response section as "NA" , and the response from the server is nothing. The 200 code is always delivered in a non-error situation, so no need for special handling there.
    2. Check the request history to see how long Xano is taking to respond. These approaches should be keeping it to maybe 1.5 seconds or less. You might also see slack spamming your endpoint - in a launch plan, this can drive queuing and effective response time. A higher plan will handle more simultaneous responses.
    3. Yes, you can run background tasks more frequently with a scale plan - like every few seconds.

  • WMcCartney
    WMcCartney Member
    Options

    Thanks @Ray Deck

    1. & 2. It looks like the #3 API request should have plenty of time to return the 200 code prior to the 3 second deadline. Not sure why I continue to receive the "operation timeout" error.

    3. Got it - good to know, thank you!

  • Ray Deck
    Ray Deck Trusted Xano Expert ✭✭✭
    Options

    maccording to the function stack it does a lot more than the 4 steps listed in your screenshot. Is there more to scroll to? Are we looking at the published version? It seems step 5 is the long one.

  • WMcCartney
    WMcCartney Member
    Options

    @Ray Deck Yes, the function includes 12 steps. Here is full snapshot. I'd like to be able to acknowledge the Slack slash request (with three seconds - step #3), then continue the function steps #4 - #12 and push output to Slack.

  • Ray Deck
    Ray Deck Trusted Xano Expert ✭✭✭
    Options

    In order for it to "kick" you need to trigger the other endpoint and then stop. The other endpoint then has the job of doing the slow bits. So its receive the data, invoke the other endpoint (without waiting for it to finish) and then immediately return. Basicaly the second endpoint has the job of doing all the rest of the steps.

  • WMcCartney
    WMcCartney Member
    Options

    @Ray Deck Thanks a lot for this help. After reviewing your comments I was able to build the functionality with the 2nd endpoint and it works great! Thanks!

  • endrefyl
    endrefyl Member
    Options

    @Ray Deck Hi! In the endpoint that schedules the «heavy work endpoint», is the lowest respons time 1 second? So if I want my entire process (for the end user invoking the orginal endpoint) to be reduced by one second, I should go for a background task?

  • Ray Deck
    Ray Deck Trusted Xano Expert ✭✭✭
    Options

    Xano now has a feature called "post process" where you can more directly and simply "kick" the second part of the functionality to run after the API returns. Keeps you from having to wait that extra second.

  • endrefyl
    endrefyl Member
    Options

    @Ray Deck excellent! Thank you!