kit-image-deployer
Advanced tools
Comparing version 3.3.0 to 3.3.2-PRERELEASE-github-abuse-retries.0
{ | ||
"name": "kit-image-deployer", | ||
"version": "3.3.0", | ||
"version": "3.3.2-PRERELEASE-github-abuse-retries.0", | ||
"description": "A service that can be used to update given yaml files within a git repository with a new docker image path.", | ||
@@ -41,3 +41,11 @@ "repository": { | ||
"src" | ||
] | ||
], | ||
"publishConfig": { | ||
"tag": "PRERELEASE-github-abuse-retries" | ||
}, | ||
"release": { | ||
"fallbackTags": { | ||
"PRERELEASE-github-abuse-retries": "latest" | ||
} | ||
} | ||
} |
@@ -8,2 +8,3 @@ "use strict"; | ||
const GitHubApi = require("github"); | ||
const EventEmitter = require("events"); | ||
@@ -15,2 +16,3 @@ class ImageDeployer { | ||
retries: 10, | ||
retryIncrement: 30, | ||
docker: { | ||
@@ -24,3 +26,4 @@ registry: undefined, | ||
repo: undefined | ||
} | ||
}, | ||
config: undefined | ||
}, | ||
@@ -42,2 +45,4 @@ options | ||
}; | ||
this.emitter = new EventEmitter(); | ||
} | ||
@@ -140,3 +145,14 @@ | ||
.catch(err => { | ||
attempt(err); | ||
let errCode = err && err.code ? err.code : undefined; | ||
if (errCode && errCode >= 500) { | ||
// don't retry 500 errors | ||
reject(err); | ||
} else { | ||
self.emitter.emit( | ||
"error", | ||
`Error updating image file status code ${errCode}, will retry after delay` | ||
); | ||
// try again after a delay | ||
self.retryAfterDelay(tries, err, attempt); | ||
} | ||
}); | ||
@@ -155,3 +171,4 @@ } else { | ||
.catch(err => { | ||
if (err && err.code && err.code === 404) { | ||
let errCode = err && err.code ? err.code : undefined; | ||
if (errCode && errCode === 404) { | ||
// create file if it does not exist yet | ||
@@ -176,2 +193,6 @@ var newFile = {}; | ||
self.emitter.emit( | ||
"info", | ||
`Image file didn't exist creating image file` | ||
); | ||
return self.github | ||
@@ -194,4 +215,13 @@ .createFile({ | ||
} else { | ||
// try again | ||
attempt(err); | ||
if (errCode && errCode >= 500) { | ||
// don't retry 500 errors | ||
reject(err); | ||
} else { | ||
self.emitter.emit( | ||
"error", | ||
`Error creating image file status code ${errCode}, will retry after delay` | ||
); | ||
// try again after a delay | ||
self.retryAfterDelay(tries, err, attempt); | ||
} | ||
} | ||
@@ -209,2 +239,17 @@ }); | ||
return new Promise(function(resolve, reject) { | ||
// if the config was provided via options, skip fetching it | ||
if (self.options.config) { | ||
self | ||
.attemptCommit( | ||
self.options.config, | ||
image, | ||
branch, | ||
committer, | ||
message, | ||
save | ||
) | ||
.then(resolve) | ||
.catch(reject); | ||
} | ||
const configRequest = { | ||
@@ -237,4 +282,18 @@ user: self.options.github.user, | ||
} | ||
/** | ||
* Calls a function with a delay to back off a call due to an error | ||
* @param {number} attempt - number of this attempt | ||
* @param {object} err - the error object returned from our request | ||
* @param {function} func - the function to call after the timeout | ||
* @return {function} - Returns a setTimeout object calling the passed in object | ||
*/ | ||
retryAfterDelay(attempt, err, func) { | ||
let retryDelay = attempt * this.options.retryIncrement * 1000; | ||
return setTimeout(() => { | ||
return func(err); | ||
}, retryDelay); | ||
} | ||
} | ||
module.exports = ImageDeployer; |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Deprecated
MaintenanceThe maintainer of the package marked it as deprecated. This could indicate that a single version should not be used, or that the package is no longer maintained and any new vulnerabilities will not be fixed.
Found 1 instance in 1 package
19177
274
0
2