-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #878 from chromaui/ghengeveld/ap-3912-index-update…
…-cli-to-wait-for-copy-job-using-sentinel-file Retrieve `sentinelUrls` from `uploadBuild` and wait for all of them before finishing upload task
- Loading branch information
Showing
15 changed files
with
237 additions
and
141 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { ReadStream, createReadStream } from 'fs'; | ||
|
||
export class FileReaderBlob { | ||
readStream: ReadStream; | ||
size: number; | ||
|
||
constructor(filePath: string, contentLength: number, onProgress: (delta: number) => void) { | ||
this.size = contentLength; | ||
this.readStream = createReadStream(filePath); | ||
this.readStream.on('data', (chunk: Buffer | string) => onProgress(chunk.length)); | ||
} | ||
|
||
stream() { | ||
return this.readStream; | ||
} | ||
|
||
get [Symbol.toStringTag]() { | ||
return 'Blob'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import retry from 'async-retry'; | ||
import { Response } from 'node-fetch'; | ||
import { Context } from '../types'; | ||
|
||
// A sentinel file is created by a zip-unpack lambda within the Chromatic infrastructure once the | ||
// uploaded zip is fully extracted. The contents of this file will consist of 'OK' if the process | ||
// completed successfully and 'ERROR' if an error occurred. | ||
const SENTINEL_SUCCESS_VALUE = 'OK'; | ||
|
||
export async function waitForSentinel(ctx: Context, url: string) { | ||
const { experimental_abortSignal: signal } = ctx.options; | ||
|
||
ctx.log.debug(`Waiting for sentinel file to appear at ${url}`); | ||
|
||
return retry( | ||
async (bail) => { | ||
if (signal?.aborted) { | ||
return bail(signal.reason || new Error('Aborted')); | ||
} | ||
|
||
let res: Response; | ||
try { | ||
res = await ctx.http.fetch(url, { signal }, { retries: 0, noLogErrorBody: true }); | ||
} catch (e) { | ||
const { response = {} } = e; | ||
if (response.status === 403) { | ||
return bail(new Error('Provided signature expired.')); | ||
} | ||
throw new Error('Sentinel file not present.'); | ||
} | ||
|
||
const result = await res.text(); | ||
if (result !== SENTINEL_SUCCESS_VALUE) { | ||
ctx.log.debug(`Sentinel file not OK, got ${result}`); | ||
return bail(new Error('Sentinel file error.')); | ||
} | ||
ctx.log.debug(`Sentinel file OK.`); | ||
}, | ||
{ | ||
retries: 185, // 3 minutes and some change (matches the lambda timeout with some extra buffer) | ||
minTimeout: 1000, | ||
maxTimeout: 1000, | ||
} | ||
); | ||
} |
Oops, something went wrong.