Skip to content

Commit

Permalink
Exit with an error code if uploading fails
Browse files Browse the repository at this point in the history
Also
* try to upload the failed assets once
* generalize task names, i.e. remove travis from names
* upgrade dependencies

This fixes #75.
  • Loading branch information
stigkj committed Mar 4, 2022
1 parent ffcfc57 commit 060f462
Show file tree
Hide file tree
Showing 5 changed files with 379 additions and 373 deletions.
6 changes: 4 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,10 @@ if (options.dryRun) {
}

if (Array.isArray(errors) && errors.length > 0) {
console.log('\n---Failing assets---');
errors.forEach(e => console.log(`${e.item.path}: ${e.message}`));
console.error('\n---Failing assets---');
errors.forEach(error => console.error(`${error.item.path}: ${error.message}`));

process.exit(1);
}
}
);
Expand Down
23 changes: 19 additions & 4 deletions lib/uploader.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { Storage } = require('@google-cloud/storage');
const PromisePool = require('@supercharge/promise-pool');
const { PromisePool } = require('@supercharge/promise-pool');
const { isDirectory, makeAbsolute, getFilesToUpload } = require('./file-util');

function uploadToGCS(bucket, cacheControl, validate, resume, asset) {
Expand Down Expand Up @@ -52,11 +52,26 @@ function getAllAssetsToUpload(options) {
);
}

function upload(options) {
async function retry(errors, options) {
const assetsToRetry = errors.map((error) => error.item);

if (assetsToRetry.length !== 0) {
console.log(`---Retrying ${assetsToRetry.length} files---`);
return uploadToCloud(options, assetsToRetry);
}

return {results: [], errors: []}
}

async function upload(options) {
const assets = getAllAssetsToUpload(options);
console.log(`---Uploading ${assets.length} files---`)

return uploadToCloud(options, assets);
console.log(`---Uploading ${assets.length} files---`);
const {results: uploadedAssetsFirst, errors: errorsFirst} = await uploadToCloud(options, assets);

const {results: uploadedAssetsRetried, errors: errorsRetried} = await retry(errorsFirst, options);

return {results: uploadedAssetsFirst.concat(uploadedAssetsRetried), errors: errorsRetried};
}

module.exports = { getAllAssetsToUpload, upload };
Loading

0 comments on commit 060f462

Please sign in to comment.