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(cli): give each internal job a fresh copy of all data #2250

Merged
merged 1 commit into from
Jun 14, 2022
Merged
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
97 changes: 54 additions & 43 deletions packages/cli/src/cli/cogify/action.cog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,11 @@ export class ActionCogCreate extends CommandLineAction {
}

async onExecute(): Promise<void> {
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,
Expand All @@ -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;
Expand All @@ -165,6 +127,55 @@ export class ActionCogCreate extends CommandLineAction {
}
}

async processTiff(
job: CogStacJob,
tiffName: string,
tmpFolder: string,
isCommit: boolean,
logger: LogType,
): Promise<void> {
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<void> {
const basePath = job.getJobPath();
Expand Down