MCPcopy Index your code
hub / github.com/PrairieLearn/PrairieLearn / call

Method call

lib/code-caller.js:127–162  ·  view source on GitHub ↗
(file, fcn, args, options, callback)

Source from the content-addressed store, hash-verified

125 }
126
127 call(file, fcn, args, options, callback) {
128 debug(`enter call(), state: ${String(this.state)}, uuid: ${this.uuid}`);
129 if (!this._checkState([CREATED, WAITING])) return callback(new Error('invalid PythonCaller state'));
130
131 if (this.state == CREATED) {
132 this._startChild();
133 }
134
135 const localOptions = _.defaults(options, {
136 cwd: __dirname,
137 paths: [],
138 timeout: 20000, // FIXME: this number (equivalent to 20 seconds) should not have to be this high
139 });
140 const callData = {
141 file, fcn, args,
142 cwd: localOptions.cwd,
143 paths: localOptions.paths,
144 };
145 const callDataString = JSON.stringify(callData);
146 this.callback = callback;
147 this.timeoutID = setTimeout(this._timeout.bind(this), localOptions.timeout);
148
149 this.outputStdout = '';
150 this.outputStderr = '';
151 this.outputBoth = '';
152 this.outputData = '';
153
154 this.lastCallData = callData;
155
156 this.child.stdin.write(callDataString);
157 this.child.stdin.write('\n');
158
159 this.state = IN_CALL;
160 this._checkState();
161 debug(`exit call(), state: ${String(this.state)}, uuid: ${this.uuid}`);
162 }
163
164 /*
165 * @param {function} callback - A callback(err, success) function. If 'success' is false then this PythonCaller should be discarded and a new one created by the parent.

Callers 15

restartMethod · 0.95
sylvester.jsFile · 0.80
__webpack_require__Function · 0.80
socket.io.jsFile · 0.80
formatArgsFunction · 0.80
logFunction · 0.80
runTimeoutFunction · 0.80
runClearTimeoutFunction · 0.80
enabledFunction · 0.80
runInContextFunction · 0.80
serializeFunction · 0.80
walkFunction · 0.80

Calls 4

_checkStateMethod · 0.95
_startChildMethod · 0.95
debugFunction · 0.85
callbackFunction · 0.85

Tested by

no test coverage detected