From 2e9fe40583a3567d41d5951e8397ed92b85b7de0 Mon Sep 17 00:00:00 2001 From: Blayne Chard Date: Fri, 10 Jun 2022 15:22:42 +1200 Subject: [PATCH] fix(cli): give each internal job a fresh copy of all data Somethings modify the job.json so a fresh job.json should be loaded for each job --- packages/cli/src/cli/cogify/action.cog.ts | 97 +++++++++++++---------- 1 file changed, 54 insertions(+), 43 deletions(-) diff --git a/packages/cli/src/cli/cogify/action.cog.ts b/packages/cli/src/cli/cogify/action.cog.ts index 77284bc37..12e3f6f24 100644 --- a/packages/cli/src/cli/cogify/action.cog.ts +++ b/packages/cli/src/cli/cogify/action.cog.ts @@ -78,11 +78,11 @@ export class ActionCogCreate extends CommandLineAction { } async onExecute(): Promise { - const jobFn = this.job?.value; - if (jobFn == null) throw new Error('Missing job name'); + const jobLocation = this.job?.value; + if (jobLocation == null) throw new Error('Missing job name'); - const job = await CogStacJob.load(jobFn); const isCommit = this.commit?.value ?? false; + const job = await CogStacJob.load(jobLocation); const logger = LogConfig.get().child({ correlationId: job.id, @@ -103,46 +103,8 @@ export class ActionCogCreate extends CommandLineAction { try { for (const name of names) { - const tiffFolder = await makeTiffFolder(tmpFolder, name); - const targetPath = job.getJobPath(`${name}.tiff`); - fsa.configure(job.output.location); - - const outputExists = await fsa.exists(targetPath); - logger.info({ targetPath, outputExists }, 'CogCreate:CheckExists'); - // Output file exists don't try and overwrite it - if (outputExists) { - logger.warn({ targetPath }, 'CogCreate:OutputExists'); - await this.checkJobStatus(job, logger); - continue; - } - - let cutlineJson: FeatureCollection | undefined; - if (job.output.cutline != null) { - const cutlinePath = job.getJobPath('cutline.geojson.gz'); - logger.info({ path: cutlinePath }, 'CogCreate:UsingCutLine'); - cutlineJson = await Cutline.loadCutline(cutlinePath); - } else { - logger.warn('CutLine:Skip'); - } - const cutline = new Cutline(job.tileMatrix, cutlineJson, job.output.cutline?.blend, job.output.oneCogCovering); - - const tmpVrtPath = await CogVrt.buildVrt(tiffFolder, job, cutline, name, logger); - - if (tmpVrtPath == null) { - logger.warn({ name }, 'CogCreate:NoMatchingSourceImagery'); - return; - } - - const tmpTiff = fsa.join(tiffFolder, `${name}.tiff`); - - await buildCogForName(job, name, tmpVrtPath, tmpTiff, logger, isCommit); - logger.info({ target: targetPath }, 'CogCreate:StoreTiff'); - if (isCommit) { - await fsa.write(targetPath, createReadStream(tmpTiff)); - await this.checkJobStatus(job, logger); - } else { - logger.warn({ name }, 'DryRun:Done'); - } + const tiffJob = await CogStacJob.load(jobLocation); + await this.processTiff(tiffJob, name, tmpFolder, isCommit, logger.child({ tiffName: name })); } } catch (e) { const processingId = job.json.processingId; @@ -165,6 +127,55 @@ export class ActionCogCreate extends CommandLineAction { } } + async processTiff( + job: CogStacJob, + tiffName: string, + tmpFolder: string, + isCommit: boolean, + logger: LogType, + ): Promise { + const tiffFolder = await makeTiffFolder(tmpFolder, tiffName); + const targetPath = job.getJobPath(`${tiffName}.tiff`); + fsa.configure(job.output.location); + + const outputExists = await fsa.exists(targetPath); + logger.info({ targetPath, outputExists }, 'CogCreate:CheckExists'); + // Output file exists don't try and overwrite it + if (outputExists) { + logger.warn({ targetPath }, 'CogCreate:OutputExists'); + await this.checkJobStatus(job, logger); + return; + } + + let cutlineJson: FeatureCollection | undefined; + if (job.output.cutline != null) { + const cutlinePath = job.getJobPath('cutline.geojson.gz'); + logger.info({ path: cutlinePath }, 'CogCreate:UsingCutLine'); + cutlineJson = await Cutline.loadCutline(cutlinePath); + } else { + logger.warn('CutLine:Skip'); + } + const cutline = new Cutline(job.tileMatrix, cutlineJson, job.output.cutline?.blend, job.output.oneCogCovering); + + const tmpVrtPath = await CogVrt.buildVrt(tiffFolder, job, cutline, tiffName, logger); + + if (tmpVrtPath == null) { + logger.warn('CogCreate:NoMatchingSourceImagery'); + return; + } + + const tmpTiff = fsa.join(tiffFolder, `${tiffName}.tiff`); + + await buildCogForName(job, tiffName, tmpVrtPath, tmpTiff, logger, isCommit); + logger.info({ target: targetPath }, 'CogCreate:StoreTiff'); + if (isCommit) { + await fsa.write(targetPath, createReadStream(tmpTiff)); + await this.checkJobStatus(job, logger); + } else { + logger.warn('DryRun:Done'); + } + } + /** Check to see how many tiffs are remaining in the job */ async checkJobStatus(job: CogStacJob, logger: LogType): Promise { const basePath = job.getJobPath();