Error 504 running a long duration python code block in a workflow

I am experimenting running some of our python scripts inside workflow code blocks.

The one script updates 400+ rows in a table on via their REST API (that is rate limited) so we have a 1 second delay per row - resulting in an execution time of over 400 seconds.

If I run this code with a smaller table, the script executes fine.
But on the full 400+ rows I get an 'Internal Error running a block : Error : 504' - this is with the code block timeout to 600000ms to try and allow for the long execution time.

If I set a shorter timeout I get 'Timeout Error: The block run exceeded the timeout of 30000ms'.

Any ideas?

The errors you're encountering seem to be related to the execution time and potential timeout of the code blocks in your workflow when processing a large number of rows. Here are some suggestions to address the issue:

  1. Batch Processing: Instead of processing each row one by one with a 1-second delay, consider batching your API requests. This way, you can send multiple requests in a single call, reducing the overall execution time. However, you still need to ensure that you stay within the rate limits of the API.

  2. Optimize API Calls: Check if there are any optimizations you can make in your API calls. Sometimes, APIs provide bulk update endpoints that allow you to update multiple rows in a single request. This could significantly reduce the number of requests you need to make.

  3. Paginate and Resume: If the API supports pagination, you could retrieve and update a smaller number of rows per API call. This can help manage the load and avoid timeouts. If you encounter a timeout, you can resume from where you left off instead of starting over.

  4. Error Handling: Ensure that your script handles errors gracefully. For example, if you encounter a timeout or rate limit error, your script could wait and retry the request after a certain period of time.

  5. Distributed Processing: If possible, consider breaking down the task into smaller units and distributing them across multiple code blocks or workers. This could be done using a queue system or task scheduler. Each worker would process a portion of the rows, and this could help avoid timeouts.

  6. Monitor Resource Usage: Check if there are any resource limitations on the platform where you're running the code blocks. If you're hitting memory or processing limits, it could lead to errors. You might need to optimize your code to be more memory-efficient.

7 . Logging and Debugging: Implement comprehensive logging and debugging in your code. This can help you pinpoint the exact location where the error occurs and gather more information about what might be causing it.

1 Like

Thanks for the suggestions.

Yes, this is a Retool timeout.
If I run the script elsewhere, it completes.

I suspect there is a hard limit somewhere, which cannot be overridden (to a point) by the timeout setting in the Retool code block.

Hey @BrettL! Do you have insight, perhaps from the side, into when the requests fail? I'm also wondering if you've tried using a loop block and run into similar issues. If you wouldn't mind sharing the code you're using that could also be helpful.

As a side note: Curious to know what the rate limits for the REST API are in case batching your requests might allow you to make more concurrent requests and cut down the query time in general.