|
7 | 7 | import time |
8 | 8 | from collections.abc import AsyncIterator, Iterator |
9 | 9 | from dataclasses import dataclass |
10 | | -from typing import TYPE_CHECKING, Any, Protocol, TypeVar, cast, overload |
| 10 | +from typing import TYPE_CHECKING, Any, Literal, Protocol, TypeVar, cast, overload |
11 | 11 |
|
12 | 12 | import pytest |
13 | 13 |
|
@@ -229,11 +229,26 @@ async def drain() -> list[_HasIdT]: |
229 | 229 | return collected |
230 | 230 |
|
231 | 231 |
|
| 232 | +ConflictErrorType = Literal[ |
| 233 | + 'actor-name-not-unique', |
| 234 | + 'actor-task-name-not-unique', |
| 235 | + 'schedule-name-not-unique', |
| 236 | + 'version-already-exists', |
| 237 | + 'env-var-already-exists', |
| 238 | +] |
| 239 | +"""API error types signalling that a create request lost the resource's unique name or version number. |
| 240 | +
|
| 241 | +Kept a closed set rather than a plain `str` so a typo in a call below fails the type check instead of silently |
| 242 | +disabling the recovery it was meant to enable. The values and their status codes come from the API itself - the |
| 243 | +`*-not-unique` ones are 409, `version-already-exists` and `env-var-already-exists` are 403. |
| 244 | +""" |
| 245 | + |
| 246 | + |
232 | 247 | async def _create_with_conflict_recovery( |
233 | 248 | create: Callable[[], Awaitable[T] | T], |
234 | 249 | recover: Callable[[], Awaitable[T | None] | T | None], |
235 | 250 | *, |
236 | | - error_type: str, |
| 251 | + error_type: ConflictErrorType, |
237 | 252 | description: str, |
238 | 253 | ) -> T: |
239 | 254 | """Run `create`, recovering the resource if an already-committed retry made its name unavailable. |
|
0 commit comments