-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4611 from spalger/implement/devLiveOptimizer
Implement dev live optimizer
- Loading branch information
Showing
89 changed files
with
1,682 additions
and
1,291 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,3 +12,5 @@ target | |
esvm | ||
.htpasswd | ||
installedPlugins | ||
webpackstats.json | ||
config/kibana.dev.yml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
let cluster = require('cluster'); | ||
let { join } = require('path'); | ||
let { compact, invoke, bindAll, once, get } = require('lodash'); | ||
|
||
let Log = require('../Log'); | ||
let Worker = require('./Worker'); | ||
|
||
module.exports = class ClusterManager { | ||
constructor(opts) { | ||
this.log = new Log(opts.quiet, opts.silent); | ||
this.addedCount = 0; | ||
|
||
this.workers = [ | ||
new Worker({ | ||
type: 'optmzr', | ||
title: 'optimizer', | ||
log: this.log, | ||
argv: compact([ | ||
'--plugins.initialize=false', | ||
'--server.autoListen=false' | ||
]), | ||
watch: false | ||
}), | ||
|
||
new Worker({ | ||
type: 'server', | ||
log: this.log | ||
}) | ||
]; | ||
|
||
// broker messages between workers | ||
this.workers.forEach((worker) => { | ||
worker.on('broadcast', (msg) => { | ||
this.workers.forEach((to) => { | ||
if (to !== worker && to.online) { | ||
to.fork.send(msg); | ||
} | ||
}); | ||
}); | ||
}); | ||
|
||
bindAll(this, 'onWatcherAdd', 'onWatcherError', 'onWatcherChange'); | ||
|
||
if (opts.watch) this.setupWatching(); | ||
else this.startCluster(); | ||
} | ||
|
||
startCluster() { | ||
invoke(this.workers, 'start'); | ||
} | ||
|
||
setupWatching() { | ||
var chokidar = require('chokidar'); | ||
let utils = require('requirefrom')('src/utils'); | ||
let fromRoot = utils('fromRoot'); | ||
|
||
this.watcher = chokidar.watch([ | ||
'src/plugins', | ||
'src/server', | ||
'src/ui', | ||
'src/utils', | ||
'config', | ||
'installedPlugins' | ||
], { | ||
cwd: fromRoot('.'), | ||
ignored: /[\\\/](node_modules|bower_components|public)[\\\/]/, | ||
}); | ||
|
||
this.watcher.on('add', this.onWatcherAdd); | ||
this.watcher.on('error', this.onWatcherError); | ||
|
||
this.watcher.on('ready', once(() => { | ||
// start sending changes to workers | ||
this.watcher.removeListener('add', this.onWatcherAdd); | ||
this.watcher.on('all', this.onWatcherChange); | ||
|
||
this.log.good('Watching for changes', `(${this.addedCount} files)`); | ||
this.startCluster(); | ||
})); | ||
} | ||
|
||
onWatcherAdd() { | ||
this.addedCount += 1; | ||
} | ||
|
||
onWatcherChange(e, path) { | ||
invoke(this.workers, 'onChange', path); | ||
} | ||
|
||
onWatcherError(err) { | ||
this.log.bad('Failed to watch files!\n', err.stack); | ||
process.exit(1); // eslint-disable-line no-process-exit | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.