Interactive interface for browsing global, full-resolution satellite imagery
Add better retry to getVisMetadata fetching
ZachTRiced7936f28c04b
diff --git a/tasks/build-options/extractConfigFromWMTS.js b/tasks/build-options/extractConfigFromWMTS.jsindex 803fef326..660b79ac2 100644--- a/tasks/build-options/extractConfigFromWMTS.js+++ b/tasks/build-options/extractConfigFromWMTS.js@@ -118,10 +118,10 @@ async function processEntry (entry) {gc = JSON.parse(convert.xml2json(xml, { compact: true, spaces: 2 }))} catch (e) {if (tolerant) {- process.stderr.write(`${prog}: WARN: [${inputFile}] Unable to get GC: ${e}\n`)+ console.warn(`${prog}: WARN: [${inputFile}] Unable to get GC: ${e}\n`)warningCount += 1} else {- process.stderr.write(`${prog}: ERROR: [${inputFile}] Unable to get GC: ${e}\n`)+ console.error(`${prog}: ERROR: [${inputFile}] Unable to get GC: ${e}\n`)errorCount += 1}return { errorCount, warningCount, layerCount }@@ -132,27 +132,10 @@ async function processEntry (entry) {if (!gcContents || !gcContents.Layer) {errorCount += 1- process.stderr.write(`${prog}: ERROR: [${gcId}] No layers\n`)+ console.error(`${prog}: ERROR: [${gcId}] No layers\n`)return { errorCount, warningCount, layerCount }}- // if (typeof gc.Capabilities.Contents.Layer === 'object') {- // const gcLayer = gc.Capabilities.Contents.Layer- // const ident = gcLayer['ows:Identifier']- // try {- // layerCount += 1- // processLayer(gcLayer, wvLayers, entry)- // } catch (error) {- // if (error instanceof SkipException) {- // warningCount += 1- // process.stderr.write(`${prog}: WARNING: [${ident}] Skipping\n`)- // } else {- // errorCount += 1- // console.error(error.stack)- // process.stderr.write(`${prog}: ERROR: [${gcId}:${ident}] ${e}\n`)- // }- // }- // } else {for (const gcLayer of gcContents.Layer) {try {layerCount += 1@@ -160,15 +143,14 @@ async function processEntry (entry) {} catch (error) {if (error instanceof SkipException) {warningCount += 1- process.stderr.write(`${prog}: WARNING: [${id}] Skipping\n`)+ console.warn(`${prog}: WARNING: [${id}] Skipping\n`)} else {errorCount += 1console.error(error.stack)- process.stderr.write(`${prog}: ERROR: [${gcId}:${ident}] ${e}\n`)+ console.error(`${prog}: ERROR: [${gcId}:${ident}] ${e}\n`)}}}- // }if (gcContents.TileMatrixSet === 'Object') {processMatrixSet(gcContents.TileMatrixSet)diff --git a/tasks/build-options/getVisMetadata.js b/tasks/build-options/getVisMetadata.jsindex af918fde4..6c2433138 100644--- a/tasks/build-options/getVisMetadata.js+++ b/tasks/build-options/getVisMetadata.js@@ -2,7 +2,7 @@ const fs = require('fs')const path = require('path')const yargs = require('yargs')const console = require('console')-const request = require('axios').default+const axios = require('axios').defaultconst prog = path.basename(__filename)@@ -121,31 +121,33 @@ async function getDAAC (metadata) {return metadata}-async function getMetadata (layerId, baseUrl) {- let errorCount = 0- try {- return request({- method: 'get',- url: `${baseUrl}${layerId}.json`,- responseType: 'json',- timeout: 10000- }).then(async (response) => {- metadata = response.data- layerMetadata[layerId] = await getDAAC(metadata)- metadataKeys = Object.keys(layerMetadata[layerId])- metadataKeys = metadataKeys.filter(x => !useKeys.includes(x))- for (key of metadataKeys) {- delete layerMetadata[layerId][key]- }- })- } catch (error) {- errorCount += 1- if (errorCount <= 2) {- console.warn(`${prog}: WARNING: Failed to retrieve metadata config for ${layerId}, will retry...`)- await getMetadata(layerId, baseUrl)- } else {- throw new Error(`{prog}: Error: Failed to retrieve metadata config for ${layerId}`)+async function getMetadata (layerId, baseUrl, count) {+ if (count) console.warn(`retry #${count} for ${layerId}`)+ return axios({+ method: 'get',+ url: `${baseUrl}${layerId}.json`,+ responseType: 'json',+ timeout: 10000+ }).then(async (response) => {+ metadata = response.data+ layerMetadata[layerId] = await getDAAC(metadata)+ metadataKeys = Object.keys(layerMetadata[layerId])+ metadataKeys = metadataKeys.filter(x => !useKeys.includes(x))+ for (key of metadataKeys) {+ delete layerMetadata[layerId][key]}+ }).catch((error) => {+ handleException(error, layerId, url, count)+ })+}++async function handleException (error, layerId, url, count) {+ if (!count) count = 0+ count+++ if (count <= 5) {+ await getMetadata(layerId, url, count)+ } else {+ console.warn(`\n ${prog} WARN: Unable to fetch ${layerId} ${error}`)}}