|
| 1 | +from __future__ import annotations |
| 2 | + |
| 3 | +from datetime import datetime, timedelta |
| 4 | +from typing import Annotated |
| 5 | + |
| 6 | +from pydantic import BaseModel, ConfigDict, Field |
| 7 | + |
| 8 | +from crawlee import Request |
| 9 | +from crawlee._utils.docs import docs_group |
| 10 | + |
| 11 | + |
| 12 | +@docs_group('Data structures') |
| 13 | +class ProlongRequestLockResponse(BaseModel): |
| 14 | + """Response to prolong request lock calls.""" |
| 15 | + |
| 16 | + model_config = ConfigDict(populate_by_name=True) |
| 17 | + |
| 18 | + lock_expires_at: Annotated[datetime, Field(alias='lockExpiresAt')] |
| 19 | + |
| 20 | + |
| 21 | +@docs_group('Data structures') |
| 22 | +class RequestQueueHead(BaseModel): |
| 23 | + """Model for request queue head. |
| 24 | +
|
| 25 | + Represents a collection of requests retrieved from the beginning of a queue, |
| 26 | + including metadata about the queue's state and lock information for the requests. |
| 27 | + """ |
| 28 | + |
| 29 | + model_config = ConfigDict(populate_by_name=True) |
| 30 | + |
| 31 | + limit: Annotated[int | None, Field(alias='limit', default=None)] |
| 32 | + """The maximum number of requests that were requested from the queue.""" |
| 33 | + |
| 34 | + had_multiple_clients: Annotated[bool, Field(alias='hadMultipleClients', default=False)] |
| 35 | + """Indicates whether the queue has been accessed by multiple clients (consumers).""" |
| 36 | + |
| 37 | + queue_modified_at: Annotated[datetime, Field(alias='queueModifiedAt')] |
| 38 | + """The timestamp when the queue was last modified.""" |
| 39 | + |
| 40 | + lock_time: Annotated[timedelta | None, Field(alias='lockSecs', default=None)] |
| 41 | + """The duration for which the returned requests are locked and cannot be processed by other clients.""" |
| 42 | + |
| 43 | + queue_has_locked_requests: Annotated[bool | None, Field(alias='queueHasLockedRequests', default=False)] |
| 44 | + """Indicates whether the queue contains any locked requests.""" |
| 45 | + |
| 46 | + items: Annotated[list[Request], Field(alias='items', default_factory=list[Request])] |
| 47 | + """The list of request objects retrieved from the beginning of the queue.""" |
| 48 | + |
| 49 | + |
| 50 | +class KeyValueStoreKeyInfo(BaseModel): |
| 51 | + """Model for a key-value store key info.""" |
| 52 | + |
| 53 | + model_config = ConfigDict(populate_by_name=True) |
| 54 | + |
| 55 | + key: Annotated[str, Field(alias='key')] |
| 56 | + size: Annotated[int, Field(alias='size')] |
| 57 | + |
| 58 | + |
| 59 | +class KeyValueStoreListKeysPage(BaseModel): |
| 60 | + """Model for listing keys in the key-value store.""" |
| 61 | + |
| 62 | + model_config = ConfigDict(populate_by_name=True) |
| 63 | + |
| 64 | + count: Annotated[int, Field(alias='count')] |
| 65 | + limit: Annotated[int, Field(alias='limit')] |
| 66 | + is_truncated: Annotated[bool, Field(alias='isTruncated')] |
| 67 | + items: Annotated[list[KeyValueStoreKeyInfo], Field(alias='items', default_factory=list)] |
| 68 | + exclusive_start_key: Annotated[str | None, Field(alias='exclusiveStartKey', default=None)] |
| 69 | + next_exclusive_start_key: Annotated[str | None, Field(alias='nextExclusiveStartKey', default=None)] |
| 70 | + |
| 71 | + |
| 72 | +class CachedRequest(BaseModel): |
| 73 | + """Pydantic model for cached request information.""" |
| 74 | + |
| 75 | + id: str |
| 76 | + """The ID of the request.""" |
| 77 | + |
| 78 | + was_already_handled: bool |
| 79 | + """Whether the request was already handled.""" |
| 80 | + |
| 81 | + hydrated: Request | None = None |
| 82 | + """The hydrated request object (the original one).""" |
| 83 | + |
| 84 | + lock_expires_at: datetime | None = None |
| 85 | + """The expiration time of the lock on the request.""" |
| 86 | + |
| 87 | + forefront: bool = False |
| 88 | + """Whether the request was added to the forefront of the queue.""" |
0 commit comments