#Retry in Python SDK?
1 messages · Page 1 of 1 (latest)
Hi @muted nova ! Ideally you would simply check the result of the build step, and handle it as you wish (retry etc) before continuing. But it's possible that you're running into the "surprising laziness" problem, where some steps return "success" when they haven't yet been executed at all. So, if I'm right, then you need to either 1) wait for a future version of the Dagger API to make laziness less confusing - this is a short-term item as many people are asking about it, or 2) implement a workaround, for example add a simple with_exec().exit_code after the build, to force the build to run (to get the exit code you need to exec; to exec you need to build).
Copying @glad yarrow who is leading on this topic.
For reference: https://github.com/dagger/dagger/issues/4668
I depends. Not every failure benefits from retrying. A failed test will probably remain broken on retry, unless it's due to a network issue or something like that. So you need to apply the retry logic where it makes sense for your use case.
Because of Container { exitCode } doesn't work if the command fails, remember that you need to capture the error since exit_code will either return 0 on success or raise an exception otherwise.
And the existence of exit code: in the error message can mean different things:
async def exec(ctr: dagger.Container):
try:
await ctr.exit_code()
except dagger.QueryError as e:
if "exit code:" in str(e):
# command executed but failed
raise
# command not executed (e.g., not configured)
raise