If the result is what I excepted, do something (success).
Else, wait 5 seconds and retry.
If it failed 3 times, do something (error).
Pseudo code
retry = 3
while retry > 0:
wait(5 seconds)
result = request("http://myurl.com")
if result.text == "OK":
do_something_on_success()
break
retry = retry - 1
if retry == 0:
do_something_on_error()
To do that, I create a variable retry in a Set, with the value 3.
After my request, if the result is not what I expected, I test the value of retry.
If it’s greater that 3, I update it to retry - 1 and loop on the request statement (with a pause before). If retry is 0, I consider it in “error” and I don’t try anymore.
My problem is that I don’t know how to update this value in another Set.
The variable is accessed by {{ $('Name of the block').item.json.retry }}. I would like to use a variable global to the whole workflow.
Workaround
I found a workaround transforming my loop into recursive calls of my workflow, but I don’t really like the readablility of it.
You can check runindex to see how often it has failed. So you do not have do do anything fancy to see how many retries there were.
In the second if just check if the runIndex is smaller than what you want it set to and you are done.
Sorry, didnt see that question.
You cannot use those variables in expressions only in code blocks.
I personally never use the workflow variables, as it only saves when the workflow saves. And it causes the workflow to save every time it runs, which I do not like.
I use Redis to store variables. But you can use what ever you like of course.
If you have a license and get the variable feature you can read variables in expressions, but don’t think you can set them in workflows yet.
As a developer, I find it very odd to not have the ability to update the value of a variable and use it in a condition.
For me, it seems to be a mandatory feature.
Maybe it’s because I’m new to N8N and I have to bend to the N8N’s philosophy…