Skip to content

Commit d27c080

Browse files
committed
Move specific models from Crawlee to SDK
1 parent c01af44 commit d27c080

File tree

2 files changed

+69
-8
lines changed

2 files changed

+69
-8
lines changed
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
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."""

src/apify/apify_storage_client/_request_queue_client.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,9 @@
1313
from crawlee import Request
1414
from crawlee._utils.requests import unique_key_to_request_id
1515
from crawlee.storage_clients._base import RequestQueueClient
16-
from crawlee.storage_clients.models import (
17-
AddRequestsResponse,
18-
CachedRequest,
19-
ProcessedRequest,
20-
ProlongRequestLockResponse,
21-
RequestQueueHead,
22-
RequestQueueMetadata,
23-
)
16+
from crawlee.storage_clients.models import AddRequestsResponse, ProcessedRequest, RequestQueueMetadata
17+
18+
from ._models import CachedRequest, ProlongRequestLockResponse, RequestQueueHead
2419

2520
if TYPE_CHECKING:
2621
from collections.abc import Sequence

0 commit comments

Comments
 (0)