Skip to content

Commit

Permalink
Add timeout for @google-cloud/storage
Browse files Browse the repository at this point in the history
  • Loading branch information
henrik242 committed Jun 17, 2021
1 parent b697438 commit 5d04250
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ Options:
--flatten, -f Flatten filestructure [boolean] [default: false]
--dry-run, -n Print a list of which files would be uploaded [boolean]
--resumable, -r Resumable upload [boolean] [default: true]
--validation, -V Validation for upload [boolean] [default: true]
--validation, -V Validation for upload [string] [default: md5]
--timeout, -t Upload timeout [string] [default: 60000]
--help, -h, -? Show help [boolean]
--version, -v Show version number [boolean]
```
Expand Down
16 changes: 11 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,21 @@ const {argv} = require('yargs')
})
.option('resumable', {
alias: 'r',
describe: 'Resumable upload',
default: true,
describe: 'Force a resumable upload',
default: false,
type: 'boolean',
})
.option('validation', {
alias: 'V',
describe: 'Validation for upload',
default: true,
type: 'boolean',
describe: 'Possible values: "md5", "crc32c", or false. By default, data integrity is validated with an MD5 checksum for maximum reliability',
default: 'md5',
type: 'string',
})
.option('timeout', {
alias: 't',
describe: 'Set the HTTP request timeout in milliseconds. This option is not available for resumable uploads',
default: '60000',
type: 'string',
})
.help()
.version()
Expand Down
6 changes: 4 additions & 2 deletions lib/uploader.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
const { Storage } = require('@google-cloud/storage');
const { isDirectory, makeAbsolute, getFilesToUpload } = require('./file-util');

function uploadToGCS(bucket, cacheControl, validate, resume, asset) {
function uploadToGCS(bucket, cacheControl, validate, resume, timelimit, asset) {
const uploadOpt = {
destination: asset.destination,
validation: validate,
resumable: resume,
timeout: timelimit,
public: true,
gzip: true,
metadata: { cacheControl },
Expand All @@ -23,6 +24,7 @@ function uploadToCloud(options, assets) {
cacheControl,
validation,
resumable,
timeout,
} = options;

const storage = new Storage({
Expand All @@ -34,7 +36,7 @@ function uploadToCloud(options, assets) {

return Promise.all(
assets.map(asset =>
uploadToGCS(bucket, cacheControl, validation, resumable, asset)
uploadToGCS(bucket, cacheControl, validation, resumable, timeout, asset)
)
);
}
Expand Down

0 comments on commit 5d04250

Please sign in to comment.