21 lines
493 B
Python
21 lines
493 B
Python
import sys
|
|
import time
|
|
import typing
|
|
|
|
from loop_claude.outcome import Failure, Stop
|
|
|
|
T = typing.TypeVar("T")
|
|
|
|
|
|
def retried(who, attempt: typing.Callable[[], T | Failure]) -> T | Stop:
|
|
failures = 0
|
|
while True:
|
|
failures += 1
|
|
result = attempt()
|
|
if not isinstance(result, Failure):
|
|
return result
|
|
if failures == 3:
|
|
return Stop(1, f"the {who} failed three times running: {result.reason}")
|
|
print(f"retrying the {who} in a minute: {result.reason}", file=sys.stderr)
|
|
time.sleep(60)
|