-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgalaxy-autoscale.js
68 lines (57 loc) · 1.84 KB
/
galaxy-autoscale.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/* Copyright J. Eric Hartzog (Avario, Inc.), 2017 */
import { SyncedCron } from 'meteor/percolate:synced-cron';
import runAutoScale from './lib/autoscale';
// Create the object with default options
const GalaxyAutoScale = {
options: {
log: true,
logger: null,
interval: 'every 15 minutes',
jobName: 'galaxy-auto-scale',
stepDelayMs: 5000,
loadingTimeoutMs: 30000,
// Good reading for these rules at http://galaxy-guide.meteor.com/scaling.html
scalingRules: {
containersMin: 1,
containersMax: 3,
// cpuUsageMax: 80,
// memoryMax: 70,
connectionsPerContainerMax: 80, // Scale up when conn/container reaches this
connectionsPerContainerMin: 40, // Scale down when conn/container reaches this
},
},
};
const optionsAreValid = (opts) => {
if ((!opts.appName && !opts.appUrl) || !opts.username || !opts.password) {
return false;
}
return true;
};
GalaxyAutoScale.config = (opts) => {
GalaxyAutoScale.options = Object.assign({}, GalaxyAutoScale.options, opts);
};
GalaxyAutoScale.addSyncedCronJob = () => {
if (!optionsAreValid(GalaxyAutoScale.options)) {
throw new Error('Tried to start GalaxyAutoScale with invalid options set.');
}
Meteor.startup(() => {
SyncedCron.add({
name: GalaxyAutoScale.options.jobName,
schedule(parser) {
return parser.text(GalaxyAutoScale.options.interval);
},
job() {
runAutoScale(GalaxyAutoScale.options);
},
});
});
};
GalaxyAutoScale.startSyncedCron = () => {
Meteor.startup(() => {
SyncedCron.start()
});
};
GalaxyAutoScale.runAutoScale = () => {
runAutoScale(GalaxyAutoScale.options);
};
export { GalaxyAutoScale };