I am experimenting running some of our python scripts inside workflow code blocks.
The one script updates 400+ rows in a table on Tadabase.io 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'.
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:
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.
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.
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.
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.
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.
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.
Hey @BrettL! Do you have insight, perhaps from the Tadabase.io 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.