Loop to check web URL every 5 minutes until desired outcome is achieved?


#1

Been using a successful piston for a while now to grab Octopus Agile API results - however the last two days they’ve been late releasing the data, so my timer which runs at 5pm didn’t work as the data wasn’t out by then.

I decided to run a check and if the data wasn’t available, keep checking every 5 minutes until it is. I thought a loop would be correct for this but when i put the “wait in” it seems to run the entire piston again from the start instead of just the loop - so is there a correct way to do this?

So to explain the piston - for the purposes of testing i’ve just used 1 minute pause but to save hits on the server i’d probably set this to 10 minutes.

So the piston runs at a set time - first it checks the URL and sets the result in a variable.

Next we check the variable, if it’s higher than 15 it means the API hasn’t updated, so I want to enter the loop to keep checking until the result is lower than 15 and it can run the rest of the commands in the piston.

At the moment if it’s lower than 15 at the start, it works with no problem, however when it enters the loop it seems to run the loop and I assume it’s getting to wait bit each time and getting stuck there. If I put wait at the end how would i exit the loop at all once the desire outcome is reached? I assume there’s a proper way to do this and not just have it loops really fast as quickly as it can process?


#2

I went for a “while” loop instead in the end put the wait at the end - it still seems to run the entire piston from the start again but that still works as the first part will check the URL again anyway and if it’s not below 15 it ends up waiting in the loop and checking again. I’m thinking there’s no point in putting anything in the loop except wait for 10 minutes though so it’ll run the start of the piston again.


#3

Often when you use a wait, you need to set ‘never cancel tasks’ on the ‘with’ that includes the wait to avoid starting over.


#4

Gotcha, so that would have it cycle round the loop rather than the entire piston after the wait?


#5

It should. Let us know if it solves your problem.