Skip to content

Commit 2145cae

Browse files
drobnikjfnesveda
andauthored
feat: add list_and_lock_head, delete_request_lock, prolong_request_lock, batch_add_requests, batch_delete_requests and list_requests methods (#129)
Co-authored-by: František Nesveda <[email protected]>
1 parent f1c69f2 commit 2145cae

File tree

7 files changed

+617
-2
lines changed

7 files changed

+617
-2
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
Changelog
22
=========
33

4+
[1.3.0](../../releases/tag/v1.3.0) - TBD
5+
6+
### Added
7+
8+
- Added list_and_lock_head, delete_request_lock, prolong_request_lock methods for the RequestQueueClient(Async) classes
9+
- Added batch_add_requests, batch_delete_requests, list_requests methods for the RequestQueueClient(Async) classes
10+
411
[1.2.2](../../releases/tag/v1.2.2) - 2023-05-31
512

613
### Fixed

docs/docs.md

Lines changed: 236 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3742,10 +3742,16 @@ Async sub-client for manipulating a single request queue.
37423742
* [async update()](#requestqueueclientasync-update)
37433743
* [async delete()](#requestqueueclientasync-delete)
37443744
* [async list\_head()](#requestqueueclientasync-list\_head)
3745+
* [async list\_and\_lock\_head()](#requestqueueclientasync-list\_and\_lock\_head)
37453746
* [async add\_request()](#requestqueueclientasync-add\_request)
37463747
* [async get\_request()](#requestqueueclientasync-get\_request)
37473748
* [async update\_request()](#requestqueueclientasync-update\_request)
37483749
* [async delete\_request()](#requestqueueclientasync-delete\_request)
3750+
* [async prolong\_request\_lock()](#requestqueueclientasync-prolong\_request\_lock)
3751+
* [async delete\_request\_lock()](#requestqueueclientasync-delete\_request\_lock)
3752+
* [async batch\_add\_requests()](#requestqueueclientasync-batch\_add\_requests)
3753+
* [async batch\_delete\_requests()](#requestqueueclientasync-batch\_delete\_requests)
3754+
* [async list\_requests()](#requestqueueclientasync-list\_requests)
37493755

37503756
***
37513757

@@ -3817,6 +3823,28 @@ Retrieve a given number of requests from the beginning of the queue.
38173823

38183824
***
38193825

3826+
#### [](#requestqueueclientasync-list_and_lock_head) `async RequestQueueClientAsync.list_and_lock_head(*, lock_secs, limit=None)`
3827+
3828+
Retrieve a given number of unlocked requests from the beginning of the queue and lock them for a given time.
3829+
3830+
[https://docs.apify.com/api/v2#/reference/request-queues/queue-head-with-locks/get-head-and-lock](https://docs.apify.com/api/v2#/reference/request-queues/queue-head-with-locks/get-head-and-lock)
3831+
3832+
* **Parameters**
3833+
3834+
* **lock_secs** (`int`) – How long the requests will be locked for, in seconds
3835+
3836+
* **limit** (`int`, *optional*) – How many requests to retrieve
3837+
3838+
* **Returns**
3839+
3840+
The desired number of locked requests from the beginning of the queue.
3841+
3842+
* **Return type**
3843+
3844+
`dict`
3845+
3846+
***
3847+
38203848
#### [](#requestqueueclientasync-add_request) `async RequestQueueClientAsync.add_request(request, *, forefront=None)`
38213849

38223850
Add a request to the queue.
@@ -3897,6 +3925,96 @@ Delete a request from the queue.
38973925

38983926
***
38993927

3928+
#### [](#requestqueueclientasync-prolong_request_lock) `async RequestQueueClientAsync.prolong_request_lock(request_id, *, forefront=None, lock_secs)`
3929+
3930+
Prolong the lock on a request.
3931+
3932+
[https://docs.apify.com/api/v2#/reference/request-queues/request-lock/prolong-request-lock](https://docs.apify.com/api/v2#/reference/request-queues/request-lock/prolong-request-lock)
3933+
3934+
* **Parameters**
3935+
3936+
* **request_id** (`str`) – ID of the request to prolong the lock
3937+
3938+
* **forefront** (`bool`, *optional*) – Whether to put the request in the beginning or the end of the queue after lock expires
3939+
3940+
* **lock_secs** (`int`) – By how much to prolong the lock, in seconds
3941+
3942+
* **Return type**
3943+
3944+
`Dict`
3945+
3946+
***
3947+
3948+
#### [](#requestqueueclientasync-delete_request_lock) `async RequestQueueClientAsync.delete_request_lock(request_id, *, forefront=None)`
3949+
3950+
Delete the lock on a request.
3951+
3952+
[https://docs.apify.com/api/v2#/reference/request-queues/request-lock/delete-request-lock](https://docs.apify.com/api/v2#/reference/request-queues/request-lock/delete-request-lock)
3953+
3954+
* **Parameters**
3955+
3956+
* **request_id** (`str`) – ID of the request to delete the lock
3957+
3958+
* **forefront** (`bool`, *optional*) – Whether to put the request in the beginning or the end of the queue after the lock is deleted
3959+
3960+
* **Return type**
3961+
3962+
`None`
3963+
3964+
***
3965+
3966+
#### [](#requestqueueclientasync-batch_add_requests) `async RequestQueueClientAsync.batch_add_requests(requests, *, forefront=None)`
3967+
3968+
Add requests to the queue.
3969+
3970+
[https://docs.apify.com/api/v2#/reference/request-queues/batch-request-operations/add-requests](https://docs.apify.com/api/v2#/reference/request-queues/batch-request-operations/add-requests)
3971+
3972+
* **Parameters**
3973+
3974+
* **requests** (`List[Dict[str, Any]]`) – List of the requests to add
3975+
3976+
* **forefront** (`bool`, *optional*) – Whether to add the requests to the head or the end of the queue
3977+
3978+
* **Return type**
3979+
3980+
`Dict`
3981+
3982+
***
3983+
3984+
#### [](#requestqueueclientasync-batch_delete_requests) `async RequestQueueClientAsync.batch_delete_requests(requests)`
3985+
3986+
Delete given requests from the queue.
3987+
3988+
[https://docs.apify.com/api/v2#/reference/request-queues/batch-request-operations/delete-requests](https://docs.apify.com/api/v2#/reference/request-queues/batch-request-operations/delete-requests)
3989+
3990+
* **Parameters**
3991+
3992+
* **requests** (`List[Dict[str, Any]]`) – List of the requests to delete
3993+
3994+
* **Return type**
3995+
3996+
`Dict`
3997+
3998+
***
3999+
4000+
#### [](#requestqueueclientasync-list_requests) `async RequestQueueClientAsync.list_requests(*, limit=None, exclusive_start_id=None)`
4001+
4002+
List requests in the queue.
4003+
4004+
[https://docs.apify.com/api/v2#/reference/request-queues/request-collection/list-requests](https://docs.apify.com/api/v2#/reference/request-queues/request-collection/list-requests)
4005+
4006+
* **Parameters**
4007+
4008+
* **limit** (`int`, *optional*) – How many requests to retrieve
4009+
4010+
* **exclusive_start_id** (`str`, *optional*) – All requests up to this one (including) are skipped from the result
4011+
4012+
* **Return type**
4013+
4014+
`Dict`
4015+
4016+
***
4017+
39004018
### [](#requestqueueclient) RequestQueueClient
39014019

39024020
Sub-client for manipulating a single request queue.
@@ -3905,10 +4023,16 @@ Sub-client for manipulating a single request queue.
39054023
* [update()](#requestqueueclient-update)
39064024
* [delete()](#requestqueueclient-delete)
39074025
* [list\_head()](#requestqueueclient-list\_head)
4026+
* [list\_and\_lock\_head()](#requestqueueclient-list\_and\_lock\_head)
39084027
* [add\_request()](#requestqueueclient-add\_request)
39094028
* [get\_request()](#requestqueueclient-get\_request)
39104029
* [update\_request()](#requestqueueclient-update\_request)
39114030
* [delete\_request()](#requestqueueclient-delete\_request)
4031+
* [prolong\_request\_lock()](#requestqueueclient-prolong\_request\_lock)
4032+
* [delete\_request\_lock()](#requestqueueclient-delete\_request\_lock)
4033+
* [batch\_add\_requests()](#requestqueueclient-batch\_add\_requests)
4034+
* [batch\_delete\_requests()](#requestqueueclient-batch\_delete\_requests)
4035+
* [list\_requests()](#requestqueueclient-list\_requests)
39124036

39134037
***
39144038

@@ -3980,6 +4104,28 @@ Retrieve a given number of requests from the beginning of the queue.
39804104

39814105
***
39824106

4107+
#### [](#requestqueueclient-list_and_lock_head) `RequestQueueClient.list_and_lock_head(*, lock_secs, limit=None)`
4108+
4109+
Retrieve a given number of unlocked requests from the beginning of the queue and lock them for a given time.
4110+
4111+
[https://docs.apify.com/api/v2#/reference/request-queues/queue-head-with-locks/get-head-and-lock](https://docs.apify.com/api/v2#/reference/request-queues/queue-head-with-locks/get-head-and-lock)
4112+
4113+
* **Parameters**
4114+
4115+
* **lock_secs** (`int`) – How long the requests will be locked for, in seconds
4116+
4117+
* **limit** (`int`, *optional*) – How many requests to retrieve
4118+
4119+
* **Returns**
4120+
4121+
The desired number of locked requests from the beginning of the queue.
4122+
4123+
* **Return type**
4124+
4125+
`dict`
4126+
4127+
***
4128+
39834129
#### [](#requestqueueclient-add_request) `RequestQueueClient.add_request(request, *, forefront=None)`
39844130

39854131
Add a request to the queue.
@@ -4060,6 +4206,96 @@ Delete a request from the queue.
40604206

40614207
***
40624208

4209+
#### [](#requestqueueclient-prolong_request_lock) `RequestQueueClient.prolong_request_lock(request_id, *, forefront=None, lock_secs)`
4210+
4211+
Prolong the lock on a request.
4212+
4213+
[https://docs.apify.com/api/v2#/reference/request-queues/request-lock/prolong-request-lock](https://docs.apify.com/api/v2#/reference/request-queues/request-lock/prolong-request-lock)
4214+
4215+
* **Parameters**
4216+
4217+
* **request_id** (`str`) – ID of the request to prolong the lock
4218+
4219+
* **forefront** (`bool`, *optional*) – Whether to put the request in the beginning or the end of the queue after lock expires
4220+
4221+
* **lock_secs** (`int`) – By how much to prolong the lock, in seconds
4222+
4223+
* **Return type**
4224+
4225+
`Dict`
4226+
4227+
***
4228+
4229+
#### [](#requestqueueclient-delete_request_lock) `RequestQueueClient.delete_request_lock(request_id, *, forefront=None)`
4230+
4231+
Delete the lock on a request.
4232+
4233+
[https://docs.apify.com/api/v2#/reference/request-queues/request-lock/delete-request-lock](https://docs.apify.com/api/v2#/reference/request-queues/request-lock/delete-request-lock)
4234+
4235+
* **Parameters**
4236+
4237+
* **request_id** (`str`) – ID of the request to delete the lock
4238+
4239+
* **forefront** (`bool`, *optional*) – Whether to put the request in the beginning or the end of the queue after the lock is deleted
4240+
4241+
* **Return type**
4242+
4243+
`None`
4244+
4245+
***
4246+
4247+
#### [](#requestqueueclient-batch_add_requests) `RequestQueueClient.batch_add_requests(requests, *, forefront=None)`
4248+
4249+
Add requests to the queue.
4250+
4251+
[https://docs.apify.com/api/v2#/reference/request-queues/batch-request-operations/add-requests](https://docs.apify.com/api/v2#/reference/request-queues/batch-request-operations/add-requests)
4252+
4253+
* **Parameters**
4254+
4255+
* **requests** (`List[Dict[str, Any]]`) – List of the requests to add
4256+
4257+
* **forefront** (`bool`, *optional*) – Whether to add the requests to the head or the end of the queue
4258+
4259+
* **Return type**
4260+
4261+
`Dict`
4262+
4263+
***
4264+
4265+
#### [](#requestqueueclient-batch_delete_requests) `RequestQueueClient.batch_delete_requests(requests)`
4266+
4267+
Delete given requests from the queue.
4268+
4269+
[https://docs.apify.com/api/v2#/reference/request-queues/batch-request-operations/delete-requests](https://docs.apify.com/api/v2#/reference/request-queues/batch-request-operations/delete-requests)
4270+
4271+
* **Parameters**
4272+
4273+
* **requests** (`List[Dict[str, Any]]`) – List of the requests to delete
4274+
4275+
* **Return type**
4276+
4277+
`Dict`
4278+
4279+
***
4280+
4281+
#### [](#requestqueueclient-list_requests) `RequestQueueClient.list_requests(*, limit=None, exclusive_start_id=None)`
4282+
4283+
List requests in the queue.
4284+
4285+
[https://docs.apify.com/api/v2#/reference/request-queues/request-collection/list-requests](https://docs.apify.com/api/v2#/reference/request-queues/request-collection/list-requests)
4286+
4287+
* **Parameters**
4288+
4289+
* **limit** (`int`, *optional*) – How many requests to retrieve
4290+
4291+
* **exclusive_start_id** (`str`, *optional*) – All requests up to this one (including) are skipped from the result
4292+
4293+
* **Return type**
4294+
4295+
`Dict`
4296+
4297+
***
4298+
40634299
### [](#requestqueuecollectionclientasync) RequestQueueCollectionClientAsync
40644300

40654301
Async sub-client for manipulating request queues.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "apify_client"
3-
version = "1.2.2"
3+
version = "1.3.0"
44
description = "Apify API client for Python"
55
readme = "README.md"
66
license = {text = "Apache Software License"}

scripts/check_async_docstrings.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@
2929
# Find corresponding sync method in the sync class
3030
sync_method = sync_class.find('DefNode', name=async_method.name)
3131

32+
# Skip methods with @ignore_docs decorator
33+
if len(async_method.decorators) and str(async_method.decorators[0].value) == 'ignore_docs':
34+
continue
35+
3236
# If the sync method has a docstring, check if it matches the async dostring
3337
if isinstance(sync_method.value[0].value, str):
3438
sync_docstring = sync_method.value[0].value

scripts/fix_async_docstrings.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@
2626
# Find corresponding sync method in the sync class
2727
sync_method = sync_class.find('DefNode', name=async_method.name)
2828

29+
# Skip methods with @ignore_docs decorator
30+
if len(async_method.decorators) and str(async_method.decorators[0].value) == 'ignore_docs':
31+
continue
32+
2933
# If the sync method has a docstring, copy it to the async method (with adjustments)
3034
if isinstance(sync_method.value[0].value, str):
3135
sync_docstring = sync_method.value[0].value

0 commit comments

Comments
 (0)