Admin: Added retry logic, fixed version exports and removed unnecessary logging.

This commit is contained in:
Richard Moore 2020-10-07 00:11:47 -04:00
parent e65fa8fc00
commit df21d5326a
No known key found for this signature in database
GPG Key ID: 665176BE8E9DC651
6 changed files with 54 additions and 9 deletions

@ -56,7 +56,7 @@ const utils_1 = require("../utils");
latestVersions[pLocal.name] = version;
// Write out the _version.ts
if (!pLocal._ethers_nobuild) {
const code = "export const version = " + JSON.stringify(dirname + "/" + pLocal.version) + ";\n";
const code = "export const version = " + JSON.stringify(dirname + "/" + version) + ";\n";
fs_1.default.writeFileSync(path_1.resolve(path_1.getPackagePath(dirname), "src.ts/_version.ts"), code);
}
}

@ -176,14 +176,13 @@ exports.invalidate = invalidate;
];
for (let i = 0; i < fileInfos.length; i++) {
const { filename, key } = fileInfos[i];
const status = yield putObject(s3, {
yield putObject(s3, {
ACL: "public-read",
Body: fs_1.default.readFileSync(path_1.resolve(filename)),
Bucket: bucketName,
ContentType: "application/javascript; charset=utf-8",
Key: (originRoot + key)
});
console.log(status);
console.log(`${log_1.colorify.bold("Uploaded:")} https://cdn.ethers.io/lib/${key}`);
}
}

@ -60,7 +60,13 @@ function nonnull(value) {
}
return value;
}
function getUrl(href, options) {
function staller(duration) {
return new Promise((resolve) => {
const timer = setTimeout(resolve, duration);
timer.unref();
});
}
function _getUrl(href, options) {
return __awaiter(this, void 0, void 0, function* () {
if (options == null) {
options = {};
@ -100,4 +106,23 @@ function getUrl(href, options) {
return response;
});
}
function getUrl(href, options) {
return __awaiter(this, void 0, void 0, function* () {
let error = null;
for (let i = 0; i < 3; i++) {
try {
const result = yield Promise.race([
_getUrl(href, options),
staller(30000).then((result) => { throw new Error("timeout"); })
]);
return result;
}
catch (e) {
error = e;
}
yield staller(1000);
}
throw error;
});
}
exports.getUrl = getUrl;

@ -50,7 +50,7 @@ import { loadJson, repeat, saveJson } from "../utils";
// Write out the _version.ts
if (!pLocal._ethers_nobuild) {
const code = "export const version = " + JSON.stringify(dirname + "/" + pLocal.version) + ";\n";
const code = "export const version = " + JSON.stringify(dirname + "/" + version) + ";\n";
fs.writeFileSync(resolve(getPackagePath(dirname), "src.ts/_version.ts"), code);
}
}

@ -184,15 +184,13 @@ export function invalidate(cloudfront: AWS.CloudFront, distributionId: string):
for (let i = 0; i < fileInfos.length; i++) {
const { filename, key } = fileInfos[i];
const status = await putObject(s3, {
await putObject(s3, {
ACL: "public-read",
Body: fs.readFileSync(resolve(filename)),
Bucket: bucketName,
ContentType: "application/javascript; charset=utf-8",
Key: (originRoot + key)
});
console.log(status);
console.log(`${ colorify.bold("Uploaded:") } https://cdn.ethers.io/lib/${ key }`);
}
}

@ -68,7 +68,14 @@ function nonnull(value: string): string {
return value;
}
export async function getUrl(href: string, options?: Options): Promise<GetUrlResponse> {
function staller(duration: number): Promise<void> {
return new Promise((resolve) => {
const timer = setTimeout(resolve, duration);
timer.unref();
});
}
async function _getUrl(href: string, options?: Options): Promise<GetUrlResponse> {
if (options == null) { options = { }; }
// @TODO: Once we drop support for node 8, we can pass the href
@ -112,3 +119,19 @@ export async function getUrl(href: string, options?: Options): Promise<GetUrlRes
return response;
}
export async function getUrl(href: string, options?: Options): Promise<GetUrlResponse> {
let error: Error = null;
for (let i = 0; i < 3; i++) {
try {
const result = await Promise.race([
_getUrl(href, options),
staller(30000).then((result) => { throw new Error("timeout") })
]);
return result;
} catch (e) {
error = e;
}
await staller(1000);
}
throw error;
}