Waits for the given file to be processed, default timeout is 30 mins.
(
self,
id: str,
*,
poll_interval: float = 5.0,
max_wait_seconds: float = 30 * 60,
)
| 718 | ) |
| 719 | |
| 720 | async def wait_for_processing( |
| 721 | self, |
| 722 | id: str, |
| 723 | *, |
| 724 | poll_interval: float = 5.0, |
| 725 | max_wait_seconds: float = 30 * 60, |
| 726 | ) -> FileObject: |
| 727 | """Waits for the given file to be processed, default timeout is 30 mins.""" |
| 728 | TERMINAL_STATES = {"processed", "error", "deleted"} |
| 729 | |
| 730 | start = time.time() |
| 731 | file = await self.retrieve(id) |
| 732 | while file.status not in TERMINAL_STATES: |
| 733 | await self._sleep(poll_interval) |
| 734 | |
| 735 | file = await self.retrieve(id) |
| 736 | if time.time() - start > max_wait_seconds: |
| 737 | raise RuntimeError( |
| 738 | f"Giving up on waiting for file {id} to finish processing after {max_wait_seconds} seconds." |
| 739 | ) |
| 740 | |
| 741 | return file |
| 742 | |
| 743 | |
| 744 | class FilesWithRawResponse: |