apify-client 3.0.0-beta.51 → 3.0.0-beta.52
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/base/resource_client.js +13 -7
- package/dist/bundle.js +2 -2
- package/dist/bundle.js.map +1 -1
- package/dist/resource_clients/build.d.ts +1 -0
- package/dist/resource_clients/build.js +1 -0
- package/dist/resource_clients/run.d.ts +1 -0
- package/dist/resource_clients/run.js +1 -0
- package/package.json +1 -1
|
@@ -9,6 +9,8 @@ import { ApiClient } from './api_client.js';
|
|
|
9
9
|
const MAX_WAIT_FOR_FINISH = 999999;
|
|
10
10
|
/** The API holds a `waitForFinish` response for at most a minute, however long the parameter asks for. */
|
|
11
11
|
const MAX_WAIT_FOR_FINISH_HOLD_SECS = 60;
|
|
12
|
+
/** How long `waitForFinish()` keeps polling a job that returns 404, to ride out replica lag, before it gives up. */
|
|
13
|
+
const MAX_WAIT_WHEN_JOB_NOT_EXIST_MILLIS = 3000;
|
|
12
14
|
/**
|
|
13
15
|
* Resource client.
|
|
14
16
|
* @private
|
|
@@ -88,10 +90,14 @@ export class ResourceClient extends ApiClient {
|
|
|
88
90
|
const { waitSecs = MAX_WAIT_FOR_FINISH, timeoutSecs = 'noTimeout', signal } = options;
|
|
89
91
|
const waitMillis = waitSecs * 1000;
|
|
90
92
|
let job;
|
|
93
|
+
let notFoundSince;
|
|
94
|
+
let notFoundError;
|
|
91
95
|
const startedAt = Date.now();
|
|
92
96
|
const shouldRepeat = () => {
|
|
93
|
-
const
|
|
94
|
-
if (
|
|
97
|
+
const now = Date.now();
|
|
98
|
+
if (now - startedAt >= waitMillis)
|
|
99
|
+
return false;
|
|
100
|
+
if (notFoundSince !== undefined && now - notFoundSince >= MAX_WAIT_WHEN_JOB_NOT_EXIST_MILLIS)
|
|
95
101
|
return false;
|
|
96
102
|
const hasJobEnded = job && ACT_JOB_TERMINAL_STATUSES.includes(job.status);
|
|
97
103
|
return !hasJobEnded;
|
|
@@ -110,10 +116,13 @@ export class ResourceClient extends ApiClient {
|
|
|
110
116
|
try {
|
|
111
117
|
const response = await this.httpClient.call(requestOpts);
|
|
112
118
|
job = parseResponse(response, schema);
|
|
119
|
+
notFoundSince = undefined;
|
|
113
120
|
}
|
|
114
121
|
catch (err) {
|
|
115
122
|
catchNotFoundOrThrow(err);
|
|
116
123
|
job = undefined;
|
|
124
|
+
notFoundSince ??= Date.now();
|
|
125
|
+
notFoundError = err;
|
|
117
126
|
}
|
|
118
127
|
// It might take some time for database replicas to get up-to-date,
|
|
119
128
|
// so getRun() might return null. Wait a little bit and try it again.
|
|
@@ -122,11 +131,8 @@ export class ResourceClient extends ApiClient {
|
|
|
122
131
|
signal?.throwIfAborted();
|
|
123
132
|
}
|
|
124
133
|
} while (shouldRepeat());
|
|
125
|
-
if (!job)
|
|
126
|
-
|
|
127
|
-
const jobName = constructorName.match(/(\w+)Client/)[1].toLowerCase();
|
|
128
|
-
throw new Error(`Waiting for ${jobName} to finish failed. Cannot fetch actor ${jobName} details from the server.`);
|
|
129
|
-
}
|
|
134
|
+
if (!job)
|
|
135
|
+
throw notFoundError;
|
|
130
136
|
return job;
|
|
131
137
|
}
|
|
132
138
|
}
|