diff --git a/lib/models/rabbitmq/index.js b/lib/models/rabbitmq/index.js index eeb287d9b..d32285a66 100644 --- a/lib/models/rabbitmq/index.js +++ b/lib/models/rabbitmq/index.js @@ -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) { diff --git a/lib/models/services/cluster-config-service.js b/lib/models/services/cluster-config-service.js index dd5f210c5..548528a55 100644 --- a/lib/models/services/cluster-config-service.js +++ b/lib/models/services/cluster-config-service.js @@ -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) @@ -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 } }) + }) } /** diff --git a/lib/workers/cluster.delete.js b/lib/workers/cluster.delete.js index 59af3095c..798c53970 100644 --- a/lib/workers/cluster.delete.js +++ b/lib/workers/cluster.delete.js @@ -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({ @@ -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 }) + }) } diff --git a/unit/workers/cluster.delete.js b/unit/workers/cluster.delete.js index daa5879bd..5c903586c 100644 --- a/unit/workers/cluster.delete.js +++ b/unit/workers/cluster.delete.js @@ -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() }) })