|
1 | 1 | from __future__ import annotations |
2 | 2 |
|
| 3 | +from datetime import datetime |
3 | 4 | from logging import getLogger |
4 | 5 | from typing import TYPE_CHECKING, Final, Literal |
5 | 6 |
|
|
15 | 16 | if TYPE_CHECKING: |
16 | 17 | from collections.abc import Sequence |
17 | 18 |
|
18 | | - from apify_client.clients import RequestQueueClientAsync |
| 19 | + from apify_client._resource_clients import RequestQueueClientAsync |
19 | 20 | from crawlee import Request |
20 | 21 | from crawlee.storage_clients.models import AddRequestsResponse, ProcessedRequest, RequestQueueMetadata |
21 | 22 |
|
@@ -82,21 +83,26 @@ async def get_metadata(self) -> ApifyRequestQueueMetadata: |
82 | 83 | if response is None: |
83 | 84 | raise ValueError('Failed to fetch request queue metadata from the API.') |
84 | 85 |
|
| 86 | + total_request_count = int(response.total_request_count) |
| 87 | + handled_request_count = int(response.handled_request_count) |
| 88 | + pending_request_count = int(response.pending_request_count) |
| 89 | + created_at = datetime.fromisoformat(response.created_at) |
| 90 | + modified_at = datetime.fromisoformat(response.modified_at) |
| 91 | + accessed_at = datetime.fromisoformat(response.accessed_at) |
| 92 | + |
85 | 93 | # Enhance API response with local estimations to account for propagation delays (API data can be delayed |
86 | 94 | # by a few seconds, while local estimates are immediately accurate). |
87 | 95 | return ApifyRequestQueueMetadata( |
88 | | - id=response['id'], |
89 | | - name=response['name'], |
90 | | - total_request_count=max(response['totalRequestCount'], self._implementation.metadata.total_request_count), |
91 | | - handled_request_count=max( |
92 | | - response['handledRequestCount'], self._implementation.metadata.handled_request_count |
93 | | - ), |
94 | | - pending_request_count=response['pendingRequestCount'], |
95 | | - created_at=min(response['createdAt'], self._implementation.metadata.created_at), |
96 | | - modified_at=max(response['modifiedAt'], self._implementation.metadata.modified_at), |
97 | | - accessed_at=max(response['accessedAt'], self._implementation.metadata.accessed_at), |
98 | | - had_multiple_clients=response['hadMultipleClients'] or self._implementation.metadata.had_multiple_clients, |
99 | | - stats=RequestQueueStats.model_validate(response['stats'], by_alias=True), |
| 96 | + id=response.id, |
| 97 | + name=response.name, |
| 98 | + total_request_count=max(total_request_count, self._implementation.metadata.total_request_count), |
| 99 | + handled_request_count=max(handled_request_count, self._implementation.metadata.handled_request_count), |
| 100 | + pending_request_count=pending_request_count, |
| 101 | + created_at=min(created_at, self._implementation.metadata.created_at), |
| 102 | + modified_at=max(modified_at, self._implementation.metadata.modified_at), |
| 103 | + accessed_at=max(accessed_at, self._implementation.metadata.accessed_at), |
| 104 | + had_multiple_clients=response.had_multiple_clients or self._implementation.metadata.had_multiple_clients, |
| 105 | + stats=RequestQueueStats.model_validate(response.stats, by_alias=True), # ty: ignore[possibly-missing-attribute] |
100 | 106 | ) |
101 | 107 |
|
102 | 108 | @classmethod |
|
0 commit comments