1
0
mirror of https://github.com/yldio/copilot.git synced 2025-01-07 17:40:14 +02:00
copilot/legacy/docker-compose-client/src/index.js
Sérgio Ramos 8295bd6882 chore: initial lerna setup
this shall be a progressive process
2017-05-25 10:56:50 +01:00

51 lines
1.2 KiB
JavaScript

const { Client } = require('zerorpc');
const { EventEmitter } = require('events');
const awaitify = require('apr-awaitify');
class DockerComposeClient extends EventEmitter {
constructor(endpoint = 'tcp://0.0.0.0:4242') {
super();
this.client = new Client({
heartbeatInterval: 60 * 4 * 1000, // 4m
timeout: 60 * 30, // 30m
});
this.client.connect(endpoint);
this.client.on('error', err => this.emit('error', err));
this._invoke = awaitify(this._invoke.bind(this));
}
// Why isn't client.connect async with error??
_invoke(name, ...args) {
return this.client.invoke(name, ...args);
}
close() {
return this.client.close();
}
provision({ projectName, manifest }) {
// eslint-disable-next-line camelcase
return this._invoke('up', { project_name: projectName }, manifest);
}
scale({ projectName, services, manifest }) {
return this._invoke(
'scale',
{
// eslint-disable-next-line camelcase
project_name: projectName,
services: Object.keys(services).map(name => ({
name,
num: services[name]
}))
},
manifest
);
}
}
module.exports = DockerComposeClient;