How to best handle long-running methods

Hey all,

I have a long running server-side request to perform and when done I want to update the frontend page with the results. If I run this routine using a Wix web module, then it will timeout with the message “WebMethod request timed-out after 14 seconds”.

My timing indicates the request typically takes up to a minute to run - it’s a non-trivial operation and the time to run can’t really be shortened.

So I was wondering what approaches are available to handle this in the Wix code ecosystem?

  • Perhaps I could try reimplementing using wix-http-functions instead of a WebMethod - do they have the same timeout limitation? (I couldn’t find a mention of their timeout limits anywhere)

  • I could get an async notification from a websocket when the operation completes - can that be done in Wix? I found that the socket.io npm module is available to install in Wix code, but the following forum discussion suggests that it’s not usable for this: https://www.wix.com/code/home/forum/community-discussion/socket-io-npm-module

  • I could write an old fashioned polling loop that periodically hits the server looking for a result.

Any suggestions or code examples would be welcomed!
Matt

2 Likes

Update: I’ve just tested with a wix-http-function and that didn’t help. I inserted some sleep time into the handler and found that if my request processing time was too long (again around 14 seconds) then the client would see it hang for a long time (40+ seconds) and eventually hang up with no response.

Hi, Can we please have an official answer on this how to handle such situations? It is not only for the long-running operations, but also when a wix-http-functions is called from 3rd parties (ie. new data is coming from a server) I would like to forward that data to the UI to redraw real-time (maybe just send an event then the UI could get the data itself). So the question, how can we send an event to the UI to trigger this functionality?

2 Likes

There is a time limit of 14 secs and after that you will get the timeout notice.

As Genry has explained better in this old post here.
https://www.wix.com/corvid/forum/community-discussion/settimeout-in-backend-not-working

If you want more help with this issue, please post your question as a new post rather than jumping onto an old post from 2018.

CLOSED.