Skip to content

Commit 46ab4a4

Browse files
authored
Merge pull request #457 from Brikaa/dont-run-if-compile-error
Piston-Nix: Don't start run stage if compile stage errored
2 parents 1fa110c + b381271 commit 46ab4a4

2 files changed

Lines changed: 31 additions & 18 deletions

File tree

api/src/api/v2.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,11 @@ router.post('/execute', async (req, res) => {
264264

265265
await job.prime();
266266

267-
const result = await job.execute();
267+
let result = await job.execute();
268+
// Backward compatibility when the run stage is not started
269+
if (result.run === undefined) {
270+
result.run = result.compile;
271+
}
268272

269273
await job.cleanup();
270274

api/src/job.js

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ class Job {
234234
this.logger.debug('Compiling');
235235

236236
let compile;
237+
let compile_errored = false;
237238

238239
if (this.runtime.compiled) {
239240
compile = await this.safe_call(
@@ -242,16 +243,20 @@ class Job {
242243
this.timeouts.compile,
243244
this.memory_limits.compile
244245
);
246+
compile_errored = compile.code !== 0;
245247
}
246248

247-
this.logger.debug('Running');
249+
let run;
250+
if (!compile_errored) {
251+
this.logger.debug('Running');
248252

249-
const run = await this.safe_call(
250-
this.runtime.run,
251-
[code_files[0].name, ...this.args],
252-
this.timeouts.run,
253-
this.memory_limits.run
254-
);
253+
run = await this.safe_call(
254+
this.runtime.run,
255+
[code_files[0].name, ...this.args],
256+
this.timeouts.run,
257+
this.memory_limits.run
258+
);
259+
}
255260

256261
this.state = job_states.EXECUTED;
257262

@@ -277,6 +282,7 @@ class Job {
277282

278283
const code_files = this.files.filter(file => file.encoding == 'utf8');
279284

285+
let compile_errored = false;
280286
if (this.runtime.compiled) {
281287
eventBus.emit('stage', 'compile');
282288
const { error, code, signal } = await this.safe_call(
@@ -288,19 +294,22 @@ class Job {
288294
);
289295

290296
eventBus.emit('exit', 'compile', { error, code, signal });
297+
compile_errored = code !== 0;
291298
}
292299

293-
this.logger.debug('Running');
294-
eventBus.emit('stage', 'run');
295-
const { error, code, signal } = await this.safe_call(
296-
this.runtime.run,
297-
[code_files[0].name, ...this.args],
298-
this.timeouts.run,
299-
this.memory_limits.run,
300-
eventBus
301-
);
300+
if (!compile_errored) {
301+
this.logger.debug('Running');
302+
eventBus.emit('stage', 'run');
303+
const { error, code, signal } = await this.safe_call(
304+
this.runtime.run,
305+
[code_files[0].name, ...this.args],
306+
this.timeouts.run,
307+
this.memory_limits.run,
308+
eventBus
309+
);
302310

303-
eventBus.emit('exit', 'run', { error, code, signal });
311+
eventBus.emit('exit', 'run', { error, code, signal });
312+
}
304313

305314
this.state = job_states.EXECUTED;
306315
}

0 commit comments

Comments
 (0)