api: fix errors from refactor + PISTON_ALIAS envvar
This commit is contained in:
parent
c6610671fa
commit
3ae32aad3f
|
@ -1,5 +1,5 @@
|
||||||
const logger = require('logplease').create('executor/job');
|
const logger = require('logplease').create('executor/job');
|
||||||
const uuidv4 = require('uuid/v4');
|
const {v4: uuidv4} = require('uuid');
|
||||||
const cp = require('child_process');
|
const cp = require('child_process');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const config = require('../config');
|
const config = require('../config');
|
||||||
|
@ -17,7 +17,7 @@ let gid = 0;
|
||||||
|
|
||||||
class Job {
|
class Job {
|
||||||
|
|
||||||
constructor({ runtime, files, args, stdin, timeouts, main }) {
|
constructor({ runtime, files, args, stdin, timeouts, main, alias }) {
|
||||||
this.uuid = uuidv4();
|
this.uuid = uuidv4();
|
||||||
this.runtime = runtime;
|
this.runtime = runtime;
|
||||||
this.files = files;
|
this.files = files;
|
||||||
|
@ -25,6 +25,7 @@ class Job {
|
||||||
this.stdin = stdin;
|
this.stdin = stdin;
|
||||||
this.timeouts = timeouts;
|
this.timeouts = timeouts;
|
||||||
this.main = main;
|
this.main = main;
|
||||||
|
this.alias = alias;
|
||||||
|
|
||||||
let file_list = this.files.map(f => f.name);
|
let file_list = this.files.map(f => f.name);
|
||||||
|
|
||||||
|
@ -87,7 +88,10 @@ class Job {
|
||||||
var stderr = '';
|
var stderr = '';
|
||||||
|
|
||||||
const proc = cp.spawn(proc_call[0], proc_call.splice(1) ,{
|
const proc = cp.spawn(proc_call[0], proc_call.splice(1) ,{
|
||||||
env: this.runtime.env_vars,
|
env: {
|
||||||
|
...this.runtime.env_vars,
|
||||||
|
PISTON_ALIAS: this.alias
|
||||||
|
},
|
||||||
stdio: 'pipe',
|
stdio: 'pipe',
|
||||||
cwd: this.dir,
|
cwd: this.dir,
|
||||||
uid: this.uid,
|
uid: this.uid,
|
||||||
|
@ -106,7 +110,7 @@ class Job {
|
||||||
} else {
|
} else {
|
||||||
stderr += data;
|
stderr += data;
|
||||||
}
|
}
|
||||||
);
|
});
|
||||||
|
|
||||||
proc.stdout.on('data', data => {
|
proc.stdout.on('data', data => {
|
||||||
if (stdout.length > config.output_max_size) {
|
if (stdout.length > config.output_max_size) {
|
||||||
|
@ -114,7 +118,7 @@ class Job {
|
||||||
} else {
|
} else {
|
||||||
stdout += data;
|
stdout += data;
|
||||||
}
|
}
|
||||||
);
|
});
|
||||||
|
|
||||||
const exit_cleanup = () => {
|
const exit_cleanup = () => {
|
||||||
clear_timeout(kill_timeout);
|
clear_timeout(kill_timeout);
|
||||||
|
|
|
@ -48,6 +48,7 @@ module.exports = {
|
||||||
|
|
||||||
const job = new Job({
|
const job = new Job({
|
||||||
runtime,
|
runtime,
|
||||||
|
alias: req.body.language,
|
||||||
files: req.body.files,
|
files: req.body.files,
|
||||||
args: req.body.args,
|
args: req.body.args,
|
||||||
stdin: req.body.stdin,
|
stdin: req.body.stdin,
|
||||||
|
|
|
@ -23,7 +23,7 @@ const get_package_list = async () => {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const get_package async (lang, version) => {
|
const get_package = async (lang, version) => {
|
||||||
const packages = await get_package_list();
|
const packages = await get_package_list();
|
||||||
|
|
||||||
const candidates = packages
|
const candidates = packages
|
||||||
|
|
Loading…
Reference in New Issue