Skip to content

Commit 7c52c64

Browse files
authored
feat: Add unlockRequests endpoint to RequestQueue client (#700)
Implement the `unlockRequests` method in the RequestQueue client to support the new API endpoint. Update the mock server and tests to include the endpoint.
1 parent 3041d8a commit 7c52c64

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed

src/resource_clients/request_queue.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,22 @@ export class RequestQueueClient extends ResourceClient {
503503
return cast(parseDateFields(pluckData(response.data)));
504504
}
505505

506+
/**
507+
* https://docs.apify.com/api/v2/request-queue-requests-unlock-post
508+
*/
509+
async unlockRequests(): Promise<RequestQueueClientUnlockRequestsResult> {
510+
const response = await this.httpClient.call({
511+
url: this._url('requests/unlock'),
512+
method: 'POST',
513+
timeout: this.timeoutMillis,
514+
params: this._params({
515+
clientKey: this.clientKey,
516+
}),
517+
});
518+
519+
return cast(parseDateFields(pluckData(response.data)));
520+
}
521+
506522
/**
507523
* https://docs.apify.com/api/v2#/reference/request-queues/request-collection/list-requests
508524
*
@@ -676,6 +692,10 @@ interface UnprocessedRequest {
676692
method?: AllowedHttpMethods;
677693
}
678694

695+
export interface RequestQueueClientUnlockRequestsResult {
696+
unlockedCount: number;
697+
}
698+
679699
export interface RequestQueueClientBatchRequestsOperationResult {
680700
processedRequests: ProcessedRequest[];
681701
unprocessedRequests: UnprocessedRequest[];

test/mock_server/routes/request_queues.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ const ROUTES = [
1616
{ id: 'put-lock-request', method: 'PUT', path: '/:queueId/requests/:requestId/lock' },
1717
{ id: 'delete-lock-request', method: 'DELETE', path: '/:queueId/requests/:requestId/lock' },
1818
{ id: 'batch-insert', method: 'POST', path: '/:queueId/requests/batch', type: 'dummyBatchOperation' },
19+
{ id: 'unlock-requests', method: 'POST', path: '/:queueId/requests/unlock' },
1920
{ id: 'batch-delete', method: 'DELETE', path: '/:queueId/requests/batch', type: 'dummyBatchOperation' },
2021
{ id: 'get-request', method: 'GET', path: '/:queueId/requests/:requestId' },
2122
{ id: 'delete-request', method: 'DELETE', path: '/:queueId/requests/:requestId' },

test/request_queues.test.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,18 @@ describe('Request Queue methods', () => {
166166
validateRequest({ forefront }, { queueId }, request);
167167
});
168168

169+
test('unlockRequests() works', async () => {
170+
const queueId = 'some-id';
171+
172+
const res = await client.requestQueue(queueId).unlockRequests();
173+
expect(res.id).toEqual('unlock-requests');
174+
validateRequest({}, { queueId });
175+
176+
const browserRes = await page.evaluate((id) => client.requestQueue(id).unlockRequests(), queueId);
177+
expect(browserRes).toEqual(res);
178+
validateRequest({}, { queueId });
179+
});
180+
169181
test('getRequest() works', async () => {
170182
const queueId = 'some-id';
171183
const requestId = 'xxx';

0 commit comments

Comments
 (0)