Skip to content

Commit 4f4d2d7

Browse files
feat(gatsby-source-drupal): Allow sites to configure the request timeout (#35794) (#35820)
* feat(gatsby-source-drupal): Allow sites to configure the request timeout * Inject timeout in every call (cherry picked from commit 8166d4a) Co-authored-by: Kyle Mathews <[email protected]>
1 parent 2652fa8 commit 4f4d2d7

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

packages/gatsby-source-drupal/README.md

+6
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,12 @@ module.exports = {
307307

308308
You can use the `concurrentAPIRequests` option to change how many simultaneous API requests are made to the server/service. 20 is the default and seems to be the fastest for most sites.
309309

310+
## API Request Timeout
311+
312+
You can use the `requestTimeoutMS` option to set the request timeout for API requests. API requests sometimes stall and we want to retry these instead of endlessly waiting.
313+
314+
The default is 30000ms. Very large sites might need to increase this.
315+
310316
## Disallowed Link Types
311317

312318
You can use the `disallowedLinkTypes` option to skip link types found in JSON:API documents. By default it skips the `self`, `describedby`, `contact_message--feedback`, and `contact_message--pesonal` links, which do not provide data that can be sourced. You may override the setting to add additional link types to be skipped.

packages/gatsby-source-drupal/src/gatsby-node.js

+14-5
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,6 @@ async function worker([url, options]) {
9292
const response = await got(url, {
9393
agent,
9494
cache: false,
95-
timeout: {
96-
// Occasionally requests to Drupal stall. Set a 30s timeout to retry in this case.
97-
request: 30000,
98-
},
9995
// request: http2wrapper.auto,
10096
// http2: true,
10197
...options,
@@ -166,6 +162,7 @@ exports.sourceNodes = async (
166162
params = {},
167163
concurrentFileRequests = 20,
168164
concurrentAPIRequests = 20,
165+
requestTimeoutMS,
169166
disallowedLinkTypes = [
170167
`self`,
171168
`describedby`,
@@ -188,7 +185,6 @@ exports.sourceNodes = async (
188185
touchNode,
189186
unstable_createNodeManifest,
190187
} = actions
191-
192188
// Update the concurrency limit from the plugin options
193189
requestQueue.concurrency = concurrentAPIRequests
194190

@@ -329,6 +325,10 @@ ${JSON.stringify(webhookBody, null, 4)}`
329325
searchParams: params,
330326
responseType: `json`,
331327
parentSpan: fastBuildsSpan,
328+
timeout: {
329+
// Occasionally requests to Drupal stall. Set a (default) 30s timeout to retry in this case.
330+
request: requestTimeoutMS,
331+
},
332332
},
333333
])
334334

@@ -487,6 +487,10 @@ ${JSON.stringify(webhookBody, null, 4)}`
487487
searchParams: params,
488488
responseType: `json`,
489489
parentSpan: fullFetchSpan,
490+
timeout: {
491+
// Occasionally requests to Drupal stall. Set a (default) 30s timeout to retry in this case.
492+
request: requestTimeoutMS,
493+
},
490494
},
491495
])
492496
allData = await Promise.all(
@@ -537,6 +541,10 @@ ${JSON.stringify(webhookBody, null, 4)}`
537541
searchParams: params,
538542
responseType: `json`,
539543
parentSpan: fullFetchSpan,
544+
timeout: {
545+
// Occasionally requests to Drupal stall. Set a (default) 30s timeout to retry in this case.
546+
request: requestTimeoutMS,
547+
},
540548
},
541549
])
542550
} catch (error) {
@@ -837,6 +845,7 @@ exports.pluginOptionsSchema = ({ Joi }) =>
837845
params: Joi.object().description(`Append optional GET params to requests`),
838846
concurrentFileRequests: Joi.number().integer().default(20).min(1),
839847
concurrentAPIRequests: Joi.number().integer().default(20).min(1),
848+
requestTimeoutMS: Joi.number().integer().default(30000).min(1),
840849
disallowedLinkTypes: Joi.array().items(Joi.string()),
841850
skipFileDownloads: Joi.boolean(),
842851
fastBuilds: Joi.boolean(),

0 commit comments

Comments
 (0)