Skip to content

Commit

Permalink
add pMap
Browse files Browse the repository at this point in the history
  • Loading branch information
Marigold committed Feb 19, 2024
1 parent caf932c commit 2ee009e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
9 changes: 6 additions & 3 deletions baker/GrapherBaker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ import { parseFaqs } from "../db/model/Gdoc/rawToEnriched.js"
import { GdocPost } from "../db/model/Gdoc/GdocPost.js"
import { getShortPageCitation } from "../site/gdocs/utils.js"
import { getSlugForTopicTag, getTagToSlugMap } from "./GrapherBakingUtils.js"
import pMap from "p-map"

const renderDatapageIfApplicable = async (
grapher: GrapherInterface,
Expand Down Expand Up @@ -491,11 +492,13 @@ export const bakeAllChangedGrapherPagesVariablesPngSvgAndDeleteRemovedGraphers =
}
)

await Promise.all(
jobs.map(async (job) => {
await pMap(
jobs,
async (job) => {
await bakeSingleGrapherChart(job)
progressBar.tick({ name: `slug ${job.slug}` })
})
},
{ concurrency: 20 }
)

await deleteOldGraphers(bakedSiteDir, excludeUndefined(newSlugs))
Expand Down
8 changes: 4 additions & 4 deletions db/model/Variable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -415,10 +415,10 @@ export const fetchS3DataValuesByPath = async (
const resp = await retryPromise(
() =>
fetch(dataPath, { keepalive: true }).then((response) => {
if (!resp.ok) {
if (!response.ok) {
// Trigger retry
throw new Error(
`Error fetching data from S3 for ${dataPath}: ${resp.status} ${resp.statusText}`
`Error fetching data from S3 for ${dataPath}: ${response.status} ${response.statusText}`
)
}
return response
Expand Down Expand Up @@ -448,10 +448,10 @@ export const fetchS3MetadataByPath = async (
const resp = await retryPromise(
() =>
fetch(metadataPath, { keepalive: true }).then((response) => {
if (!resp.ok) {
if (!response.ok) {
// Trigger retry
throw new Error(
`Error fetching metadata from S3 for ${metadataPath}: ${resp.status} ${resp.statusText}`
`Error fetching metadata from S3 for ${metadataPath}: ${response.status} ${response.statusText}`
)
}
return response
Expand Down

0 comments on commit 2ee009e

Please sign in to comment.