How to stop a "DO While" after a certain time?

Good afternoon friends, a question please:

I am using “Do while” to continue with the next download from a website, it does the same as the “Wait for download” activity, but I prefer to do it with “Do While”, the problem occurs when after pressing the button to download, the web page can crash and leave me in an infinite loop, it has rarely happened to me but anyway it is a problem that I want to solve.

So when the page crashes I would like my “DO While” to have a timer and for example stop in 4 min.

It occurs to me to put a second “condition” in “do while”

(numberOfTxt=newNumberofTXT) or (…)

but I don’t know how I could set the timer.

1 Like

Hi @Lynx,

I would avoid loops or creating timers in this situation. I would suggest using a Trigger Scope activity with a File Change Trigger for the download, and then perhaps a Process End trigger to execute certain activities if the web browser crashes.

Kind Regards

1 Like

First time I read about these activities, I will look for info to implement and start testing. I tell you how it went. If you have an example, I would greatly appreciate it if you share it with me.

1 Like

Just set up a counter, set it to 0 before the Do While, then at the end of the Do While increment it. Include checking the value in the Do While condition. Add a 1 second delay and then you know letting the counter go to 5 means a 5 second attempt, letting it go to 10 means a 10 second attempt, etc.

2 Likes

I’ll give you some clues to aid your learning,

Here are the two Trigger types you will likely use.

Take notice in File Change Trigger parameter - ChangeType.
Process End Trigger - You’d put the process name (.exe) that closes unexpectedly here
These go in a Trigger Scope activity

The academy has a great tutorial on triggers (for background processes), start here in your learning
Link: https://academy.uipath.com/learningpath/attended-automation-features-in-studio
On the tutorial go to: Attended Automation Features in Studio → Background processes, triggers and process chaining → Triggers

It can get a bit complicated when having multiple trigger types and casting trigger arguments, if you get stuck, just give me a mention here or a PM, best for you to learn by yourself and if you get stuck we can give you further guidance and answers.

While postwick’s answer would work, I advise against using delays - they aren’t best practice and they unnecessarily slow down processes. Triggers are superior - instantaneous, idly waiting on an event.

Kind Regards

Edit:
@Lynx
Have you thought about simply using the activity parameter Timeout in the Wait for Download activity? That way the activity will throw an error if the timeout is reached. With that error, you could use a Retry Scope or a Try Catch, Finally to execute logic in case of timeout. The issue with this approach is that you won’t be able to distinguish if the file hasn’t downloaded due to the browser crashing or the download just being slow without further logic.

image

1 Like

Hi @Lynx,

You can use Element Exists and Retry Scope activities. And for the timer part this you generally need when web page crashes so you can put a delay there like each time of 1 minute and add a counter and then check the value of that counter as per your req. and exit the loop.

Thanks

1 Like

I’ve been testing this way “(numberOfTxt=newNumberofTXT) or (counter<4)”, but the condition after the “or” doesn’t work, it should break the loop but it doesn’t.

1 Like

Hi @Lynx,

Can’t you make the download through API using a HTTP Request activity? I think it would be the best approach.

If it is not possible and you want use this approach of wait an amount of time, you can do just like this:

image

If this solves your problem, kindly mark this post as solution to close this topic.

If you need extra help and/or have any question, please let me know :slight_smile:

Thanks!

Change it to AND

This timer (alone) works fine (it is set to 4 just as an example, I would put that in 120 seconds as a maximum limit). Thanks @postwick @gustavo.cervelin

But I need it to work with the rule I’ve been using:
(numberOfTxt=newNumberofTXT), this would allow me to optimize the time once it detects a new text file to continue the flow with the next download.

When I combine it like this: (numberOfTxt=newNumberofTXT) or (counter<4), it doesn’t work (Doesn’t stop after 4 seconds). What I expect is the following: If the first and the second are successful, stop the loop, I set the time to 4 just to test, but this is not true.

This timer (alone) works fine (it is set to 4 just as an example, I would put that in 120 seconds as a maximum limit).

But I need it to work with the rule I’ve been using:
(numberOfTxt=newNumberofTXT), this would allow me to optimize the time once it detects a new text file to continue the flow with the next download.

When I combine it like this: (numberOfTxt=newNumberofTXT) or (counter<4), it doesn’t work. What I expect is the following: If the first and the second are successful, stop the loop, I set the time to 4 just to test, but this is not true.

And I necessarily need those two rules the first to optimize times because it waits for the download to finish. And the second to prevent getting stuck in an infinite loop, if the website crashes (it has already happened to me)

I plan to use the “Is True” activity first to validate the logic part, but if you have any suggestions, those are welcome.

1 Like

As I said, change it to AND.

You only want it to continue if there is no new file AND the counter limit hasn’t been reached. With OR, as long as the first (numberOfTxt=newNumberofTXT) is true, the rest is irrelevant.

1 Like

You’re absolutely right, I’ve been getting confused. Thank you very much

1 Like

I get confused on those all the time. Especially with things like…

((NOT SomeValue = “test”) OR (SomeOther = “real”)) AND (NOT WowIamConfused)

:smiley:

The real fun part is when you start using Check True and Check False, it adds another layer to the “is false false true, or true false false, or false true false”?

1 Like

I was confused that a loop would exit when this was done (numberOfTxt=newNumberofTXT), so I put the “or” (counter<4). That is, if one of the two is affirmative (True “or” True ) then exit the loop.

But I had forgotten that the first statement (numberOfTxt=newNumberofTXT) was to stay in the loop. :sweat_smile:

1 Like

As an additional pointer, there is also a While - which is different from Do While.

Do While executes the activities inside it then checks the condition to see if it should do it again.

While checks the condition first and if the condition is false it does nothing, if the condition is true it executes the activities then checks the condition again, etc.

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.