(args, label, options = {})
| 764 | } |
| 765 | |
| 766 | async function retrySimdeckJson(args, label, options = {}) { |
| 767 | const attempts = options.attempts ?? 6; |
| 768 | const delayMs = options.delayMs ?? 2_000; |
| 769 | const healthTimeoutMs = options.healthTimeoutMs ?? 60_000; |
| 770 | let lastError; |
| 771 | for (let attempt = 1; attempt <= attempts; attempt += 1) { |
| 772 | try { |
| 773 | return simdeckJson(args, options); |
| 774 | } catch (error) { |
| 775 | lastError = error; |
| 776 | if (attempt === attempts) { |
| 777 | break; |
| 778 | } |
| 779 | if (isServiceConnectionError(error)) { |
| 780 | logStep( |
| 781 | `${label} lost service connection on attempt ${attempt}; waiting for health before retry`, |
| 782 | ); |
| 783 | try { |
| 784 | await waitForHealth({ timeoutMs: healthTimeoutMs }); |
| 785 | } catch (healthError) { |
| 786 | lastError = healthError; |
| 787 | } |
| 788 | } |
| 789 | await sleep(delayMs); |
| 790 | } |
| 791 | } |
| 792 | throw new Error( |
| 793 | `${label} failed after ${attempts} attempts: ${lastError?.message ?? lastError}`, |
| 794 | ); |
| 795 | } |
| 796 | |
| 797 | async function retrySimdeckText(args, label, options = {}) { |
| 798 | const attempts = options.attempts ?? 6; |
no test coverage detected