@wbg-mde/r-factory
Version:
Metadata editor R integration module
39 lines (38 loc) • 1.61 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const R = require("@wbg-mde/r-script");
const path = require("path");
const api_helper_1 = require("./modules/shared/api-helper");
class Server {
constructor(opt) {
this.PORT = 9090;
this.workingDirectory = path.join(process.cwd(), 'dist', 'r-scripts');
this.libPath = '';
this.memorylimit = 36000;
this.plumberInitScript = 'run.R';
this.ocpuStartScript = 'start.app.R';
this.options = opt;
}
start() {
this.PORT = this.options ? (this.options.port || this.PORT) : this.PORT;
this.workingDirectory = this.options ? (this.options.directory || this.workingDirectory) : this.workingDirectory;
this.libPath = this.options ? (this.options.libPath || this.libPath) : this.libPath;
let startScript = this.plumberInitScript;
if (this.options && this.options.server === 'opencpu') {
startScript = this.ocpuStartScript;
}
R(path.join(this.workingDirectory, startScript))
.data(this.PORT, this.workingDirectory, this.libPath, this.memorylimit, this.options.timeLimit || 900)
.start((err, result, process_id) => {
if (process_id) {
process.env.r_child_process_id = process_id;
}
console.log(err ? err.toString() : '');
console.log(result ? result.toString() : '');
});
}
stop() {
api_helper_1.APIHelper.call('stop', 'get', {});
}
}
exports.Server = Server;