Fail step only on last retry Retry logic on a step is now failing the earlier runs, and shows failure even if last retry succeeds. This CL mark those as ok_ret='any'. Change-Id: I1f72f6317a7ab73f76dd8476843c7b2b8a1ff164 Reviewed-on: https://flutter-review.googlesource.com/c/recipes/+/12720 Reviewed-by: Oliver Newman <olivernewman@google.com> Commit-Queue: Keyong Han <keyonghan@google.com>
diff --git a/recipe_modules/retry/api.py b/recipe_modules/retry/api.py index 7428954..7a071f5 100644 --- a/recipe_modules/retry/api.py +++ b/recipe_modules/retry/api.py
@@ -18,20 +18,24 @@ **kwargs ): """Retry the step with exponential backoff. - Args: - step_name (str): Name of the step. - cmd (None|List[int|string|Placeholder|Path]): The program - arguments to run. - max_attempts (int): How many times to try before giving up. - sleep (int or float): The initial time to sleep between attempts. - backoff_factor (int or float): The factor by which the sleep time - will be multiplied after each attempt. + Args: + step_name (str): Name of the step. + cmd (None|List[int|string|Placeholder|Path]): The program + arguments to run. + max_attempts (int): How many times to try before giving up. + sleep (int or float): The initial time to sleep between attempts. + backoff_factor (int or float): The factor by which the sleep time + will be multiplied after each attempt. + + Returns a `step_data.StepData` for the running step. """ for attempt in range(max_attempts): - try: - return self.m.step(step_name, cmd, **kwargs) - except self.m.step.StepFailure: + step = self.m.step(step_name, cmd, ok_ret='any', **kwargs) + if step.retcode != 0: if attempt == max_attempts - 1: - raise - self.m.time.sleep(sleep) - sleep *= backoff_factor + step.presentation.status = self.m.step.FAILURE + raise self.m.step.StepFailure('.'.join(step.name_tokens), step) + self.m.time.sleep(sleep) + sleep *= backoff_factor + else: + return step
diff --git a/recipe_modules/retry/examples/full.expected/pass_with_retries.json b/recipe_modules/retry/examples/full.expected/pass_with_retries.json index f0fbe56..0bc3a24 100644 --- a/recipe_modules/retry/examples/full.expected/pass_with_retries.json +++ b/recipe_modules/retry/examples/full.expected/pass_with_retries.json
@@ -4,10 +4,7 @@ "ls", "-la" ], - "name": "mytest", - "~followup_annotations": [ - "@@@STEP_FAILURE@@@" - ] + "name": "mytest" }, { "cmd": [