Skip to content

Commit

Permalink
fix(gatsby-plugin-sharp): Set a unique uuid for each job (#17693)
Browse files Browse the repository at this point in the history
  • Loading branch information
sidharthachatterjee authored and GatsbyJS Bot committed Sep 17, 2019
1 parent 4e67a30 commit 0926c73
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 10 deletions.
3 changes: 2 additions & 1 deletion packages/gatsby-plugin-sharp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
"progress": "^2.0.3",
"semver": "^5.7.1",
"sharp": "^0.23.0",
"svgo": "^1.3.0"
"svgo": "^1.3.0",
"uuid": "^3.3.3"
},
"devDependencies": {
"@babel/cli": "^7.6.0",
Expand Down
16 changes: 9 additions & 7 deletions packages/gatsby-plugin-sharp/src/scheduler.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const _ = require(`lodash`)
const { existsSync } = require(`fs`)
const uuidv4 = require(`uuid/v4`)
const queue = require(`async/queue`)
const { processFile } = require(`./process-file`)
const { createProgress } = require(`./utils`)
Expand Down Expand Up @@ -66,16 +67,19 @@ exports.scheduleJob = async (

if (!isQueued) {
// Create image job
const jobId = uuidv4()
boundActionCreators.createJob(
{
id: `processing image ${job.inputPath}`,
id: jobId,
description: `processing image ${job.inputPath}`,
imagesCount: 1,
},
{ name: `gatsby-plugin-sharp` }
)

q.push(cb => {
runJobs(
jobId,
inputFileKey,
boundActionCreators,
pluginOptions,
Expand All @@ -89,6 +93,7 @@ exports.scheduleJob = async (
}

function runJobs(
jobId,
inputFileKey,
boundActionCreators,
pluginOptions,
Expand All @@ -105,7 +110,7 @@ function runJobs(
// Update job info
boundActionCreators.setJob(
{
id: `processing image ${job.inputPath}`,
id: jobId,
imagesCount: jobs.length,
},
{ name: `gatsby-plugin-sharp` }
Expand Down Expand Up @@ -143,7 +148,7 @@ function runJobs(

boundActionCreators.setJob(
{
id: `processing image ${job.inputPath}`,
id: jobId,
imagesFinished,
},
{ name: `gatsby-plugin-sharp` }
Expand All @@ -152,10 +157,7 @@ function runJobs(
)

Promise.all(promises).then(() => {
boundActionCreators.endJob(
{ id: `processing image ${job.inputPath}` },
{ name: `gatsby-plugin-sharp` }
)
boundActionCreators.endJob({ id: jobId }, { name: `gatsby-plugin-sharp` })
cb()
})
} catch (err) {
Expand Down
30 changes: 28 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -11065,7 +11065,7 @@ is-text-path@^2.0.0:
dependencies:
text-extensions "^2.0.0"

is-typedarray@~1.0.0:
is-typedarray@^1.0.0, is-typedarray@~1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/is-typedarray/-/is-typedarray-1.0.0.tgz#e479c80858df0c1b11ddda6940f96011fcda4a9a"

Expand Down Expand Up @@ -19111,6 +19111,13 @@ type-of@^2.0.1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/type-of/-/type-of-2.0.1.tgz#e72a1741896568e9f628378d816d6912f7f23972"

typedarray-to-buffer@^3.1.5:
version "3.1.5"
resolved "https://registry.yarnpkg.com/typedarray-to-buffer/-/typedarray-to-buffer-3.1.5.tgz#a97ee7a9ff42691b9f783ff1bc5112fe3fca9080"
integrity sha512-zdu8XMNEDepKKR+XYOXAVPtWui0ly0NtohUscw+UmaHiAWT8hrV1rr//H6V+0DvJ3OQ19S979M0laLfX8rm82Q==
dependencies:
is-typedarray "^1.0.0"

typedarray@^0.0.6, typedarray@~0.0.5:
version "0.0.6"
resolved "https://registry.yarnpkg.com/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777"
Expand Down Expand Up @@ -20439,7 +20446,7 @@ wrappy@1:
version "1.0.2"
resolved "https://registry.yarnpkg.com/wrappy/-/wrappy-1.0.2.tgz#b5243d8f3ec1aa35f1364605bc0d1036e30ab69f"

write-file-atomic@2.4.1, write-file-atomic@^2.0.0, write-file-atomic@^2.3.0, write-file-atomic@^2.4.2, write-file-atomic@^3.0.0:
write-file-atomic@2.4.1, write-file-atomic@^2.0.0, write-file-atomic@^2.3.0:
version "2.4.1"
resolved "https://registry.yarnpkg.com/write-file-atomic/-/write-file-atomic-2.4.1.tgz#d0b05463c188ae804396fd5ab2a370062af87529"
integrity sha512-TGHFeZEZMnv+gBFRfjAcxL5bPHrsGKtnb4qsFAws7/vlh+QfwAaySIw4AXP9ZskTTh5GWu3FLuJhsWVdiJPGvg==
Expand All @@ -20448,6 +20455,25 @@ write-file-atomic@2.4.1, write-file-atomic@^2.0.0, write-file-atomic@^2.3.0, wri
imurmurhash "^0.1.4"
signal-exit "^3.0.2"

write-file-atomic@^2.4.2:
version "2.4.3"
resolved "https://registry.yarnpkg.com/write-file-atomic/-/write-file-atomic-2.4.3.tgz#1fd2e9ae1df3e75b8d8c367443c692d4ca81f481"
integrity sha512-GaETH5wwsX+GcnzhPgKcKjJ6M2Cq3/iZp1WyY/X1CSqrW+jVNM9Y7D8EC2sM4ZG/V8wZlSniJnCKWPmBYAucRQ==
dependencies:
graceful-fs "^4.1.11"
imurmurhash "^0.1.4"
signal-exit "^3.0.2"

write-file-atomic@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/write-file-atomic/-/write-file-atomic-3.0.0.tgz#1b64dbbf77cb58fd09056963d63e62667ab4fb21"
integrity sha512-EIgkf60l2oWsffja2Sf2AL384dx328c0B+cIYPTQq5q2rOYuDV00/iPFBOUiDKKwKMOhkymH8AidPaRvzfxY+Q==
dependencies:
imurmurhash "^0.1.4"
is-typedarray "^1.0.0"
signal-exit "^3.0.2"
typedarray-to-buffer "^3.1.5"

write-file-stdout@0.0.2:
version "0.0.2"
resolved "https://registry.yarnpkg.com/write-file-stdout/-/write-file-stdout-0.0.2.tgz#c252d7c7c5b1b402897630e3453c7bfe690d9ca1"
Expand Down

0 comments on commit 0926c73

Please sign in to comment.