apify-client 3.0.0-beta.14 → 3.0.0-beta.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/apify_api_error.js +23 -7
- package/dist/apify_client.d.ts +22 -3
- package/dist/apify_client.js +35 -29
- package/dist/base/api_client.d.ts +6 -6
- package/dist/base/api_client.js +24 -16
- package/dist/base/resource_client.d.ts +13 -8
- package/dist/base/resource_client.js +35 -19
- package/dist/base/resource_collection_client.d.ts +6 -4
- package/dist/base/resource_collection_client.js +17 -11
- package/dist/bundle.js +13 -13
- package/dist/bundle.js.map +1 -1
- package/dist/http_client.d.ts +34 -13
- package/dist/http_client.js +58 -28
- package/dist/index.d.ts +1 -0
- package/dist/resource_clients/actor.d.ts +26 -11
- package/dist/resource_clients/actor.js +62 -33
- package/dist/resource_clients/actor_collection.d.ts +6 -2
- package/dist/resource_clients/actor_collection.js +9 -3
- package/dist/resource_clients/actor_env_var.d.ts +10 -3
- package/dist/resource_clients/actor_env_var.js +16 -6
- package/dist/resource_clients/actor_env_var_collection.d.ts +7 -2
- package/dist/resource_clients/actor_env_var_collection.js +11 -4
- package/dist/resource_clients/actor_version.d.ts +10 -3
- package/dist/resource_clients/actor_version.js +18 -8
- package/dist/resource_clients/actor_version_collection.d.ts +7 -2
- package/dist/resource_clients/actor_version_collection.js +11 -4
- package/dist/resource_clients/build.d.ts +16 -6
- package/dist/resource_clients/build.js +30 -15
- package/dist/resource_clients/build_collection.d.ts +3 -1
- package/dist/resource_clients/build_collection.js +4 -1
- package/dist/resource_clients/dataset.d.ts +21 -7
- package/dist/resource_clients/dataset.js +65 -37
- package/dist/resource_clients/dataset_collection.d.ts +6 -2
- package/dist/resource_clients/dataset_collection.js +12 -2
- package/dist/resource_clients/key_value_store.d.ts +31 -11
- package/dist/resource_clients/key_value_store.js +58 -34
- package/dist/resource_clients/key_value_store_collection.d.ts +6 -2
- package/dist/resource_clients/key_value_store_collection.js +12 -2
- package/dist/resource_clients/log.d.ts +4 -1
- package/dist/resource_clients/log.js +15 -6
- package/dist/resource_clients/request_queue.d.ts +52 -18
- package/dist/resource_clients/request_queue.js +114 -60
- package/dist/resource_clients/request_queue_collection.d.ts +6 -2
- package/dist/resource_clients/request_queue_collection.js +9 -3
- package/dist/resource_clients/run.d.ts +33 -13
- package/dist/resource_clients/run.js +65 -35
- package/dist/resource_clients/run_collection.d.ts +3 -1
- package/dist/resource_clients/run_collection.js +4 -1
- package/dist/resource_clients/schedule.d.ts +13 -4
- package/dist/resource_clients/schedule.js +23 -9
- package/dist/resource_clients/schedule_collection.d.ts +6 -2
- package/dist/resource_clients/schedule_collection.js +9 -3
- package/dist/resource_clients/store_collection.d.ts +3 -1
- package/dist/resource_clients/store_collection.js +4 -1
- package/dist/resource_clients/task.d.ts +27 -9
- package/dist/resource_clients/task.js +60 -31
- package/dist/resource_clients/task_collection.d.ts +6 -2
- package/dist/resource_clients/task_collection.js +9 -3
- package/dist/resource_clients/user.d.ts +14 -5
- package/dist/resource_clients/user.js +30 -14
- package/dist/resource_clients/webhook.d.ts +13 -4
- package/dist/resource_clients/webhook.js +24 -10
- package/dist/resource_clients/webhook_collection.d.ts +6 -2
- package/dist/resource_clients/webhook_collection.js +9 -3
- package/dist/resource_clients/webhook_dispatch.d.ts +4 -1
- package/dist/resource_clients/webhook_dispatch.js +7 -2
- package/dist/resource_clients/webhook_dispatch_collection.d.ts +3 -1
- package/dist/resource_clients/webhook_dispatch_collection.js +4 -1
- package/dist/timeouts.d.ts +72 -0
- package/dist/timeouts.js +31 -0
- package/dist/utils.d.ts +10 -0
- package/dist/utils.js +10 -0
- package/package.json +1 -1
|
@@ -1,24 +1,26 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import { MAX_PAYLOAD_SIZE_BYTES, REQUEST_QUEUE_MAX_REQUESTS_PER_BATCH_OPERATION } from '@apify/consts';
|
|
3
3
|
import log from '@apify/log';
|
|
4
|
-
import {
|
|
4
|
+
import { ResourceClient } from '../base/resource_client.js';
|
|
5
5
|
import { ResponseValidationError } from '../response_validation_error.js';
|
|
6
6
|
import * as schemas from '../schemas.js';
|
|
7
|
+
import { optionalTimeoutSchema, timeoutOptionsSchema, timeoutOptionsShape } from '../timeouts.js';
|
|
7
8
|
import { anyObjectSchema, cast, catchNotFoundOrThrow, isNonArrayObject, parseArgument, parseDateFields, parseResponse, RequestQueuePaginationIterator, sliceArrayByByteLength, } from '../utils.js';
|
|
8
9
|
const DEFAULT_PARALLEL_BATCH_ADD_REQUESTS = 5;
|
|
9
10
|
const DEFAULT_UNPROCESSED_RETRIES_BATCH_ADD_REQUESTS = 3;
|
|
10
11
|
const DEFAULT_MIN_DELAY_BETWEEN_UNPROCESSED_REQUESTS_RETRIES_MILLIS = 500;
|
|
11
12
|
const DEFAULT_REQUEST_QUEUE_REQUEST_PAGE_LIMIT = 1000;
|
|
12
13
|
const SAFETY_BUFFER_PERCENT = 0.01 / 100; // 0.01%
|
|
13
|
-
const listHeadOptionsSchema = z.strictObject({ limit: z.number().min(0).optional() });
|
|
14
|
+
const listHeadOptionsSchema = z.strictObject({ limit: z.number().min(0).optional(), ...timeoutOptionsShape });
|
|
14
15
|
const listAndLockHeadOptionsSchema = z.strictObject({
|
|
15
16
|
lockSecs: z.number(),
|
|
16
17
|
limit: z.number().min(0).optional(),
|
|
18
|
+
...timeoutOptionsShape,
|
|
17
19
|
});
|
|
18
20
|
// Predicates, not `z.looseObject` arms: these run over a whole batch, and an object arm would copy
|
|
19
21
|
// every key of every request. `id` is assigned by the API, so a new request must not carry one.
|
|
20
22
|
const newRequestSchema = z.custom((value) => isNonArrayObject(value) && value.id === undefined, 'Expected a request object without an `id`');
|
|
21
|
-
const forefrontOptionsSchema = z.strictObject({ forefront: z.boolean().optional() });
|
|
23
|
+
const forefrontOptionsSchema = z.strictObject({ forefront: z.boolean().optional(), ...timeoutOptionsShape });
|
|
22
24
|
const batchAddRequestsSchema = z.array(newRequestSchema).min(1).max(REQUEST_QUEUE_MAX_REQUESTS_PER_BATCH_OPERATION);
|
|
23
25
|
const batchAddRequestsWithRetriesSchema = z.array(newRequestSchema).min(1);
|
|
24
26
|
const optionalBooleanSchema = z.boolean().optional();
|
|
@@ -33,18 +35,21 @@ const existingRequestSchema = z.custom((value) => isNonArrayObject(value) && typ
|
|
|
33
35
|
const prolongRequestLockOptionsSchema = z.strictObject({
|
|
34
36
|
lockSecs: z.number(),
|
|
35
37
|
forefront: z.boolean().optional(),
|
|
38
|
+
...timeoutOptionsShape,
|
|
36
39
|
});
|
|
37
40
|
const requestFilterSchema = z.array(z.enum(['locked', 'pending'])).min(1);
|
|
38
41
|
const listRequestsOptionsSchema = z.strictObject({
|
|
39
42
|
limit: z.number().min(0).optional(),
|
|
40
43
|
cursor: z.string().optional(),
|
|
41
44
|
filter: requestFilterSchema.optional(),
|
|
45
|
+
...timeoutOptionsShape,
|
|
42
46
|
});
|
|
43
47
|
const paginateRequestsOptionsSchema = z.strictObject({
|
|
44
48
|
limit: z.number().min(0).optional(),
|
|
45
49
|
maxPageLimit: z.number().default(DEFAULT_REQUEST_QUEUE_REQUEST_PAGE_LIMIT),
|
|
46
50
|
cursor: z.string().optional(),
|
|
47
51
|
filter: requestFilterSchema.optional(),
|
|
52
|
+
...timeoutOptionsShape,
|
|
48
53
|
});
|
|
49
54
|
/**
|
|
50
55
|
* Client for managing a specific Request queue.
|
|
@@ -78,7 +83,7 @@ const paginateRequestsOptionsSchema = z.strictObject({
|
|
|
78
83
|
*/
|
|
79
84
|
export class RequestQueueClient extends ResourceClient {
|
|
80
85
|
clientKey;
|
|
81
|
-
|
|
86
|
+
timeoutSecs;
|
|
82
87
|
/**
|
|
83
88
|
* @hidden
|
|
84
89
|
*/
|
|
@@ -88,35 +93,56 @@ export class RequestQueueClient extends ResourceClient {
|
|
|
88
93
|
...options,
|
|
89
94
|
});
|
|
90
95
|
this.clientKey = userOptions.clientKey;
|
|
91
|
-
this.
|
|
96
|
+
this.timeoutSecs = userOptions.timeoutSecs;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Picks the timeout of a request: an explicit per-call `timeoutSecs` as is, otherwise the method's default
|
|
100
|
+
* tier, capped at the queue-wide `timeoutSecs` when one was given.
|
|
101
|
+
*/
|
|
102
|
+
resolveTimeout(timeoutSecs, defaultTier) {
|
|
103
|
+
if (timeoutSecs !== undefined)
|
|
104
|
+
return timeoutSecs;
|
|
105
|
+
if (this.timeoutSecs === undefined)
|
|
106
|
+
return defaultTier;
|
|
107
|
+
const tierSecs = this.httpClient.timeoutMillis[defaultTier] / 1000;
|
|
108
|
+
return tierSecs <= this.timeoutSecs ? defaultTier : this.timeoutSecs;
|
|
92
109
|
}
|
|
93
110
|
/**
|
|
94
111
|
* Gets the Request queue object from the Apify API.
|
|
95
112
|
*
|
|
113
|
+
* @param options - Request options
|
|
114
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'short'`.
|
|
96
115
|
* @returns The RequestQueue object, or `undefined` if it does not exist
|
|
97
116
|
* @see https://docs.apify.com/api/v2/request-queue-get
|
|
98
117
|
*/
|
|
99
|
-
async get() {
|
|
100
|
-
|
|
118
|
+
async get(options = {}) {
|
|
119
|
+
const { timeoutSecs } = parseArgument(options, timeoutOptionsSchema, 'TimeoutOptions');
|
|
120
|
+
return this.getResource(schemas.RequestQueue(), {}, this.resolveTimeout(timeoutSecs, 'short'));
|
|
101
121
|
}
|
|
102
122
|
/**
|
|
103
123
|
* Updates the Request queue with specified fields.
|
|
104
124
|
*
|
|
105
125
|
* @param newFields - Fields to update in the Request queue
|
|
126
|
+
* @param options - Request options
|
|
127
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'short'`.
|
|
106
128
|
* @returns The updated RequestQueue object
|
|
107
129
|
* @see https://docs.apify.com/api/v2/request-queue-put
|
|
108
130
|
*/
|
|
109
|
-
async update(newFields) {
|
|
131
|
+
async update(newFields, options = {}) {
|
|
110
132
|
parseArgument(newFields, anyObjectSchema);
|
|
111
|
-
|
|
133
|
+
const { timeoutSecs } = parseArgument(options, timeoutOptionsSchema, 'TimeoutOptions');
|
|
134
|
+
return this.updateResource(schemas.RequestQueue(), newFields, this.resolveTimeout(timeoutSecs, 'short'));
|
|
112
135
|
}
|
|
113
136
|
/**
|
|
114
137
|
* Deletes the Request queue.
|
|
115
138
|
*
|
|
139
|
+
* @param options - Request options
|
|
140
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'short'`.
|
|
116
141
|
* @see https://docs.apify.com/api/v2/request-queue-delete
|
|
117
142
|
*/
|
|
118
|
-
async delete() {
|
|
119
|
-
|
|
143
|
+
async delete(options = {}) {
|
|
144
|
+
const { timeoutSecs } = parseArgument(options, timeoutOptionsSchema, 'TimeoutOptions');
|
|
145
|
+
return this.deleteResource(this.resolveTimeout(timeoutSecs, 'short'));
|
|
120
146
|
}
|
|
121
147
|
/**
|
|
122
148
|
* Lists requests from the beginning of the queue (head).
|
|
@@ -125,16 +151,18 @@ export class RequestQueueClient extends ResourceClient {
|
|
|
125
151
|
* inspecting what requests are waiting to be processed.
|
|
126
152
|
*
|
|
127
153
|
* @param options - Options for listing (e.g., limit)
|
|
154
|
+
* @param options.limit - Maximum number of requests to return.
|
|
155
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'short'`.
|
|
128
156
|
* @returns List of requests from the queue head
|
|
129
157
|
* @see https://docs.apify.com/api/v2/request-queue-head-get
|
|
130
158
|
*/
|
|
131
159
|
async listHead(options = {}) {
|
|
132
160
|
const parsed = parseArgument(options, listHeadOptionsSchema, 'RequestQueueClientListHeadOptions');
|
|
133
161
|
const response = await this.httpClient.call({
|
|
134
|
-
url: this.
|
|
162
|
+
url: this.buildUrl('head'),
|
|
135
163
|
method: 'GET',
|
|
136
|
-
|
|
137
|
-
params: this.
|
|
164
|
+
timeoutSecs: this.resolveTimeout(parsed.timeoutSecs, 'short'),
|
|
165
|
+
params: this.buildParams({
|
|
138
166
|
limit: parsed.limit,
|
|
139
167
|
clientKey: this.clientKey,
|
|
140
168
|
}),
|
|
@@ -153,6 +181,7 @@ export class RequestQueueClient extends ResourceClient {
|
|
|
153
181
|
* @param options - Lock configuration
|
|
154
182
|
* @param options.lockSecs - **Required.** Duration in seconds to lock the requests. After this time, the locks expire and requests can be retrieved by other clients.
|
|
155
183
|
* @param options.limit - Maximum number of requests to return. Default is 25.
|
|
184
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'medium'`.
|
|
156
185
|
* @returns Object containing `items` (locked requests), `queueModifiedAt`, `hadMultipleClients`, and lock information
|
|
157
186
|
* @see https://docs.apify.com/api/v2/request-queue-head-lock-post
|
|
158
187
|
*
|
|
@@ -177,10 +206,10 @@ export class RequestQueueClient extends ResourceClient {
|
|
|
177
206
|
async listAndLockHead(options) {
|
|
178
207
|
const parsed = parseArgument(options, listAndLockHeadOptionsSchema, 'RequestQueueClientListAndLockHeadOptions');
|
|
179
208
|
const response = await this.httpClient.call({
|
|
180
|
-
url: this.
|
|
209
|
+
url: this.buildUrl('head/lock'),
|
|
181
210
|
method: 'POST',
|
|
182
|
-
|
|
183
|
-
params: this.
|
|
211
|
+
timeoutSecs: this.resolveTimeout(parsed.timeoutSecs, 'medium'),
|
|
212
|
+
params: this.buildParams({
|
|
184
213
|
limit: parsed.limit,
|
|
185
214
|
lockSecs: parsed.lockSecs,
|
|
186
215
|
clientKey: this.clientKey,
|
|
@@ -204,6 +233,7 @@ export class RequestQueueClient extends ResourceClient {
|
|
|
204
233
|
* @param request.payload - HTTP payload for POST/PUT requests (string).
|
|
205
234
|
* @param options - Additional options
|
|
206
235
|
* @param options.forefront - If `true`, adds the request to the beginning of the queue. Default is `false` (adds to the end).
|
|
236
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'short'`.
|
|
207
237
|
* @returns Object with `requestId`, `wasAlreadyPresent`, and `wasAlreadyHandled` flags
|
|
208
238
|
* @see https://docs.apify.com/api/v2/request-queue-requests-post
|
|
209
239
|
*
|
|
@@ -230,11 +260,11 @@ export class RequestQueueClient extends ResourceClient {
|
|
|
230
260
|
parseArgument(request, newRequestSchema);
|
|
231
261
|
const parsed = parseArgument(options, forefrontOptionsSchema, 'RequestQueueClientAddRequestOptions');
|
|
232
262
|
const response = await this.httpClient.call({
|
|
233
|
-
url: this.
|
|
263
|
+
url: this.buildUrl('requests'),
|
|
234
264
|
method: 'POST',
|
|
235
|
-
|
|
265
|
+
timeoutSecs: this.resolveTimeout(parsed.timeoutSecs, 'short'),
|
|
236
266
|
data: request,
|
|
237
|
-
params: this.
|
|
267
|
+
params: this.buildParams({
|
|
238
268
|
forefront: parsed.forefront,
|
|
239
269
|
clientKey: this.clientKey,
|
|
240
270
|
}),
|
|
@@ -246,23 +276,23 @@ export class RequestQueueClient extends ResourceClient {
|
|
|
246
276
|
*
|
|
247
277
|
* @private
|
|
248
278
|
*/
|
|
249
|
-
async
|
|
279
|
+
async addRequestBatch(requests, options = {}) {
|
|
250
280
|
parseArgument(requests, batchAddRequestsSchema);
|
|
251
281
|
const parsed = parseArgument(options, forefrontOptionsSchema, 'RequestQueueClientAddRequestOptions');
|
|
252
282
|
const response = await this.httpClient.call({
|
|
253
|
-
url: this.
|
|
283
|
+
url: this.buildUrl('requests/batch'),
|
|
254
284
|
method: 'POST',
|
|
255
|
-
|
|
285
|
+
timeoutSecs: this.resolveTimeout(parsed.timeoutSecs, 'medium'),
|
|
256
286
|
data: requests,
|
|
257
|
-
params: this.
|
|
287
|
+
params: this.buildParams({
|
|
258
288
|
forefront: parsed.forefront,
|
|
259
289
|
clientKey: this.clientKey,
|
|
260
290
|
}),
|
|
261
291
|
});
|
|
262
292
|
return parseResponse(response, schemas.BatchAddResult());
|
|
263
293
|
}
|
|
264
|
-
async
|
|
265
|
-
const { forefront, maxUnprocessedRequestsRetries = DEFAULT_UNPROCESSED_RETRIES_BATCH_ADD_REQUESTS, minDelayBetweenUnprocessedRequestsRetriesMillis = DEFAULT_MIN_DELAY_BETWEEN_UNPROCESSED_REQUESTS_RETRIES_MILLIS, } = options;
|
|
294
|
+
async addRequestBatchWithRetries(requests, options = {}) {
|
|
295
|
+
const { forefront, timeoutSecs, maxUnprocessedRequestsRetries = DEFAULT_UNPROCESSED_RETRIES_BATCH_ADD_REQUESTS, minDelayBetweenUnprocessedRequestsRetriesMillis = DEFAULT_MIN_DELAY_BETWEEN_UNPROCESSED_REQUESTS_RETRIES_MILLIS, } = options;
|
|
266
296
|
// Keep track of the requests that remain to be processed (in parameter format)
|
|
267
297
|
let remainingRequests = requests;
|
|
268
298
|
// Keep track of the requests that have been processed (in api format)
|
|
@@ -272,8 +302,9 @@ export class RequestQueueClient extends ResourceClient {
|
|
|
272
302
|
let unprocessedRequests = [];
|
|
273
303
|
for (let i = 0; i < 1 + maxUnprocessedRequestsRetries; i++) {
|
|
274
304
|
try {
|
|
275
|
-
const response = await this.
|
|
305
|
+
const response = await this.addRequestBatch(remainingRequests, {
|
|
276
306
|
forefront,
|
|
307
|
+
timeoutSecs,
|
|
277
308
|
});
|
|
278
309
|
processedRequests.push(...response.processedRequests);
|
|
279
310
|
unprocessedRequests = response.unprocessedRequests;
|
|
@@ -329,6 +360,7 @@ export class RequestQueueClient extends ResourceClient {
|
|
|
329
360
|
* @param options.maxUnprocessedRequestsRetries - Maximum number of retry attempts for rate-limited requests. Default is 3.
|
|
330
361
|
* @param options.maxParallel - Maximum number of parallel batch API calls. Default is 5.
|
|
331
362
|
* @param options.minDelayBetweenUnprocessedRequestsRetriesMillis - Minimum delay before retrying rate-limited requests. Default is 500ms.
|
|
363
|
+
* @param options.timeoutSecs - Timeout for each batch API request. Default is `'medium'`.
|
|
332
364
|
* @returns Object with `processedRequests` (successfully added) and `unprocessedRequests` (failed after all retries)
|
|
333
365
|
* @see https://docs.apify.com/api/v2/request-queue-requests-batch-post
|
|
334
366
|
*
|
|
@@ -353,9 +385,10 @@ export class RequestQueueClient extends ResourceClient {
|
|
|
353
385
|
* @since Added in 2.1.0
|
|
354
386
|
*/
|
|
355
387
|
async batchAddRequests(requests, options = {}) {
|
|
356
|
-
const { forefront, maxUnprocessedRequestsRetries = DEFAULT_UNPROCESSED_RETRIES_BATCH_ADD_REQUESTS, maxParallel = DEFAULT_PARALLEL_BATCH_ADD_REQUESTS, minDelayBetweenUnprocessedRequestsRetriesMillis = DEFAULT_MIN_DELAY_BETWEEN_UNPROCESSED_REQUESTS_RETRIES_MILLIS, } = options;
|
|
388
|
+
const { forefront, timeoutSecs, maxUnprocessedRequestsRetries = DEFAULT_UNPROCESSED_RETRIES_BATCH_ADD_REQUESTS, maxParallel = DEFAULT_PARALLEL_BATCH_ADD_REQUESTS, minDelayBetweenUnprocessedRequestsRetriesMillis = DEFAULT_MIN_DELAY_BETWEEN_UNPROCESSED_REQUESTS_RETRIES_MILLIS, } = options;
|
|
357
389
|
parseArgument(requests, batchAddRequestsWithRetriesSchema);
|
|
358
390
|
parseArgument(forefront, optionalBooleanSchema);
|
|
391
|
+
parseArgument(timeoutSecs, optionalTimeoutSchema);
|
|
359
392
|
parseArgument(maxUnprocessedRequestsRetries, optionalNumberSchema);
|
|
360
393
|
parseArgument(maxParallel, optionalNumberSchema);
|
|
361
394
|
parseArgument(minDelayBetweenUnprocessedRequestsRetriesMillis, optionalNumberSchema);
|
|
@@ -367,7 +400,7 @@ export class RequestQueueClient extends ResourceClient {
|
|
|
367
400
|
while (i < requests.length) {
|
|
368
401
|
const slicedRequests = requests.slice(i, i + REQUEST_QUEUE_MAX_REQUESTS_PER_BATCH_OPERATION);
|
|
369
402
|
const requestsInBatch = sliceArrayByByteLength(slicedRequests, payloadSizeLimitBytes, i);
|
|
370
|
-
const requestPromise = this.
|
|
403
|
+
const requestPromise = this.addRequestBatchWithRetries(requestsInBatch, options);
|
|
371
404
|
executingRequests.add(requestPromise);
|
|
372
405
|
// A rejection reaches the caller through the awaits below; this bookkeeping chain only has to avoid
|
|
373
406
|
// turning it into an unhandled one of its own.
|
|
@@ -399,18 +432,21 @@ export class RequestQueueClient extends ResourceClient {
|
|
|
399
432
|
* Requests can be identified by either their ID or unique key.
|
|
400
433
|
*
|
|
401
434
|
* @param requests - Array of requests to delete (by id or uniqueKey)
|
|
435
|
+
* @param options - Request options
|
|
436
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'short'`.
|
|
402
437
|
* @returns Result containing processed and unprocessed requests
|
|
403
438
|
* @see https://docs.apify.com/api/v2/request-queue-requests-batch-delete
|
|
404
439
|
* @since Added in 2.3.0
|
|
405
440
|
*/
|
|
406
|
-
async batchDeleteRequests(requests) {
|
|
441
|
+
async batchDeleteRequests(requests, options = {}) {
|
|
407
442
|
parseArgument(requests, batchDeleteRequestsSchema);
|
|
443
|
+
const { timeoutSecs } = parseArgument(options, timeoutOptionsSchema, 'TimeoutOptions');
|
|
408
444
|
const response = await this.httpClient.call({
|
|
409
|
-
url: this.
|
|
445
|
+
url: this.buildUrl('requests/batch'),
|
|
410
446
|
method: 'DELETE',
|
|
411
|
-
|
|
447
|
+
timeoutSecs: this.resolveTimeout(timeoutSecs, 'short'),
|
|
412
448
|
data: requests,
|
|
413
|
-
params: this.
|
|
449
|
+
params: this.buildParams({
|
|
414
450
|
clientKey: this.clientKey,
|
|
415
451
|
}),
|
|
416
452
|
});
|
|
@@ -420,16 +456,19 @@ export class RequestQueueClient extends ResourceClient {
|
|
|
420
456
|
* Gets a specific request from the queue by its ID.
|
|
421
457
|
*
|
|
422
458
|
* @param id - Request ID
|
|
459
|
+
* @param options - Request options
|
|
460
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'short'`.
|
|
423
461
|
* @returns The request object, or `undefined` if not found
|
|
424
462
|
* @see https://docs.apify.com/api/v2/request-queue-request-get
|
|
425
463
|
*/
|
|
426
|
-
async getRequest(id) {
|
|
464
|
+
async getRequest(id, options = {}) {
|
|
427
465
|
parseArgument(id, requestIdSchema);
|
|
466
|
+
const { timeoutSecs } = parseArgument(options, timeoutOptionsSchema, 'TimeoutOptions');
|
|
428
467
|
const requestOpts = {
|
|
429
|
-
url: this.
|
|
468
|
+
url: this.buildUrl(['requests', id]),
|
|
430
469
|
method: 'GET',
|
|
431
|
-
|
|
432
|
-
params: this.
|
|
470
|
+
timeoutSecs: this.resolveTimeout(timeoutSecs, 'short'),
|
|
471
|
+
params: this.buildParams(),
|
|
433
472
|
};
|
|
434
473
|
try {
|
|
435
474
|
const response = await this.httpClient.call(requestOpts);
|
|
@@ -445,6 +484,8 @@ export class RequestQueueClient extends ResourceClient {
|
|
|
445
484
|
*
|
|
446
485
|
* @param request - The updated request object (must include id)
|
|
447
486
|
* @param options - Update options such as whether to move to front
|
|
487
|
+
* @param options.forefront - If `true`, moves the request to the beginning of the queue. Default is `false`.
|
|
488
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'medium'`.
|
|
448
489
|
* @returns Information about the updated request
|
|
449
490
|
* @see https://docs.apify.com/api/v2/request-queue-request-put
|
|
450
491
|
*/
|
|
@@ -452,11 +493,11 @@ export class RequestQueueClient extends ResourceClient {
|
|
|
452
493
|
parseArgument(request, existingRequestSchema);
|
|
453
494
|
const parsed = parseArgument(options, forefrontOptionsSchema, 'RequestQueueClientAddRequestOptions');
|
|
454
495
|
const response = await this.httpClient.call({
|
|
455
|
-
url: this.
|
|
496
|
+
url: this.buildUrl(['requests', request.id]),
|
|
456
497
|
method: 'PUT',
|
|
457
|
-
|
|
498
|
+
timeoutSecs: this.resolveTimeout(parsed.timeoutSecs, 'medium'),
|
|
458
499
|
data: request,
|
|
459
|
-
params: this.
|
|
500
|
+
params: this.buildParams({
|
|
460
501
|
forefront: parsed.forefront,
|
|
461
502
|
clientKey: this.clientKey,
|
|
462
503
|
}),
|
|
@@ -467,14 +508,17 @@ export class RequestQueueClient extends ResourceClient {
|
|
|
467
508
|
* Deletes a specific request from the queue.
|
|
468
509
|
*
|
|
469
510
|
* @param id - Request ID
|
|
511
|
+
* @param options - Request options
|
|
512
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'short'`.
|
|
470
513
|
*/
|
|
471
|
-
async deleteRequest(id) {
|
|
514
|
+
async deleteRequest(id, options = {}) {
|
|
472
515
|
parseArgument(id, requestIdSchema);
|
|
516
|
+
const { timeoutSecs } = parseArgument(options, timeoutOptionsSchema, 'TimeoutOptions');
|
|
473
517
|
await this.httpClient.call({
|
|
474
|
-
url: this.
|
|
518
|
+
url: this.buildUrl(['requests', id]),
|
|
475
519
|
method: 'DELETE',
|
|
476
|
-
|
|
477
|
-
params: this.
|
|
520
|
+
timeoutSecs: this.resolveTimeout(timeoutSecs, 'short'),
|
|
521
|
+
params: this.buildParams({
|
|
478
522
|
clientKey: this.clientKey,
|
|
479
523
|
}),
|
|
480
524
|
});
|
|
@@ -490,6 +534,7 @@ export class RequestQueueClient extends ResourceClient {
|
|
|
490
534
|
* @param options - Lock extension options
|
|
491
535
|
* @param options.lockSecs - **Required.** New lock duration in seconds from now.
|
|
492
536
|
* @param options.forefront - If `true`, moves the request to the beginning of the queue when the lock expires. Default is `false`.
|
|
537
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'medium'`.
|
|
493
538
|
* @returns Object with new `lockExpiresAt` timestamp
|
|
494
539
|
* @see https://docs.apify.com/api/v2/request-queue-request-lock-put
|
|
495
540
|
*
|
|
@@ -508,10 +553,10 @@ export class RequestQueueClient extends ResourceClient {
|
|
|
508
553
|
parseArgument(id, requestIdSchema);
|
|
509
554
|
const parsed = parseArgument(options, prolongRequestLockOptionsSchema, 'RequestQueueClientProlongRequestLockOptions');
|
|
510
555
|
const response = await this.httpClient.call({
|
|
511
|
-
url: this.
|
|
556
|
+
url: this.buildUrl(['requests', id, 'lock']),
|
|
512
557
|
method: 'PUT',
|
|
513
|
-
|
|
514
|
-
params: this.
|
|
558
|
+
timeoutSecs: this.resolveTimeout(parsed.timeoutSecs, 'medium'),
|
|
559
|
+
params: this.buildParams({
|
|
515
560
|
forefront: parsed.forefront,
|
|
516
561
|
lockSecs: parsed.lockSecs,
|
|
517
562
|
clientKey: this.clientKey,
|
|
@@ -527,6 +572,8 @@ export class RequestQueueClient extends ResourceClient {
|
|
|
527
572
|
*
|
|
528
573
|
* @param id - Request ID
|
|
529
574
|
* @param options - Options such as whether to move to front
|
|
575
|
+
* @param options.forefront - If `true`, moves the request to the beginning of the queue. Default is `false`.
|
|
576
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'short'`.
|
|
530
577
|
* @see https://docs.apify.com/api/v2/request-queue-request-lock-delete
|
|
531
578
|
* @since Added in 2.4.1
|
|
532
579
|
*/
|
|
@@ -534,10 +581,10 @@ export class RequestQueueClient extends ResourceClient {
|
|
|
534
581
|
parseArgument(id, requestIdSchema);
|
|
535
582
|
const parsed = parseArgument(options, forefrontOptionsSchema, 'RequestQueueClientDeleteRequestLockOptions');
|
|
536
583
|
await this.httpClient.call({
|
|
537
|
-
url: this.
|
|
584
|
+
url: this.buildUrl(['requests', id, 'lock']),
|
|
538
585
|
method: 'DELETE',
|
|
539
|
-
|
|
540
|
-
params: this.
|
|
586
|
+
timeoutSecs: this.resolveTimeout(parsed.timeoutSecs, 'short'),
|
|
587
|
+
params: this.buildParams({
|
|
541
588
|
forefront: parsed.forefront,
|
|
542
589
|
clientKey: this.clientKey,
|
|
543
590
|
}),
|
|
@@ -550,18 +597,21 @@ export class RequestQueueClient extends ResourceClient {
|
|
|
550
597
|
* queue contents.
|
|
551
598
|
*
|
|
552
599
|
* @param options - Pagination options
|
|
600
|
+
* @param options.timeoutSecs - Timeout for each API request. Default is `'medium'`.
|
|
553
601
|
* @returns List of requests with pagination information
|
|
554
602
|
* @see https://docs.apify.com/api/v2/request-queue-requests-get
|
|
555
603
|
* @since Added in 2.5.1
|
|
556
604
|
*/
|
|
557
605
|
listRequests(options = {}) {
|
|
558
|
-
|
|
606
|
+
// `timeoutSecs` times every page request; it is not an API parameter, so it must not reach the query string.
|
|
607
|
+
const { timeoutSecs, ...parsed } = parseArgument(options, listRequestsOptionsSchema, 'RequestQueueClientListRequestsOptions');
|
|
608
|
+
const pageTimeout = this.resolveTimeout(timeoutSecs, 'medium');
|
|
559
609
|
const getPaginatedList = async (rqListOptions = {}) => {
|
|
560
610
|
const response = await this.httpClient.call({
|
|
561
|
-
url: this.
|
|
611
|
+
url: this.buildUrl('requests'),
|
|
562
612
|
method: 'GET',
|
|
563
|
-
|
|
564
|
-
params: this.
|
|
613
|
+
timeoutSecs: pageTimeout,
|
|
614
|
+
params: this.buildParams({
|
|
565
615
|
...rqListOptions,
|
|
566
616
|
filter: rqListOptions.filter ? rqListOptions.filter.join(',') : undefined,
|
|
567
617
|
clientKey: this.clientKey,
|
|
@@ -602,16 +652,19 @@ export class RequestQueueClient extends ResourceClient {
|
|
|
602
652
|
* This is useful for releasing all locks at once, for example when shutting down
|
|
603
653
|
* a crawler gracefully.
|
|
604
654
|
*
|
|
655
|
+
* @param options - Request options
|
|
656
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'long'`.
|
|
605
657
|
* @returns Number of requests that were unlocked
|
|
606
658
|
* @see https://docs.apify.com/api/v2/request-queue-requests-unlock-post
|
|
607
659
|
* @since Added in 2.12.5
|
|
608
660
|
*/
|
|
609
|
-
async unlockRequests() {
|
|
661
|
+
async unlockRequests(options = {}) {
|
|
662
|
+
const { timeoutSecs } = parseArgument(options, timeoutOptionsSchema, 'TimeoutOptions');
|
|
610
663
|
const response = await this.httpClient.call({
|
|
611
|
-
url: this.
|
|
664
|
+
url: this.buildUrl('requests/unlock'),
|
|
612
665
|
method: 'POST',
|
|
613
|
-
|
|
614
|
-
params: this.
|
|
666
|
+
timeoutSecs: this.resolveTimeout(timeoutSecs, 'long'),
|
|
667
|
+
params: this.buildParams({
|
|
615
668
|
clientKey: this.clientKey,
|
|
616
669
|
}),
|
|
617
670
|
});
|
|
@@ -624,6 +677,7 @@ export class RequestQueueClient extends ResourceClient {
|
|
|
624
677
|
* automatically handling pagination behind the scenes.
|
|
625
678
|
*
|
|
626
679
|
* @param options - Pagination options
|
|
680
|
+
* @param options.timeoutSecs - Timeout for each API request. Default is `'medium'`.
|
|
627
681
|
* @returns An async iterable of request pages
|
|
628
682
|
* @see https://docs.apify.com/api/v2/request-queue-requests-get
|
|
629
683
|
*
|
|
@@ -636,9 +690,9 @@ export class RequestQueueClient extends ResourceClient {
|
|
|
636
690
|
* @since Added in 2.5.1
|
|
637
691
|
*/
|
|
638
692
|
paginateRequests(options = {}) {
|
|
639
|
-
const { limit, cursor, filter, maxPageLimit } = parseArgument(options, paginateRequestsOptionsSchema, 'RequestQueueClientPaginateRequestsOptions');
|
|
693
|
+
const { limit, cursor, filter, maxPageLimit, timeoutSecs } = parseArgument(options, paginateRequestsOptionsSchema, 'RequestQueueClientPaginateRequestsOptions');
|
|
640
694
|
return new RequestQueuePaginationIterator({
|
|
641
|
-
getPage: async (pageOptions) => this.listRequests({ ...pageOptions, filter }),
|
|
695
|
+
getPage: async (pageOptions) => this.listRequests({ ...pageOptions, filter, timeoutSecs }),
|
|
642
696
|
limit,
|
|
643
697
|
cursor,
|
|
644
698
|
maxPageLimit,
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { STORAGE_OWNERSHIP_FILTER } from '@apify/consts';
|
|
2
2
|
import type { ApiClientSubResourceOptions } from '../base/api_client.js';
|
|
3
3
|
import { ResourceCollectionClient } from '../base/resource_collection_client.js';
|
|
4
|
+
import type { TimeoutOptions } from '../timeouts.js';
|
|
4
5
|
import type { PaginatedList, PaginationOptions } from '../utils.js';
|
|
5
6
|
import type { RequestQueue } from './request_queue.js';
|
|
6
7
|
/**
|
|
@@ -45,6 +46,7 @@ export declare class RequestQueueCollectionClient extends ResourceCollectionClie
|
|
|
45
46
|
* ```
|
|
46
47
|
*
|
|
47
48
|
* @param options - Pagination options.
|
|
49
|
+
* @param options.timeoutSecs - Timeout for each API request. Default is `'medium'`.
|
|
48
50
|
* @returns A paginated iterator of Request queues.
|
|
49
51
|
* @see https://docs.apify.com/api/v2/request-queues-get
|
|
50
52
|
*/
|
|
@@ -53,12 +55,14 @@ export declare class RequestQueueCollectionClient extends ResourceCollectionClie
|
|
|
53
55
|
* Gets or creates a Request queue with the specified name.
|
|
54
56
|
*
|
|
55
57
|
* @param name - Name of the Request queue. If not provided, a default queue is used.
|
|
58
|
+
* @param options - Request options
|
|
59
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'short'`.
|
|
56
60
|
* @returns The Request queue object.
|
|
57
61
|
* @see https://docs.apify.com/api/v2/request-queues-post
|
|
58
62
|
*/
|
|
59
|
-
getOrCreate(name?: string): Promise<RequestQueue>;
|
|
63
|
+
getOrCreate(name?: string, options?: TimeoutOptions): Promise<RequestQueue>;
|
|
60
64
|
}
|
|
61
|
-
export interface RequestQueueCollectionListOptions extends PaginationOptions {
|
|
65
|
+
export interface RequestQueueCollectionListOptions extends PaginationOptions, TimeoutOptions {
|
|
62
66
|
unnamed?: boolean;
|
|
63
67
|
desc?: boolean;
|
|
64
68
|
/**
|
|
@@ -2,12 +2,14 @@ import { z } from 'zod';
|
|
|
2
2
|
import { STORAGE_OWNERSHIP_FILTER } from '@apify/consts';
|
|
3
3
|
import { ResourceCollectionClient } from '../base/resource_collection_client.js';
|
|
4
4
|
import * as schemas from '../schemas.js';
|
|
5
|
+
import { timeoutOptionsSchema, timeoutOptionsShape } from '../timeouts.js';
|
|
5
6
|
import { paginationOptionsShape, parseArgument } from '../utils.js';
|
|
6
7
|
const listOptionsSchema = z.strictObject({
|
|
7
8
|
unnamed: z.boolean().optional(),
|
|
8
9
|
...paginationOptionsShape,
|
|
9
10
|
desc: z.boolean().optional(),
|
|
10
11
|
ownership: z.enum(STORAGE_OWNERSHIP_FILTER).optional(),
|
|
12
|
+
...timeoutOptionsShape,
|
|
11
13
|
});
|
|
12
14
|
const nameSchema = z.string().optional();
|
|
13
15
|
/**
|
|
@@ -57,22 +59,26 @@ export class RequestQueueCollectionClient extends ResourceCollectionClient {
|
|
|
57
59
|
* ```
|
|
58
60
|
*
|
|
59
61
|
* @param options - Pagination options.
|
|
62
|
+
* @param options.timeoutSecs - Timeout for each API request. Default is `'medium'`.
|
|
60
63
|
* @returns A paginated iterator of Request queues.
|
|
61
64
|
* @see https://docs.apify.com/api/v2/request-queues-get
|
|
62
65
|
*/
|
|
63
66
|
list(options = {}) {
|
|
64
67
|
const parsed = parseArgument(options, listOptionsSchema, 'RequestQueueCollectionListOptions');
|
|
65
|
-
return this.
|
|
68
|
+
return this.listResourcesPaginated(schemas.ListOfRequestQueues(), parsed, 'medium');
|
|
66
69
|
}
|
|
67
70
|
/**
|
|
68
71
|
* Gets or creates a Request queue with the specified name.
|
|
69
72
|
*
|
|
70
73
|
* @param name - Name of the Request queue. If not provided, a default queue is used.
|
|
74
|
+
* @param options - Request options
|
|
75
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'short'`.
|
|
71
76
|
* @returns The Request queue object.
|
|
72
77
|
* @see https://docs.apify.com/api/v2/request-queues-post
|
|
73
78
|
*/
|
|
74
|
-
async getOrCreate(name) {
|
|
79
|
+
async getOrCreate(name, options = {}) {
|
|
75
80
|
parseArgument(name, nameSchema);
|
|
76
|
-
|
|
81
|
+
const { timeoutSecs = 'short' } = parseArgument(options, timeoutOptionsSchema, 'TimeoutOptions');
|
|
82
|
+
return this.getOrCreateResource(schemas.RequestQueue(), name, undefined, timeoutSecs);
|
|
77
83
|
}
|
|
78
84
|
}
|