camelCase -> snake_case

This commit is contained in:
Omar Brikaa 2022-09-30 21:37:19 +02:00
parent 684bfd6610
commit f40f7702de
2 changed files with 27 additions and 27 deletions

View File

@ -172,9 +172,9 @@ router.use((req, res, next) => {
router.ws('/connect', async (ws, req) => { router.ws('/connect', async (ws, req) => {
let job = null; let job = null;
let eventBus = new events.EventEmitter(); let event_bus = new events.EventEmitter();
eventBus.on('stdout', data => event_bus.on('stdout', data =>
ws.send( ws.send(
JSON.stringify({ JSON.stringify({
type: 'data', type: 'data',
@ -183,7 +183,7 @@ router.ws('/connect', async (ws, req) => {
}) })
) )
); );
eventBus.on('stderr', data => event_bus.on('stderr', data =>
ws.send( ws.send(
JSON.stringify({ JSON.stringify({
type: 'data', type: 'data',
@ -192,10 +192,10 @@ router.ws('/connect', async (ws, req) => {
}) })
) )
); );
eventBus.on('stage', stage => event_bus.on('stage', stage =>
ws.send(JSON.stringify({ type: 'stage', stage })) ws.send(JSON.stringify({ type: 'stage', stage }))
); );
eventBus.on('exit', (stage, status) => event_bus.on('exit', (stage, status) =>
ws.send(JSON.stringify({ type: 'exit', stage, ...status })) ws.send(JSON.stringify({ type: 'exit', stage, ...status }))
); );
@ -218,7 +218,7 @@ router.ws('/connect', async (ws, req) => {
}) })
); );
await job.execute_interactive(eventBus); await job.execute_interactive(event_bus);
await job.cleanup(); await job.cleanup();
ws.close(4999, 'Job Completed'); ws.close(4999, 'Job Completed');
@ -229,7 +229,7 @@ router.ws('/connect', async (ws, req) => {
case 'data': case 'data':
if (job !== null) { if (job !== null) {
if (msg.stream === 'stdin') { if (msg.stream === 'stdin') {
eventBus.emit('stdin', msg.data); event_bus.emit('stdin', msg.data);
} else { } else {
ws.close(4004, 'Can only write to stdin'); ws.close(4004, 'Can only write to stdin');
} }
@ -240,7 +240,7 @@ router.ws('/connect', async (ws, req) => {
case 'signal': case 'signal':
if (job !== null) { if (job !== null) {
if (SIGNALS.includes(msg.signal)) { if (SIGNALS.includes(msg.signal)) {
eventBus.emit('signal', msg.signal); event_bus.emit('signal', msg.signal);
} else { } else {
ws.close(4005, 'Invalid signal'); ws.close(4005, 'Invalid signal');
} }

View File

@ -18,7 +18,7 @@ let uid = 0;
let gid = 0; let gid = 0;
let remaining_job_spaces = config.max_concurrent_jobs; let remaining_job_spaces = config.max_concurrent_jobs;
let jobQueue = []; let job_queue = [];
class Job { class Job {
#active_timeouts; #active_timeouts;
@ -74,7 +74,7 @@ class Job {
if (remaining_job_spaces < 1) { if (remaining_job_spaces < 1) {
this.logger.info(`Awaiting job slot`); this.logger.info(`Awaiting job slot`);
await new Promise(resolve => { await new Promise(resolve => {
jobQueue.push(resolve); job_queue.push(resolve);
}); });
} }
this.logger.info(`Priming job`); this.logger.info(`Priming job`);
@ -135,7 +135,7 @@ class Job {
this.logger.debug('Destroyed processes writables'); this.logger.debug('Destroyed processes writables');
} }
async safe_call(file, args, timeout, memory_limit, eventBus = null) { async safe_call(file, args, timeout, memory_limit, event_bus = null) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
const nonetwork = config.disable_networking ? ['nosocket'] : []; const nonetwork = config.disable_networking ? ['nosocket'] : [];
@ -181,16 +181,16 @@ class Job {
this.#active_parent_processes.push(proc); this.#active_parent_processes.push(proc);
if (eventBus === null) { if (event_bus === null) {
proc.stdin.write(this.stdin); proc.stdin.write(this.stdin);
proc.stdin.end(); proc.stdin.end();
proc.stdin.destroy(); proc.stdin.destroy();
} else { } else {
eventBus.on('stdin', data => { event_bus.on('stdin', data => {
proc.stdin.write(data); proc.stdin.write(data);
}); });
eventBus.on('kill', signal => { event_bus.on('kill', signal => {
proc.kill(signal); proc.kill(signal);
}); });
} }
@ -205,8 +205,8 @@ class Job {
this.#active_timeouts.push(kill_timeout); this.#active_timeouts.push(kill_timeout);
proc.stderr.on('data', async data => { proc.stderr.on('data', async data => {
if (eventBus !== null) { if (event_bus !== null) {
eventBus.emit('stderr', data); event_bus.emit('stderr', data);
} else if (stderr.length > this.runtime.output_max_size) { } else if (stderr.length > this.runtime.output_max_size) {
this.logger.info(`stderr length exceeded`); this.logger.info(`stderr length exceeded`);
process.kill(proc.pid, 'SIGKILL'); process.kill(proc.pid, 'SIGKILL');
@ -217,8 +217,8 @@ class Job {
}); });
proc.stdout.on('data', async data => { proc.stdout.on('data', async data => {
if (eventBus !== null) { if (event_bus !== null) {
eventBus.emit('stdout', data); event_bus.emit('stdout', data);
} else if (stdout.length > this.runtime.output_max_size) { } else if (stdout.length > this.runtime.output_max_size) {
this.logger.info(`stdout length exceeded`); this.logger.info(`stdout length exceeded`);
process.kill(proc.pid, 'SIGKILL'); process.kill(proc.pid, 'SIGKILL');
@ -294,7 +294,7 @@ class Job {
}; };
} }
async execute_interactive(eventBus) { async execute_interactive(event_bus) {
if (this.state !== job_states.PRIMED) { if (this.state !== job_states.PRIMED) {
throw new Error( throw new Error(
'Job must be in primed state, current state: ' + 'Job must be in primed state, current state: ' +
@ -310,31 +310,31 @@ class Job {
let compile_errored = false; let compile_errored = false;
if (this.runtime.compiled) { if (this.runtime.compiled) {
eventBus.emit('stage', 'compile'); event_bus.emit('stage', 'compile');
const { error, code, signal } = await this.safe_call( const { error, code, signal } = await this.safe_call(
this.runtime.compile, this.runtime.compile,
code_files.map(x => x.name), code_files.map(x => x.name),
this.timeouts.compile, this.timeouts.compile,
this.memory_limits.compile, this.memory_limits.compile,
eventBus event_bus
); );
eventBus.emit('exit', 'compile', { error, code, signal }); event_bus.emit('exit', 'compile', { error, code, signal });
compile_errored = code !== 0; compile_errored = code !== 0;
} }
if (!compile_errored) { if (!compile_errored) {
this.logger.debug('Running'); this.logger.debug('Running');
eventBus.emit('stage', 'run'); event_bus.emit('stage', 'run');
const { error, code, signal } = await this.safe_call( const { error, code, signal } = await this.safe_call(
this.runtime.run, this.runtime.run,
[code_files[0].name, ...this.args], [code_files[0].name, ...this.args],
this.timeouts.run, this.timeouts.run,
this.memory_limits.run, this.memory_limits.run,
eventBus event_bus
); );
eventBus.emit('exit', 'run', { error, code, signal }); event_bus.emit('exit', 'run', { error, code, signal });
} }
this.state = job_states.EXECUTED; this.state = job_states.EXECUTED;
@ -470,8 +470,8 @@ class Job {
await this.cleanup_filesystem(); await this.cleanup_filesystem();
remaining_job_spaces++; remaining_job_spaces++;
if (jobQueue.length > 0) { if (job_queue.length > 0) {
jobQueue.shift()(); job_queue.shift()();
} }
} }
} }