Skip to content

Commit

Permalink
Merge pull request #2041 from CodeNow/ASAP-fix-multi-delete
Browse files Browse the repository at this point in the history
Fix multi-delete
  • Loading branch information
Nathan219 authored Jul 6, 2017
2 parents d932a59 + 4d8fe34 commit 777ebeb
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/models/rabbitmq/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ RabbitMQ.prototype.createCluster = function (data) {
}

RabbitMQ.prototype.deleteCluster = function (data) {
this._publisher.publishTask('cluster.delete', data)
return this._publisher.publishTask('cluster.delete', data)
}

RabbitMQ.prototype.updateCluster = function (data) {
Expand Down
10 changes: 7 additions & 3 deletions lib/models/services/cluster-config-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -359,8 +359,9 @@ module.exports = class ClusterConfigService {
log.info('called')
return AutoIsolationConfig.findByIdAndAssert(clusterId)
.tap((cluster) => {
const instancesIds = cluster.instancesIds || []
return Promise.each(instancesIds, (instanceId) => rabbitMQ.deleteInstance({ instanceId }))
const instancesIds = [cluster.instance.toString()]
.concat(cluster.requestedDependencies.map(dep => dep.instance.toString()))
return Promise.map(instancesIds, (instanceId) => rabbitMQ.deleteInstance({ instanceId }))
})
.tap(() => {
return InputClusterConfig.findActiveByAutoIsolationId(clusterId)
Expand Down Expand Up @@ -425,7 +426,10 @@ module.exports = class ClusterConfigService {
})
log.info('called')
return ClusterConfigService.findAllRelatedClusters(clusterId)
.each((cluster) => rabbitMQ.deleteCluster(cluster))
.map((cluster) => AutoIsolationConfig.findByIdAndAssert(cluster.autoIsolationConfigId))
.each((cluster) => {
return rabbitMQ.deleteCluster({ cluster: { id: cluster.id } })
})
}

/**
Expand Down
4 changes: 4 additions & 0 deletions lib/workers/cluster.delete.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
require('loadenv')()
const ClusterConfigService = require('models/services/cluster-config-service')
const joi = require('utils/joi')
const WorkerStopError = require('error-cat/errors/worker-stop-error')

module.exports.jobSchema = joi.object({
cluster: joi.object({
Expand All @@ -21,4 +22,7 @@ module.exports.jobSchema = joi.object({
*/
module.exports.task = (job) => {
return ClusterConfigService.delete(job.cluster.id)
.catch((err) => {
throw new WorkerStopError('Could not delete cluster', { err })
})
}
1 change: 0 additions & 1 deletion unit/workers/cluster.delete.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ describe('Cluster Delete Worker', function () {
ClusterConfigService.delete.rejects(mongoError)
Worker.task(testData).asCallback(function (err) {
expect(err).to.exist()
expect(err).to.equal(mongoError)
done()
})
})
Expand Down

0 comments on commit 777ebeb

Please sign in to comment.