|
|
@ -14,9 +14,9 @@ const retry = require('async-retry') |
|
|
|
const splitArray = require('split-array') |
|
|
|
const { parse: parseIni } = require('ini') |
|
|
|
const { readFile, stat, lstat } = require('fs-extra') |
|
|
|
const { responseError } = require('./error') |
|
|
|
const ms = require('ms') |
|
|
|
|
|
|
|
// Ours
|
|
|
|
// Utilities
|
|
|
|
const { |
|
|
|
staticFiles: getFiles, |
|
|
|
npm: getNpmFiles, |
|
|
@ -26,6 +26,7 @@ const ua = require('./ua') |
|
|
|
const hash = require('./hash') |
|
|
|
const Agent = require('./agent') |
|
|
|
const toHost = require('./to-host') |
|
|
|
const { responseError } = require('./error') |
|
|
|
|
|
|
|
// How many concurrent HTTP/2 stream uploads
|
|
|
|
const MAX_CONCURRENT = 10 |
|
|
@ -918,17 +919,21 @@ module.exports = class Now extends EventEmitter { |
|
|
|
} |
|
|
|
|
|
|
|
setScale(nameOrId, scale) { |
|
|
|
return this.retry(async (bail, attempt) => { |
|
|
|
return this.retry( |
|
|
|
async (bail, attempt) => { |
|
|
|
if (this._debug) { |
|
|
|
console.time( |
|
|
|
`> [debug] #${attempt} POST /deployments/${nameOrId}/instances` |
|
|
|
) |
|
|
|
} |
|
|
|
|
|
|
|
const res = await this._fetch(`/now/deployments/${nameOrId}/instances`, { |
|
|
|
const res = await this._fetch( |
|
|
|
`/now/deployments/${nameOrId}/instances`, |
|
|
|
{ |
|
|
|
method: 'POST', |
|
|
|
body: scale |
|
|
|
}) |
|
|
|
} |
|
|
|
) |
|
|
|
|
|
|
|
if (this._debug) { |
|
|
|
console.timeEnd( |
|
|
@ -944,6 +949,14 @@ module.exports = class Now extends EventEmitter { |
|
|
|
|
|
|
|
if (res.status !== 200) { |
|
|
|
if (res.status === 404 || res.status === 400) { |
|
|
|
if ( |
|
|
|
body && |
|
|
|
body.error && |
|
|
|
body.error.code && |
|
|
|
body.error.code === 'not_snapshotted' |
|
|
|
) { |
|
|
|
throw new Error(body.error.message) |
|
|
|
} |
|
|
|
const err = new Error(body.error.message) |
|
|
|
err.userError = true |
|
|
|
return bail(err) |
|
|
@ -954,11 +967,19 @@ module.exports = class Now extends EventEmitter { |
|
|
|
err.userError = true |
|
|
|
return bail(err) |
|
|
|
} |
|
|
|
throw new Error(`Error occurred while scaling. Please try again later`) |
|
|
|
throw new Error( |
|
|
|
`Error occurred while scaling. Please try again later` |
|
|
|
) |
|
|
|
} |
|
|
|
|
|
|
|
return body |
|
|
|
}) |
|
|
|
}, |
|
|
|
{ |
|
|
|
retries: 300, |
|
|
|
maxTimeout: ms('5s'), |
|
|
|
factor: 1.1 |
|
|
|
} |
|
|
|
) |
|
|
|
} |
|
|
|
|
|
|
|
async unfreeze(depl) { |
|
|
|