27
Views
4
Comments
Timer for many records, best practices in ODC
Application Type
Reactive

Tengo aproximadamente 16.000 registros que estoy recuperando de una API que tarda unos 15 segundos en obtener los datos. ¿Cómo puedo realizar un procesamiento por lotes?

La API utiliza POST y envía una fecha de inicio de hoy, 31 de septiembre, y una fecha de finalización de hoy, 31 de octubre.

El problema es que el temporizador tarda entre 60 y 90 minutos, y me gustaría saber cómo optimizarlo. Básicamente, mi flujo de trabajo consiste en llamar a la API, luego iterar sobre ella con un bucle `for` y una acción para crear o actualizar los registros.

Adjunto una captura de pantalla. Necesito optimizar el proceso y he visto que el procesamiento por lotes es una buena opción, pero no sé cómo implementarlo.


2024-05-01 02-52-20
Felipe Guerra

2025-12-22 13-50-43
Sherif El-Habibi
Champion

Hi @Felipe Guerra,

I see in your attached screenshot that you’re trying to insert records into your local database, which are retrieved from the API. You can add a small tweak to avoid timeouts within the loop itself.

First, create a local variable in the action let’s call it Timeout. Each time you create a record in the database, use the Commit Transaction server action to prevent data loss or inconsistency in case of a failure. You can flag successfully inserted records with an attribute like IsInserted.

Next, check if the duration has reached the timeout limit. If it has, wake up the timer again to continue processing the remaining records.

For example, suppose you initially set the timeout to 5 minutes. If the timer runs for 6 minutes, it stops there. You then add another 5 minutes to the Timeout value and wake up the timer again, repeating this process until all records are processed.

Condition:

CurrDateTime()>= Timeout

If True:

Set Timeout = AddMinutes(CurrDateTime(), 10)

Wake up the timer again

If False:

Continue processing the loop

Here is a screenshot which can help you understand better 

One additional tip: you used a separate action for creating records, which is good practice. However, I noticed you’re using an aggregate inside that action to retrieve the document by ID to determine whether it’s an update or a create. Doing this on every iteration can lead to performance degradation, since you’re retrieving the record each time you enter the action. Imagine having 1,000 records this would put unnecessary load on the backend and could easily become a bottleneck.

A better approach is to move that aggregate outside the action just before the loop in your main logic. Then, use the CreateOrUpdate method instead. It will automatically determine whether the record is new or existing, improving performance and simplifying your logic. You can flag it using the previously mentioned attribute IsInserted, without needing to return each record individually.



2024-05-01 02-52-20
Felipe Guerra

Todavía tengo una pregunta: ¿cómo uso CreateOrUpdate? Con la función de agregación, ¿a qué acción corresponde? ¿Y cómo identifico si está en la base de datos, para actualizar o crear?

2025-12-22 13-50-43
Sherif El-Habibi
Champion

How do I identify if it is in the database, to update or create?

  • You don’t need to identify it manually the action automatically detects it. For example, suppose you pass a record with Id = 5 and use CreateOrUpdate. What happens in the background is that when the Id is passed, it checks: “Does a record with Id = 5 already exist?” If yes, it won’t create another record; it will just update it. If not, it will create a new record.

How do I use CreateOrUpdate with the aggregation function?

  • Exactly how you did in the first screenshot you get the record by Id, but remove the separate update action and keep the condition in one flow. If the result is not empty, use CreateOrUpdate. If it’s empty, you can simply do nothing. If you prefer, you can replace CreateOrUpdate with Create only, but the outcome will still be the same. That’s why I mentioned that getting the record by Id in a separate action isn’t the best approach. For example, if this action takes the Id as an input parameter, uses an aggregate to filter by it, and then applies a condition to check whether it’s empty or not, you can directly use the CreateOrUpdate action right away without needing an additional server call and it will do the rest. 

Which action does it correspond to?

  • It basically corresponds to both Create and Update in one action. It depends on the input record’s identifier: If the Id is null, it will create a new record. If the Id is not null, it will update the existing one.
Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.