Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 1
SAN-3030 - Create rebuild worker#1208
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
6af6a7748b045006b71d7f15bbffcc31b7adbb233b6d9360882d38947e59af1dcda0467e38271428dea3c3e3d3c3744feeb22852f8f5139f0865497b93508b8b60bbae43c26b0fe798dfecbc042103d3f49275b9bd467c9310b3c26ee2e9de736047b4d35ee25b16d20a00547cd1aed5420a59790145be9406e124ca079da1f2fddcbbb0188e623d0965fc54d003958b53490451f3148ed3e2799fc9af4cf2b0d1f508728d06ca932b2efdc3483b6af323b06ec172d496b317daa970a3988252cc8c2dcec53af7a6c6f302de0cd5ddb6c564f72129b680134d77e1d529f4b7e7ea749c3d33a5cc8d7458bFile filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -8,7 +8,6 @@ | ||
| require('loadenv')() | ||
| var keypather = require('keypather')() | ||
| var rabbitMQ = require('models/rabbitmq') | ||
| var Promise = require('bluebird') | ||
| var ContextVersion = require('models/mongo/context-version') | ||
| @@ -23,9 +22,10 @@ module.exports = DockRemovedWorker | ||
| /** | ||
| * Main handler for docker unhealthy event | ||
| * Should redeploy all containers on unhealthy dock | ||
| * Should mark the dock removed on every context version that runs on that dock | ||
| * Should mark stopping instances as stopped on that dock since the instances are technically stopped now. | ||
| * Should mark stopping instances as stopped on that dock since the instances are technically stopped now | ||
| * Should redeploy all running or starting containers on unhealthy dock | ||
| * Should rebuild all building containers | ||
| * @param {Object} job - Job info | ||
| * @returns {Promise} | ||
| */ | ||
| @@ -38,6 +38,7 @@ function DockRemovedWorker (job) { | ||
| host: joi.string().required(), | ||
| githubId: joi.number() | ||
| }) | ||
| return joi.validateOrBoomAsync(job, schema) | ||
| .catch(function (err) { | ||
| throw new TaskFatalError(err) | ||
| @@ -49,51 +50,127 @@ function DockRemovedWorker (job) { | ||
| }) | ||
| }) | ||
| .then(function () { | ||
| return Promise.fromCallback(function (cb) { | ||
| Instance.setStoppingAsStoppedByDockerHost(job.host, cb) | ||
| }) | ||
| var tasks = [ | ||
| DockRemovedWorker._stopStoppingInstances(job), | ||
| DockRemovedWorker._redeployAndNotify(job), | ||
| DockRemovedWorker._rebuildAndNotify(job) | ||
| ] | ||
| // those 3 can go in parallel | ||
| return Promise.all(tasks) | ||
| }) | ||
| .then(function () { | ||
| return Promise.fromCallback(function (cb) { | ||
| Instance.findInstancesByDockerHost(job.host, cb) | ||
| }) | ||
| } | ||
| /** | ||
| * Mark all stopping instances as stopped | ||
| * @param {Object} job job data | ||
| * @returns {Promise} | ||
| */ | ||
| DockRemovedWorker._stopStoppingInstances = function (job) { | ||
| return Instance.setStoppingAsStoppedByDockerHostAsync(job.host) | ||
| } | ||
| /** | ||
| * Redeploy instances that should be redeployed and send notification for each of them | ||
| * @param {Object} job job data | ||
| * @returns {Promise} | ||
| */ | ||
| DockRemovedWorker._redeployAndNotify = function (job) { | ||
| return DockRemovedWorker._redeploy(job) | ||
| .then(function (instances) { | ||
| return DockRemovedWorker._updateFrontendInstances(instances) | ||
| }) | ||
| } | ||
| /** | ||
| * Rebuild instances that should be rebuild and send notification for each of them | ||
| * @param {Object} job job data | ||
| * @returns {Promise} | ||
| */ | ||
| DockRemovedWorker._rebuildAndNotify = function (job) { | ||
| return DockRemovedWorker._rebuild(job) | ||
| .then(function (instances) { | ||
| return DockRemovedWorker._updateFrontendInstances(instances) | ||
| }) | ||
| } | ||
| /** | ||
| * Find all instances that should be redeployed (running or starting) and create new job for each of them | ||
| * @param {Object} job job data | ||
| * @returns {Promise} | ||
| */ | ||
| DockRemovedWorker._redeploy = function (job) { | ||
| var logData = { | ||
| tx: true, | ||
| job: job | ||
| } | ||
| log.info(logData, 'DockRemovedWorker._redeploy') | ||
| return Instance.findInstancesRunningOrStartingByDockerHostAsync(job.host) | ||
| .then(function (instances) { | ||
| log.trace(logData, 'DockRemovedWorker - Instances found ' + instances.length) | ||
| if (instances.length > 0) { | ||
| DockRemovedWorker._redeployContainers(instances) | ||
| return DockRemovedWorker._updateFrontendInstances(instances) | ||
| } | ||
| log.trace(logData, '_redeploy found instances to redeploy') | ||
| DockRemovedWorker._redeployContainers(instances) | ||
Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. will this redeploy all containers (even if they where crashed / stopped?) we should only redeploy running containers MemberAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this one is changed. See | ||
| return instances | ||
| }) | ||
| } | ||
| /** | ||
| * should find running instances and submit job to redeploy them | ||
| * @param {Array} instances array of instances on the dock | ||
| * should redeploy all instances | ||
| * @param {Array} instances instances array to redeploy | ||
| * @returns {Promise} | ||
| */ | ||
| DockRemovedWorker._redeployContainers = function (instances) { | ||
| instances = instances || [] | ||
| var instancesToRedeploy = instances.filter(function (instance) { | ||
| var container = instance.container | ||
| if (!container) { | ||
| return false | ||
| } | ||
| return keypather.get(container, 'inspect.State.Running') === true | ||
| }) | ||
| // we creating job for all instances right now | ||
| // job will check internally if it's valid | ||
| // if job failed validation it will quit | ||
| // we can change that later on and fetch more data here and then create | ||
| // jobs only for valid data | ||
| instancesToRedeploy.forEach(function (instance) { | ||
| instances.forEach(function (instance) { | ||
| rabbitMQ.redeployInstanceContainer({ | ||
| instanceId: instance._id, | ||
| sessionUserGithubId: process.env.HELLO_RUNNABLE_GITHUB_ID | ||
| }) | ||
| }) | ||
| } | ||
| /** | ||
| * Find all instances that should be rebuild and create new job for each of them | ||
| * @param {Object} job job data | ||
| * @returns {Promise} | ||
| */ | ||
| DockRemovedWorker._rebuild = function (job) { | ||
| var logData = { | ||
| tx: true, | ||
| job: job | ||
| } | ||
| log.info(logData, 'DockRemovedWorker._rebuild') | ||
| return Instance.findInstancesBuildingOnDockerHostAsync(job.host) | ||
| .then(function (instances) { | ||
| log.trace(logData, '_rebuild found instances to rebuild') | ||
| DockRemovedWorker._rebuildInstances(instances) | ||
| return instances | ||
| }) | ||
| } | ||
| /** | ||
| * should rebuild all instances with not completed builds (and not failed) | ||
| * @param {Array} instances array of instances to be rebuild | ||
| * @returns {Promise} | ||
| * @private | ||
| */ | ||
| DockRemovedWorker._rebuildInstances = function (instances) { | ||
| instances.forEach(function (instance) { | ||
| var payload = { | ||
| instanceId: instance._id | ||
| } | ||
| rabbitMQ.publishInstanceRebuild(payload) | ||
| }) | ||
| } | ||
| /** | ||
| * send events to update frontend instances | ||
| * @param {Array} instances array of instances that were updated | ||
| * @returns {Promise} | ||
| * @private | ||
| */ | ||
| DockRemovedWorker._updateFrontendInstances = function (instances) { | ||
| log.info({ | ||
| tx: true, | ||
| count: instances.length | ||
| }, 'DockRemovedWorker._updateFrontendInstances') | ||
| return Promise.all( | ||
| instances | ||
| .map(function (instance) { | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -42,7 +42,6 @@ function InstanceContainerRedeployWorker (job) { | ||
| tx: true, | ||
| data: job | ||
| } | ||
| var schema = joi.object({ | ||
Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Epic change man! | ||
| instanceId: joi.string().required(), | ||
| sessionUserGithubId: joi.number().required(), | ||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing jsdoc comments about params.