|
| 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 CachedRequest(BaseModel): |
| 51 | + """Pydantic model for cached request information.""" |
| 52 | + |
| 53 | + id: str |
| 54 | + """The ID of the request.""" |
| 55 | + |
| 56 | + was_already_handled: bool |
| 57 | + """Whether the request was already handled.""" |
| 58 | + |
| 59 | + hydrated: Request | None = None |
| 60 | + """The hydrated request object (the original one).""" |
| 61 | + |
| 62 | + lock_expires_at: datetime | None = None |
| 63 | + """The expiration time of the lock on the request.""" |
| 64 | + |
| 65 | + forefront: bool = False |
| 66 | + """Whether the request was added to the forefront of the queue.""" |
0 commit comments