Hello guys, I have a question. I make an API call and need to store each returned item in my database. It turns out that there is no specific number of items that will be returned, it could be dozens, it could be hundreds.
I will need to run this periodically, what approach would I need to take to avoid a possible infinite loop here, as I will never know the exact number of entries returned, but will always need to store them all?
If I made an api call that returned a list of stuff, I’d pass the list of returned stuffs lists of fields as lists of primitive types thru a recursive backend workflow
Regarding your answer @jared.gibb , then I wouldn’t need to define a maximum limit of items on which the workflow would be executed, I could just let it run over the entire list and when there were no more items it would stop execution, correct?
Yes you can always add a count parameter and increment the number every time the API call runs and add a conditional to run the API call only when count < max_value.
Sidepoint: Does the API response tell you there are no more items to retrieve? If so you can use that response to stop the recursive workflow…
I love everyone’s recommendations of max value, would work really well.
Personally I tend to opt for a time based option. Where the start time is passed and it can only run if time+10min < current time. Or something of that nature.
Both options are equally as good in my opinion and tend to have their place of being used.
If you know the count of items coming inbound you’d definitely use max option as you’ll incur less loops if it goes infinite.
If you don’t know max items inbound time based is preferred so you don’t cut yourself short by only getting part of the list.
One of my favorites is to add a date parameter that gets set when the workflow is triggered. Then, every time the workflow reschedules itself, have it check to make sure that “current date/time” is less than “date + x minutes” as a condition. So if the workflow is running longer than X minutes, it will stop rescheduling.
I would like this to be done twice a day, the time doesn’t matter. I’ll just get the data and save it to the DB. But I think I’m a bit lost between some options , I don’t know which one would be recommended in this case that could occur automatically.
Create a new recurring event as a Backend WF and set this recurring event in the Backend WF or Common WF actions.
Schedule API WF on a list in the Backend WF actions or Common WF actions.
But then how can I schedule something every 12 hours or something like that.
Generally speaking they are similar with a recurring event easier to turn on and off thru an admin (while turning off a API WF would require its ID (so you’d have to store that) unless done in the logs). However for your purposes, the API WF is clearly the way to go as you want it to run 2x a day and recurring events can only be triggered daily, weekly, etc (and creating 2 recurring events would be a hassle to maintain).