1
0
mirror of https://github.com/yldio/copilot.git synced 2024-11-14 23:30:05 +02:00

feat(portal-data): if machine is deleted, remove it from Service

This commit is contained in:
Sérgio Ramos 2017-06-27 18:14:26 +01:00 committed by Judit Greskovits
parent c438f07e56
commit 041d6bf73f

View File

@ -15,9 +15,10 @@ module.exports = class Watcher {
// todo assert options // todo assert options
this._data = options.data; this._data = options.data;
this._frequency = 500;
this._tritonWatch = new TritonWatch({ this._tritonWatch = new TritonWatch({
frequency: 500, frequency: this._frequency,
triton: { triton: {
profile: { profile: {
url: options.url || process.env.SDC_URL, url: options.url || process.env.SDC_URL,
@ -92,6 +93,11 @@ module.exports = class Watcher {
.filter(({ machineId }) => { return machine.id === machineId; }) .filter(({ machineId }) => { return machine.id === machineId; })
.pop(); .pop();
const updateService = (updatedService) => {
console.log('-> updating service', util.inspect(updatedService));
return this._data.updateService(updatedService, handleError);
};
const create = () => { const create = () => {
const instance = { const instance = {
name: machine.name, name: machine.name,
@ -101,13 +107,10 @@ module.exports = class Watcher {
console.log('-> creating instance', util.inspect(instance)); console.log('-> creating instance', util.inspect(instance));
return this._data.createInstance(instance, handleError((_, instance) => { return this._data.createInstance(instance, handleError((_, instance) => {
const updatedService = { return updateService({
id: service.id, id: service.id,
instances: instances.concat(instance) instances: instances.concat(instance)
}; });
console.log('-> updating service', util.inspect(updatedService));
return this._data.updateService(updatedService, handleError);
})); }));
}; };
@ -118,7 +121,18 @@ module.exports = class Watcher {
}; };
console.log('-> updating instance', util.inspect(updatedInstance)); console.log('-> updating instance', util.inspect(updatedInstance));
return this._data.updateInstance(updatedInstance, handleError); return this._data.updateInstance(updatedInstance, handleError(() => {
if (machine.state.toUpperCase() !== 'DELETED') {
return;
}
return setTimeout(() => {
return updateService({
id: service.id,
instances: instances.filter(({ id }) => { return id !== instance.id; })
});
}, this._frequency * 4);
}));
}; };
return isNew ? return isNew ?