From 047ea82c295db68fc8b0685d248081f9ae34a734 Mon Sep 17 00:00:00 2001 From: drobnikj Date: Tue, 20 May 2025 16:01:15 +0200 Subject: [PATCH] feat: Add `unlock_requests` method to RequestQueue clients Introduce the `unlock_requests` method to both sync and async RequestQueue clients, allowing users to unlock all requests locked by the same clientKey or Actor run. --- .../clients/resource_clients/request_queue.py | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/src/apify_client/clients/resource_clients/request_queue.py b/src/apify_client/clients/resource_clients/request_queue.py index d17e725a..2e5b7003 100644 --- a/src/apify_client/clients/resource_clients/request_queue.py +++ b/src/apify_client/clients/resource_clients/request_queue.py @@ -404,6 +404,24 @@ def list_requests( return parse_date_fields(pluck_data(response.json())) + def unlock_requests(self: RequestQueueClient) -> dict: + """Unlock all requests in the queue, which were locked by the same clientKey or from the same Actor run. + + https://docs.apify.com/api/v2#/reference/request-queues/request-collection/unlock-requests + + Returns: + dict: Result of the unlock operation + """ + request_params = self._params(clientKey=self.client_key) + + response = self.http_client.call( + url=self._url('requests/unlock'), + method='POST', + params=request_params, + ) + + return parse_date_fields(pluck_data(response.json())) + class RequestQueueClientAsync(ResourceClientAsync): """Async sub-client for manipulating a single request queue.""" @@ -813,3 +831,21 @@ async def list_requests( ) return parse_date_fields(pluck_data(response.json())) + + async def unlock_requests(self: RequestQueueClientAsync) -> dict: + """Unlock all requests in the queue, which were locked by the same clientKey or from the same Actor run. + + https://docs.apify.com/api/v2#/reference/request-queues/request-collection/unlock-requests + + Returns: + dict: Result of the unlock operation + """ + request_params = self._params(clientKey=self.client_key) + + response = await self.http_client.call( + url=self._url('requests/unlock'), + method='POST', + params=request_params, + ) + + return parse_date_fields(pluck_data(response.json()))