Async execution: send endpoint reply immediately after receiving webhook and execute the rest in the

Options
I want to send back the 200 status to the endpoint directly (in the current set up Xano would wait for each function called in the external API call to be executed.
-Is there of sending success at the chosen moment?
-Is there a way of simply telling Xano to execute as per order but do not wait for the external API replies? [Screen Shot 2022-03-01 at 2.06.20 PM.png]

Comments

  • Sean Montgomery
    Sean Montgomery Administrator

    ADMIN

    Options
    This isn't currently possible but it is on the roadmap.

    You can vote for it here.

    https://xano.nolt.io/46
  • Ray Deck
    Ray Deck Trusted Xano Expert ✭✭✭
    Options
    I think  could do this by bringing zapier to the party. You have end point A trigger a webhook zap via external API call, which returns immediately because they are async by design. Then the zap calls endpoint B to continue the work.

     as a potential all-Xano alternative, could endpoint A call endpoint B via "external API call" with a timeout of 0? Then endpoint A would return immediately and B could continue on its merry way and happily ignored by the other parties?
  • Sean Montgomery
    Sean Montgomery Administrator

    ADMIN

    Options
    That is creative and might actually work. Things can get grey with severed network connections. Sometimes the request continues. Sometimes it stops.

    Still worth a try if it is really important. We do want async support as it will allow for more things in parallel but we just aren't there yet.
  • Luck Kanthatham-2308338
    Options
    I'm not sure if you can use scheduled tasks and a table that mimics a queue to achieve a similar effect.

    I had an issue of creating shipping labels for the boxes needed in an order. For example, if an order comes in that requires 50 boxes, then it needs to make an external API call to the label-creating service 50 times.  It just takes a long time to do this all in one synchronous call.

    I resorted to having two scheduled tasks to do this:  one to push a box record for each box that needs a label into a queue table, then another task to look at the queue and see which ones need a label.

    The logic works like this:
    • call to the create order API endpoint with the number of boxes needed.  Let's say 50.  It records in the order table that this order needs 50 boxes and flags that this record needs to be processed.  The call returns right away
    • the first scheduled task looks at new orders that need labels created, it sees that there's one order that needs 50 boxes.  It then creates 50 records in the queue table and marks the record in the order table that the order has been processed.
    • the second scheduled task then looks at the items in the queue and processes them 10 items each time it "wakes up".  Each time it processes a record, it pulls the record out of the queue.  For 50 boxes, it has to process 5 times (10 each).

    I used to do something similar using AWS SQS but there's code involved.  Now that there's Xano, I'm not going back!
  • Charles Bonnevialle
    Options
    Hey Lukasz, I know it's very late, but you can achieve this with the new Lambda function. However, instead of sending a 200 status, you can call your own API from another xano API through Lambda with the following code:

    axios({
      method: 'post',
      url: 'https://xzum-osbu-jgwt.b2.xano.io/api:k8TOml/MyAPI',
      data: {
        firstName: 'Fred',
        lastName: 'Flintstone'
      }
    });

    return "ok!";
  • Valentin R
    Valentin R Member
    Options
     how would this be different from a function that contains an API call to xano's endpoint, but with a short timeout? Just wondering
  • Charles Bonnevialle
    Options
     Sorry for the delay. When the function times out it returns an error. Apart from that I think it's pretty much the same, only that my method doesn't return an error.
  • Valentin R
    Valentin R Member
    Options
     thanks, using your method already where I can.
  • Frank Wieffering
    Options

    Hi,

    Thanks for sharing this option. This gives our application a lot of opportunities. But I have a beginner question about javascript.

    I want to use a variable instead of

    '  firstName: 'Fred', lastName: 'Flintstone'

    But how can I use a variable in data. Because underneath example doesn't work. (Because of my knowledge of javascript ;)

     data: {

    $var.var_from_xano

     }

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

    I don't know exactly what you want to send in the data, but if your data is the payload, you can just remove the curly braces ( {} ) and give that a try. If its not a quick solution, please post a screenshot!