Skip to content

Commit

Permalink
fix(gatsby-source-drupal): Add timeout in case of stalled API requests (
Browse files Browse the repository at this point in the history
#33668) (#33705)

* feat(gatsby-source-drupal): More ports from customer fixes

* cleanups

(cherry picked from commit 113ae43)

Co-authored-by: Kyle Mathews <mathews.kyle@gmail.com>
  • Loading branch information
GatsbyJS Bot and KyleAMathews committed Oct 28, 2021
1 parent 857a628 commit 4722a0d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
2 changes: 1 addition & 1 deletion packages/gatsby-source-drupal/README.md
Expand Up @@ -2,7 +2,7 @@

Source plugin for pulling data (including images) into Gatsby from Drupal sites.

Pulls data from Drupal 8 sites with the
It pulls data from Drupal 8 sites with the
[Drupal JSONAPI module](https://www.drupal.org/project/jsonapi) installed.

An example site built with the headless Drupal distro
Expand Down
12 changes: 10 additions & 2 deletions packages/gatsby-source-drupal/src/gatsby-node.js
Expand Up @@ -64,6 +64,10 @@ async function worker([url, options]) {
const response = await got(url, {
agent,
cache: false,
timeout: {
// Occasionally requests to Drupal stall. Set a 15s timeout to retry in this case.
request: 15000,
},
// request: http2wrapper.auto,
// http2: true,
...options,
Expand Down Expand Up @@ -259,7 +263,7 @@ ${JSON.stringify(webhookBody, null, 4)}`

// lastFetched isn't set so do a full rebuild.
if (!lastFetched) {
setPluginStatus({ lastFetched: new Date().getTime() })
setPluginStatus({ lastFetched: Math.floor(new Date().getTime() / 1000) })
requireFullRebuild = true
} else {
const drupalFetchIncrementalActivity = reporter.activityTimer(
Expand All @@ -272,7 +276,11 @@ ${JSON.stringify(webhookBody, null, 4)}`
try {
// Hit fastbuilds endpoint with the lastFetched date.
const res = await requestQueue.push([
urlJoin(baseUrl, `gatsby-fastbuilds/sync/`, lastFetched.toString()),
urlJoin(
baseUrl,
`gatsby-fastbuilds/sync/`,
Math.floor(lastFetched).toString()
),
{
username: basicAuth.username,
password: basicAuth.password,
Expand Down
2 changes: 1 addition & 1 deletion packages/gatsby-source-drupal/src/utils.js
Expand Up @@ -364,7 +364,7 @@ ${JSON.stringify(nodeToUpdate, null, 4)}
node.internal.contentDigest = createContentDigest(node)
createNode(node)
reporter.log(
`Updated Gatsby node: id: ${node.id} type: ${node.internal.type}`
`Updated Gatsby nodeid: ${node.id} type: ${node.internal.type}`
)
}
}
Expand Down

0 comments on commit 4722a0d

Please sign in to comment.