Polling

When sending requests with the Fetch capability, the timeout duration is 3 seconds. This is enough time to complete most types of requests, but some apps may need to exceed this duration.

To handle long-running tasks, we recommend using polling. This isn't a specific feature of the Fetch capability, but rather a technique that can be implemented with the Fetch capability.

How polling works

This is a high-level overview of how polling works:

  1. Your app sends a request to its backend. This request includes a request token, which is an ID that uniquely identifies the task to be undertaken (e.g. the processing of a specific image).
  2. The backend starts asynchronously processing the request (e.g. in a background job) and immediately responds to the request with the request token that it received.
  3. Every X seconds, the app sends another request to the backend with the same token.
  4. The backend uses the request token to check if the long running-task is complete.
    1. If the task is not complete:
      1. The backend once again responds with the request token.
      2. The process repeats, with the app sending another request.
    2. If the task is complete:
      1. The backend responds with the result of the background job.
      2. The app doesn't send any further requests.

The end result is that no individual request exceeds the timeout duration, even though the combined duration of requests does.

Using a proxy

If it's difficult or impossible to modify the backend that an app interacts with, such as when integrating with a third-party service that you don't control, set up a proxy server that sits between Canva and that service. This can be a lightweight backend that only forwards and schedules requests — that is, a proxy.