MXS-1300: Use native promises for requests

The request-promise-native package adds support for request with native
promises. This is a convenient way to synchronize multiple HTTP requests.

The functions are changed to use promises to make testing easier. With
promises, the testing code can use the chai-as-promised library.

There are a few cases where doRequest is called with a callback that again
calls doAsyncRequest. With multiple hosts, this causes each command to be
propagated to all servers. This is a design flaw of the current multi-host
mode and needs to be changed.

Changed maxctrl.js to wait on the promises to silence some warnings if the
promise rejections are ignored.
This commit is contained in:
Markus Mäkelä
2017-07-14 05:22:34 +03:00
parent b54e94ce95
commit ec5b0fea39
9 changed files with 79 additions and 80 deletions

View File

@ -13,18 +13,14 @@
'use strict';
var argv = process.argv
var maxctrl = require('./core.js')
// Mangle the arguments if we are being called from the command line
if (argv[0] == process.execPath) {
argv.shift()
if (process.argv[0] == process.execPath) {
process.argv.shift()
// The first argument is always the script
argv.shift()
process.argv.shift()
}
require('./core.js')(argv)
.then(function(output){
if (output.length > 0) {
console.log(output)
}
}, console.log)
maxctrl(process.argv)
.then(function(out) {}, function(out) {})