Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(gatsby-source-drupal): Add timeout in case of stalled API requests #33668

Merged
merged 3 commits into from
Oct 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/gatsby-source-drupal/README.md
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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) })
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also fix the timestamp creation as JS uses milliseconds and PHP uses seconds.

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
Original file line number Diff line number Diff line change
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