kit-image-deployer
Advanced tools
Comparing version 3.3.0 to 3.3.1
{ | ||
"name": "kit-image-deployer", | ||
"version": "3.3.0", | ||
"version": "3.3.1", | ||
"description": "A service that can be used to update given yaml files within a git repository with a new docker image path.", | ||
@@ -5,0 +5,0 @@ "repository": { |
@@ -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,9 @@ | ||
.catch(err => { | ||
attempt(err); | ||
let errCode = err && err.code ? err.code : undefined; | ||
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 +166,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 +188,6 @@ var newFile = {}; | ||
self.emitter.emit( | ||
"info", | ||
`Image file didn't exist creating image file` | ||
); | ||
return self.github | ||
@@ -194,4 +210,8 @@ .createFile({ | ||
} else { | ||
// try again | ||
attempt(err); | ||
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 +229,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 +272,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
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
18627
264