Subscribe to events and start collecting statistics. Raises: RuntimeError: If the context manager is already active.
(self)
| 156 | return self._active |
| 157 | |
| 158 | async def __aenter__(self) -> Self: |
| 159 | """Subscribe to events and start collecting statistics. |
| 160 | |
| 161 | Raises: |
| 162 | RuntimeError: If the context manager is already active. |
| 163 | """ |
| 164 | if self._active: |
| 165 | raise RuntimeError(f'The {self.__class__.__name__} is already active.') |
| 166 | |
| 167 | await self._state.initialize() |
| 168 | # Reset `crawler_finished_at` to indicate a new run in progress. |
| 169 | self.state.crawler_finished_at = None |
| 170 | |
| 171 | # Start periodic logging and let it print initial state before activation. |
| 172 | self._periodic_logger.start() |
| 173 | await asyncio.sleep(0.01) |
| 174 | self._active = True |
| 175 | |
| 176 | self.state.crawler_last_started_at = datetime.now(timezone.utc) |
| 177 | self.state.crawler_started_at = self.state.crawler_started_at or self.state.crawler_last_started_at |
| 178 | return self |
| 179 | |
| 180 | async def __aexit__( |
| 181 | self, |
nothing calls this directly
no test coverage detected