From 2590e6db5d0f609cf0cb8afa96961e44b788c069 Mon Sep 17 00:00:00 2001 From: PrabalSingh Date: Sat, 23 May 2020 01:59:57 +0530 Subject: [PATCH 1/8] feat(project-worker): add setup and run function --- src/taskmaster.ts | 5 ++++- src/tasks/index.ts | 10 +++++++--- src/tasks/job.ts | 7 +++++-- src/tasks/scenarios/project.ts | 26 +++++++++++++++++++------- 4 files changed, 35 insertions(+), 13 deletions(-) diff --git a/src/taskmaster.ts b/src/taskmaster.ts index c3d871f..f693deb 100644 --- a/src/taskmaster.ts +++ b/src/taskmaster.ts @@ -4,7 +4,7 @@ import * as amqp from 'amqplib/callback_api' import {Connection} from 'amqplib/callback_api' import { execute } from './tasks' import config = require('../config.js') -import { SubmitJob, RunJob } from 'tasks/job'; +import {SubmitJob, RunJob, ProjectJob} from 'tasks/job'; import { mkdir } from 'shelljs' // =============== Setup Raven @@ -41,6 +41,9 @@ amqp.connect(`amqp://${config.AMQP.USER}:${config.AMQP.PASS}@${config.AMQP.HOST} case 'run': job = new RunJob(payload) break + case 'project': + job = new ProjectJob(payload) + break default: throw new Error("Scenario not declared") } diff --git a/src/tasks/index.ts b/src/tasks/index.ts index 0a8739d..f5bd1db 100644 --- a/src/tasks/index.ts +++ b/src/tasks/index.ts @@ -1,14 +1,16 @@ -import { Result, RunResult, SubmissionResult } from 'types/result' +import { Result, RunResult, SubmissionResult, ProjectResult } from 'types/result' import config = require('../../config.js') import {exec, mkdir, rm} from 'shelljs' import * as path from 'path' import RunScenario from './scenarios/run' import SubmissionScenario from './scenarios/submission' -import { RunJob, SubmitJob, Job } from "./job"; +import ProjectScenario from './scenarios/project'; +import { RunJob, SubmitJob, ProjectJob, Job } from "./job"; export function execute(job: RunJob): Promise export function execute(job: SubmitJob): Promise +export function execute(job: ProjectJob): Promise export async function execute (job: Job) { // Create RUNBOX const currentJobDir = path.join(config.RUNBOX.DIR, job.id.toString()) @@ -19,6 +21,8 @@ export async function execute (job: Job) { scenario = new RunScenario() } else if (job instanceof SubmitJob) { scenario = new SubmissionScenario() + } else if (job instanceof ProjectJob) { + scenario = new ProjectScenario() } // Setup RUNBOX @@ -30,7 +34,7 @@ export async function execute (job: Job) { // Get result const result = await scenario.result(currentJobDir, job) - rm('-rf', currentJobDir) + // rm('-rf', currentJobDir) return result } diff --git a/src/tasks/job.ts b/src/tasks/job.ts index b2ccf33..066e848 100644 --- a/src/tasks/job.ts +++ b/src/tasks/job.ts @@ -18,7 +18,8 @@ interface SubmitJobConstructorOpts extends JobConstructorOpts { } interface ProjectConstructorOpts extends JobConstructorOpts { - problem: string + problem: string, + submissionDirs: string } export class Job { @@ -57,9 +58,11 @@ export class SubmitJob extends Job { export class ProjectJob extends Job { problem: string + submissionDirs: string - constructor({ id, source, lang, timelimit, scenario, problem}: ProjectConstructorOpts) { + constructor({ id, source, lang, timelimit, scenario, problem, submissionDirs}: ProjectConstructorOpts) { super({ id, source, lang, timelimit, scenario}) this.problem = problem + this.submissionDirs = submissionDirs } } diff --git a/src/tasks/scenarios/project.ts b/src/tasks/scenarios/project.ts index aa68084..f36eab9 100644 --- a/src/tasks/scenarios/project.ts +++ b/src/tasks/scenarios/project.ts @@ -1,20 +1,32 @@ import config = require('../../../config.js') import {cat, exec, mkdir, rm, touch, head} from 'shelljs' -import { ProjectJob } from 'tasks/job' +import {ProjectJob} from 'tasks/job' import { ProjectResult } from 'types/result' import * as path from 'path' -import * as fs from 'fs' import { Scenario } from 'tasks/scenario' import { download } from 'utils/request' export default class ProjectScenario extends Scenario { async setup(currentJobDir: string, job: ProjectJob) { - // TODO - const problemDir = path.join(currentJobDir, job.problem) - await download(job.problem, problemDir) + const problemDir = path.join(currentJobDir, 'problem') + mkdir('-p', problemDir) + await download(job.problem, path.join(problemDir, 'problem')) + + const solutionDir = path.join(currentJobDir, 'solution') + mkdir('-p', solutionDir) + await download(job.source, path.join(solutionDir, 'solution')) + } - const solutionDir = path.join(currentJobDir, job.source) - await download(job.problem, solutionDir) + run(currentJobDir: string, job: ProjectJob) { + const LANG_CONFIG = config.LANGS[job.lang] + return exec(`docker run \\ + --cpus="${LANG_CONFIG.CPU_SHARE}" \\ + --memory="${LANG_CONFIG.MEM_LIMIT}" \\ + --rm \\ + -v "${currentJobDir}":/usr/src/runbox \\ + -w /usr/src/runbox codingblocks/project-worker-"${job.lang}" \\ + /bin/judge.sh -s "${job.submissionDirs}" + `) } async result(currentJobDir: string, job: ProjectJob): Promise { From b6ce935029d3f495e20025260d236587468e01f7 Mon Sep 17 00:00:00 2001 From: PrabalSingh Date: Sat, 23 May 2020 16:44:19 +0530 Subject: [PATCH 2/8] add projectScenario run & result --- src/tasks/index.ts | 2 +- src/tasks/scenarios/project.ts | 37 +++++++++++++++++++++++++++++++--- 2 files changed, 35 insertions(+), 4 deletions(-) diff --git a/src/tasks/index.ts b/src/tasks/index.ts index f5bd1db..c5665ec 100644 --- a/src/tasks/index.ts +++ b/src/tasks/index.ts @@ -34,7 +34,7 @@ export async function execute (job: Job) { // Get result const result = await scenario.result(currentJobDir, job) - // rm('-rf', currentJobDir) + rm('-rf', currentJobDir) return result } diff --git a/src/tasks/scenarios/project.ts b/src/tasks/scenarios/project.ts index f36eab9..073f891 100644 --- a/src/tasks/scenarios/project.ts +++ b/src/tasks/scenarios/project.ts @@ -8,6 +8,7 @@ import { download } from 'utils/request' export default class ProjectScenario extends Scenario { async setup(currentJobDir: string, job: ProjectJob) { + // check this. directory might be wrong const problemDir = path.join(currentJobDir, 'problem') mkdir('-p', problemDir) await download(job.problem, path.join(problemDir, 'problem')) @@ -26,16 +27,46 @@ export default class ProjectScenario extends Scenario { -v "${currentJobDir}":/usr/src/runbox \\ -w /usr/src/runbox codingblocks/project-worker-"${job.lang}" \\ /bin/judge.sh -s "${job.submissionDirs}" - `) + `); } async result(currentJobDir: string, job: ProjectJob): Promise { - // TODO + + const result_code = cat(path.join(currentJobDir, 'result.code')).toString() + + if (result_code) { + // problem hash and solution hash were not equal. // error + return { + id: job.id, + stderr: cat(path.join(currentJobDir, 'result.stderr')).toString(), + stdout: '', + code: parseInt(result_code), + time: 1, + score: 0 + } + } + + const build_stderr = cat(path.join(currentJobDir, 'build.stderr')).toString() + const stderr = build_stderr || cat((path.join(currentJobDir, 'run.stderr')).toString()) + + if (stderr) { + return { + id: job.id, + stderr: build_stderr, + stdout: '', + code: 12123, + time: 1, + score: 0 + } + } + + const build_stdout = cat(path.join(currentJobDir, 'build.stdout')).toString() + const stdout = build_stdout || cat(path.join(currentJobDir, 'run.stdout')).toString() return { id: job.id, stderr: '', - stdout: '', + stdout: stdout, time: 0, code: 0, score: 0 From 84573574bf8bffe1e8a0835bad5754477aa2727a Mon Sep 17 00:00:00 2001 From: PrabalSingh Date: Sat, 23 May 2020 19:33:40 +0530 Subject: [PATCH 3/8] install and use AdmZip --- package.json | 1 + src/tasks/scenarios/project.ts | 30 ++++++++++++++++++------------ 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/package.json b/package.json index 5e383b5..81962e2 100644 --- a/package.json +++ b/package.json @@ -19,6 +19,7 @@ "typescript": "^3.8.3" }, "dependencies": { + "adm-zip": "^0.4.14", "amqplib": "^0.5.2", "newrelic": "^6.5.0", "raven": "^2.6.4", diff --git a/src/tasks/scenarios/project.ts b/src/tasks/scenarios/project.ts index 073f891..aff57f4 100644 --- a/src/tasks/scenarios/project.ts +++ b/src/tasks/scenarios/project.ts @@ -5,35 +5,41 @@ import { ProjectResult } from 'types/result' import * as path from 'path' import { Scenario } from 'tasks/scenario' import { download } from 'utils/request' +const AdmZip = require('adm-zip') export default class ProjectScenario extends Scenario { async setup(currentJobDir: string, job: ProjectJob) { - // check this. directory might be wrong + + // for testing only, change it to download + var problemZip = new AdmZip('/judge-worker-prabal/current/problem.zip') + var solutionZip = new AdmZip('/judge-worker-prabal/current/solution.zip') + const problemDir = path.join(currentJobDir, 'problem') mkdir('-p', problemDir) - await download(job.problem, path.join(problemDir, 'problem')) + problemZip.extractAllTo(problemDir, true); const solutionDir = path.join(currentJobDir, 'solution') mkdir('-p', solutionDir) - await download(job.source, path.join(solutionDir, 'solution')) + solutionZip.extractAllTo(solutionDir, true); } run(currentJobDir: string, job: ProjectJob) { + + // LANG_CONFIG is undefined rn const LANG_CONFIG = config.LANGS[job.lang] return exec(`docker run \\ - --cpus="${LANG_CONFIG.CPU_SHARE}" \\ - --memory="${LANG_CONFIG.MEM_LIMIT}" \\ + --cpus="1" \\ + --memory="100m" \\ --rm \\ -v "${currentJobDir}":/usr/src/runbox \\ -w /usr/src/runbox codingblocks/project-worker-"${job.lang}" \\ - /bin/judge.sh -s "${job.submissionDirs}" + /bin/judge.sh -s "${job.submissionDirs} `); } async result(currentJobDir: string, job: ProjectJob): Promise { const result_code = cat(path.join(currentJobDir, 'result.code')).toString() - if (result_code) { // problem hash and solution hash were not equal. // error return { @@ -42,7 +48,7 @@ export default class ProjectScenario extends Scenario { stdout: '', code: parseInt(result_code), time: 1, - score: 0 + score: 12 } } @@ -52,11 +58,11 @@ export default class ProjectScenario extends Scenario { if (stderr) { return { id: job.id, - stderr: build_stderr, + stderr, stdout: '', code: 12123, time: 1, - score: 0 + score: 100 } } @@ -68,8 +74,8 @@ export default class ProjectScenario extends Scenario { stderr: '', stdout: stdout, time: 0, - code: 0, - score: 0 + code: 10, + score: 100 } } } From 91174fbcfb92af5a1f53bfbaad918152b59fc5ca Mon Sep 17 00:00:00 2001 From: PrabalSingh Date: Sat, 23 May 2020 21:26:35 +0530 Subject: [PATCH 4/8] improve project run --- src/tasks/scenarios/project.ts | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/src/tasks/scenarios/project.ts b/src/tasks/scenarios/project.ts index aff57f4..cb4ab85 100644 --- a/src/tasks/scenarios/project.ts +++ b/src/tasks/scenarios/project.ts @@ -25,7 +25,7 @@ export default class ProjectScenario extends Scenario { run(currentJobDir: string, job: ProjectJob) { - // LANG_CONFIG is undefined rn + // LANG_CONFIG is undefined rn, hence card coding the value of cpus and memory const LANG_CONFIG = config.LANGS[job.lang] return exec(`docker run \\ --cpus="1" \\ @@ -33,7 +33,7 @@ export default class ProjectScenario extends Scenario { --rm \\ -v "${currentJobDir}":/usr/src/runbox \\ -w /usr/src/runbox codingblocks/project-worker-"${job.lang}" \\ - /bin/judge.sh -s "${job.submissionDirs} + /bin/judge.sh -s "${job.submissionDirs}" `); } @@ -53,12 +53,10 @@ export default class ProjectScenario extends Scenario { } const build_stderr = cat(path.join(currentJobDir, 'build.stderr')).toString() - const stderr = build_stderr || cat((path.join(currentJobDir, 'run.stderr')).toString()) - - if (stderr) { + if (build_stderr) { return { id: job.id, - stderr, + stderr: build_stderr, stdout: '', code: 12123, time: 1, @@ -66,15 +64,16 @@ export default class ProjectScenario extends Scenario { } } - const build_stdout = cat(path.join(currentJobDir, 'build.stdout')).toString() - const stdout = build_stdout || cat(path.join(currentJobDir, 'run.stdout')).toString() + const stderr = cat((path.join(currentJobDir, 'run.stderr')).toString()) + const run_stdout = cat(path.join(currentJobDir, 'run.stdout')).toString() + // if code is set to 0, change the condition in judge-api queue logic return { id: job.id, - stderr: '', - stdout: stdout, + stderr: stderr, + stdout: run_stdout, time: 0, - code: 10, + code: 100, score: 100 } } From 1553455f76fb24860805d9bb33fa18315e338b1a Mon Sep 17 00:00:00 2001 From: root Date: Sat, 23 May 2020 21:36:19 +0530 Subject: [PATCH 5/8] refactor jobs --- src/tasks/index.ts | 7 +++-- src/tasks/job.ts | 45 +------------------------------ src/tasks/jobs/project.ts | 16 +++++++++++ src/tasks/jobs/run.ts | 14 ++++++++++ src/tasks/jobs/submission.ts | 20 ++++++++++++++ src/tasks/scenarios/project.ts | 4 +-- src/tasks/scenarios/run.ts | 4 +-- src/tasks/scenarios/submission.ts | 2 +- 8 files changed, 61 insertions(+), 51 deletions(-) create mode 100644 src/tasks/jobs/project.ts create mode 100644 src/tasks/jobs/run.ts create mode 100644 src/tasks/jobs/submission.ts diff --git a/src/tasks/index.ts b/src/tasks/index.ts index c5665ec..7e1744c 100644 --- a/src/tasks/index.ts +++ b/src/tasks/index.ts @@ -5,8 +5,11 @@ import * as path from 'path' import RunScenario from './scenarios/run' import SubmissionScenario from './scenarios/submission' -import ProjectScenario from './scenarios/project'; -import { RunJob, SubmitJob, ProjectJob, Job } from "./job"; +import ProjectScenario from './scenarios/project' +import {Job } from './job' +import {RunJob} from './jobs/run' +import {SubmitJob} from './jobs/submission'; +import {ProjectJob} from './jobs/project'; export function execute(job: RunJob): Promise export function execute(job: SubmitJob): Promise diff --git a/src/tasks/job.ts b/src/tasks/job.ts index 066e848..45a426a 100644 --- a/src/tasks/job.ts +++ b/src/tasks/job.ts @@ -1,26 +1,10 @@ -interface JobConstructorOpts { +export interface JobConstructorOpts { id: number source: string lang: string scenario: "run" | "submit" | "project" timelimit?: number } -interface RunJobConstructorOpts extends JobConstructorOpts { - stdin: string -} -interface TestcaseOpts { - id: number, - input: string, - output: string -} -interface SubmitJobConstructorOpts extends JobConstructorOpts { - testcases: Array -} - -interface ProjectConstructorOpts extends JobConstructorOpts { - problem: string, - submissionDirs: string -} export class Job { id: number @@ -38,31 +22,4 @@ export class Job { } } -export class RunJob extends Job { - stdin: string - - constructor({ id, source, lang, timelimit, scenario, stdin }: RunJobConstructorOpts) { - super({id, source, lang, timelimit, scenario}) - this.stdin = stdin - } -} -export class SubmitJob extends Job { - testcases: Array - - constructor({ id, source, lang, timelimit, scenario, testcases }: SubmitJobConstructorOpts) { - super({id, source, lang, timelimit, scenario}) - this.testcases = testcases - } -} - -export class ProjectJob extends Job { - problem: string - submissionDirs: string - - constructor({ id, source, lang, timelimit, scenario, problem, submissionDirs}: ProjectConstructorOpts) { - super({ id, source, lang, timelimit, scenario}) - this.problem = problem - this.submissionDirs = submissionDirs - } -} diff --git a/src/tasks/jobs/project.ts b/src/tasks/jobs/project.ts new file mode 100644 index 0000000..0734737 --- /dev/null +++ b/src/tasks/jobs/project.ts @@ -0,0 +1,16 @@ +import {Job, JobConstructorOpts} from '../job'; + +interface ProjectConstructorOpts extends JobConstructorOpts { + problem: string, + submissionDirs: string +} +export class ProjectJob extends Job { + problem: string + submissionDirs: string + + constructor({ id, source, lang, timelimit, scenario, problem, submissionDirs}: ProjectConstructorOpts) { + super({ id, source, lang, timelimit, scenario}) + this.problem = problem + this.submissionDirs = submissionDirs + } +} diff --git a/src/tasks/jobs/run.ts b/src/tasks/jobs/run.ts new file mode 100644 index 0000000..b8ae888 --- /dev/null +++ b/src/tasks/jobs/run.ts @@ -0,0 +1,14 @@ +import {Job, JobConstructorOpts} from '../job'; + +interface RunJobConstructorOpts extends JobConstructorOpts { + stdin: string +} + +export class RunJob extends Job { + stdin: string + + constructor({ id, source, lang, timelimit, scenario, stdin }: RunJobConstructorOpts) { + super({id, source, lang, timelimit, scenario}) + this.stdin = stdin + } +} \ No newline at end of file diff --git a/src/tasks/jobs/submission.ts b/src/tasks/jobs/submission.ts new file mode 100644 index 0000000..1b0239b --- /dev/null +++ b/src/tasks/jobs/submission.ts @@ -0,0 +1,20 @@ +import {Job, JobConstructorOpts} from '../job'; + +interface TestcaseOpts { + id: number, + input: string, + output: string +} + +interface SubmitJobConstructorOpts extends JobConstructorOpts { + testcases: Array +} + +export class SubmitJob extends Job { + testcases: Array + + constructor({ id, source, lang, timelimit, scenario, testcases }: SubmitJobConstructorOpts) { + super({id, source, lang, timelimit, scenario}) + this.testcases = testcases + } +} diff --git a/src/tasks/scenarios/project.ts b/src/tasks/scenarios/project.ts index cb4ab85..ceb8f9c 100644 --- a/src/tasks/scenarios/project.ts +++ b/src/tasks/scenarios/project.ts @@ -1,6 +1,6 @@ import config = require('../../../config.js') -import {cat, exec, mkdir, rm, touch, head} from 'shelljs' -import {ProjectJob} from 'tasks/job' +import { cat, exec, mkdir, rm, touch, head } from 'shelljs' +import { ProjectJob } from '../jobs/project' import { ProjectResult } from 'types/result' import * as path from 'path' import { Scenario } from 'tasks/scenario' diff --git a/src/tasks/scenarios/run.ts b/src/tasks/scenarios/run.ts index 53b32ab..2ee538d 100644 --- a/src/tasks/scenarios/run.ts +++ b/src/tasks/scenarios/run.ts @@ -1,6 +1,6 @@ import config = require('../../../config.js') -import {cat, exec, mkdir, rm, touch, head} from 'shelljs' -import { RunJob } from '../job' +import { cat, exec, mkdir, rm, touch, head } from 'shelljs' +import { RunJob} from '../jobs/run' import { RunResult } from 'types/result' import * as path from 'path' import * as fs from 'fs' diff --git a/src/tasks/scenarios/submission.ts b/src/tasks/scenarios/submission.ts index c805b1d..09e1e7f 100644 --- a/src/tasks/scenarios/submission.ts +++ b/src/tasks/scenarios/submission.ts @@ -1,6 +1,6 @@ import config = require('../../../config.js') import { cat, ls, mkdir, exec } from 'shelljs' -import { SubmitJob } from 'tasks/job' +import { SubmitJob } from '../jobs/submission' import { SubmissionResult } from 'types/result' import * as path from 'path' import * as fs from 'fs' From fda18c870818bd11238364f183cea0239445fa4a Mon Sep 17 00:00:00 2001 From: PrabalSingh Date: Mon, 25 May 2020 17:43:07 +0530 Subject: [PATCH 6/8] refactor run and use exec for extracting zip --- package.json | 1 - src/taskmaster.ts | 4 ++- src/tasks/scenarios/project.ts | 55 ++++++++++++++++------------------ 3 files changed, 29 insertions(+), 31 deletions(-) diff --git a/package.json b/package.json index 81962e2..5e383b5 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,6 @@ "typescript": "^3.8.3" }, "dependencies": { - "adm-zip": "^0.4.14", "amqplib": "^0.5.2", "newrelic": "^6.5.0", "raven": "^2.6.4", diff --git a/src/taskmaster.ts b/src/taskmaster.ts index f693deb..cf63298 100644 --- a/src/taskmaster.ts +++ b/src/taskmaster.ts @@ -4,7 +4,9 @@ import * as amqp from 'amqplib/callback_api' import {Connection} from 'amqplib/callback_api' import { execute } from './tasks' import config = require('../config.js') -import {SubmitJob, RunJob, ProjectJob} from 'tasks/job'; +import {SubmitJob} from './tasks/jobs/submission'; +import {ProjectJob} from './tasks/jobs/project'; +import {RunJob} from './tasks/jobs/run'; import { mkdir } from 'shelljs' // =============== Setup Raven diff --git a/src/tasks/scenarios/project.ts b/src/tasks/scenarios/project.ts index ceb8f9c..bb250e4 100644 --- a/src/tasks/scenarios/project.ts +++ b/src/tasks/scenarios/project.ts @@ -5,31 +5,28 @@ import { ProjectResult } from 'types/result' import * as path from 'path' import { Scenario } from 'tasks/scenario' import { download } from 'utils/request' -const AdmZip = require('adm-zip') export default class ProjectScenario extends Scenario { async setup(currentJobDir: string, job: ProjectJob) { - - // for testing only, change it to download - var problemZip = new AdmZip('/judge-worker-prabal/current/problem.zip') - var solutionZip = new AdmZip('/judge-worker-prabal/current/solution.zip') + const problemZipDir = path.join(currentJobDir, 'problem.zip') + const solutionZipDir = path.join(currentJobDir, 'solution.zip') + await download(job.problem, problemZipDir) + await download(job.source, solutionZipDir) const problemDir = path.join(currentJobDir, 'problem') mkdir('-p', problemDir) - problemZip.extractAllTo(problemDir, true); + exec(`unzip ${problemZipDir} -d ${problemDir}`) const solutionDir = path.join(currentJobDir, 'solution') mkdir('-p', solutionDir) - solutionZip.extractAllTo(solutionDir, true); + exec(`unzip ${solutionZipDir} -d ${solutionDir}`) } run(currentJobDir: string, job: ProjectJob) { - - // LANG_CONFIG is undefined rn, hence card coding the value of cpus and memory - const LANG_CONFIG = config.LANGS[job.lang] + const PROJECT_CONFIG = config.PROJECT[job.lang] return exec(`docker run \\ - --cpus="1" \\ - --memory="100m" \\ + --cpus="${PROJECT_CONFIG.CPU_SHARE}" \\ + --memory="${PROJECT_CONFIG.MEM_LIMIT}" \\ --rm \\ -v "${currentJobDir}":/usr/src/runbox \\ -w /usr/src/runbox codingblocks/project-worker-"${job.lang}" \\ @@ -38,43 +35,43 @@ export default class ProjectScenario extends Scenario { } async result(currentJobDir: string, job: ProjectJob): Promise { - - const result_code = cat(path.join(currentJobDir, 'result.code')).toString() + let result_code = cat(path.join(currentJobDir, 'result.code')).toString() if (result_code) { - // problem hash and solution hash were not equal. // error + //problem hash and solution hash were not equal return { id: job.id, stderr: cat(path.join(currentJobDir, 'result.stderr')).toString(), stdout: '', code: parseInt(result_code), - time: 1, - score: 12 + time: 0, + score: 0 } } + // if hashes were equal, result_code will be found inside solution directory + const solutionDir = path.join(currentJobDir, 'solution') + result_code = cat(path.join(solutionDir, 'result.code')).toString() + const result_time = cat(path.join(solutionDir, 'result.time')).toString() const build_stderr = cat(path.join(currentJobDir, 'build.stderr')).toString() + if (build_stderr) { return { id: job.id, stderr: build_stderr, stdout: '', - code: 12123, - time: 1, - score: 100 + code: parseInt(result_code), + time: parseFloat(result_time), + score: 0 } } - const stderr = cat((path.join(currentJobDir, 'run.stderr')).toString()) - const run_stdout = cat(path.join(currentJobDir, 'run.stdout')).toString() - - // if code is set to 0, change the condition in judge-api queue logic return { id: job.id, - stderr: stderr, - stdout: run_stdout, - time: 0, - code: 100, - score: 100 + stderr: cat((path.join(currentJobDir, 'run.stderr')).toString()), + stdout: cat(path.join(currentJobDir, 'run.stdout')).toString(), + code: parseInt(result_code), + time: parseFloat(result_time), + score: parseInt(result_code) === 0 ? 100 : 0 } } } From 0feb9b771716cf3189e4e360138be13f39e8e6cc Mon Sep 17 00:00:00 2001 From: PrabalSingh Date: Mon, 25 May 2020 18:43:35 +0530 Subject: [PATCH 7/8] result.time and result.code will be found in base --- src/tasks/scenarios/project.ts | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/src/tasks/scenarios/project.ts b/src/tasks/scenarios/project.ts index bb250e4..d944d0c 100644 --- a/src/tasks/scenarios/project.ts +++ b/src/tasks/scenarios/project.ts @@ -1,5 +1,5 @@ import config = require('../../../config.js') -import { cat, exec, mkdir, rm, touch, head } from 'shelljs' +import { cat, exec, mkdir} from 'shelljs' import { ProjectJob } from '../jobs/project' import { ProjectResult } from 'types/result' import * as path from 'path' @@ -35,24 +35,21 @@ export default class ProjectScenario extends Scenario { } async result(currentJobDir: string, job: ProjectJob): Promise { - let result_code = cat(path.join(currentJobDir, 'result.code')).toString() - if (result_code) { - //problem hash and solution hash were not equal - return { - id: job.id, - stderr: cat(path.join(currentJobDir, 'result.stderr')).toString(), - stdout: '', - code: parseInt(result_code), - time: 0, - score: 0 - } + const result_code = cat(path.join(currentJobDir, 'result.code')).toString() + if (result_code === '25') { + //problem hash and solution hash were not equal + return { + id: job.id, + stderr: cat(path.join(currentJobDir, 'result.stderr')).toString(), + stdout: '', + code: parseInt(result_code), + time: 0, + score: 0 + } } - // if hashes were equal, result_code will be found inside solution directory - const solutionDir = path.join(currentJobDir, 'solution') - result_code = cat(path.join(solutionDir, 'result.code')).toString() - const result_time = cat(path.join(solutionDir, 'result.time')).toString() const build_stderr = cat(path.join(currentJobDir, 'build.stderr')).toString() + const result_time = cat(path.join(currentJobDir, 'result.time').toString()) || '0' if (build_stderr) { return { From 9a24b9e2daa24552a0d2efdcee290ab8b576b510 Mon Sep 17 00:00:00 2001 From: root Date: Mon, 25 May 2020 19:26:45 +0530 Subject: [PATCH 8/8] test: fix imports due to refactoring of jobs --- test/run/run.c.spec.ts | 3 ++- test/run/run.cpp.spec.ts | 3 ++- test/run/run.csharp.spec.ts | 3 ++- test/run/run.java8.spec.ts | 3 ++- test/run/run.nodejs10.spec.ts | 3 ++- test/run/run.nodejs8.spec.ts | 3 ++- test/run/run.py2.spec.ts | 3 ++- test/run/run.py3.spec.ts | 3 ++- test/run/run.ruby.spec.ts | 3 ++- test/scenarios/projectScenario.spec.ts | 18 +++++++++--------- test/scenarios/runScenario.spec.ts | 2 +- test/scenarios/submissionScenario.spec.ts | 2 +- test/submission/submit.c.spec.ts | 2 +- test/submission/submit.cpp.spec.ts | 2 +- test/submission/submit.csharp.spec.ts | 2 +- test/submission/submit.java8.spec.ts | 2 +- test/submission/submit.nodejs10.spec.ts | 2 +- test/submission/submit.nodejs8.spec.ts | 2 +- test/submission/submit.py2.spec.ts | 2 +- test/submission/submit.py3.spec.ts | 2 +- test/submission/submit.ruby.spec.ts | 2 +- 21 files changed, 38 insertions(+), 29 deletions(-) diff --git a/test/run/run.c.spec.ts b/test/run/run.c.spec.ts index 3010a36..cd6e657 100644 --- a/test/run/run.c.spec.ts +++ b/test/run/run.c.spec.ts @@ -1,6 +1,7 @@ import {execute} from '../../src/tasks/' import {expect} from 'chai' -import { RunJob } from '../../src/tasks/job' +import {RunJob} from '../../src/tasks/jobs/run' + describe('run - c', () => { it('.c file runs correctly', async () => { const runResult = await execute(new RunJob({ diff --git a/test/run/run.cpp.spec.ts b/test/run/run.cpp.spec.ts index 8987b7b..ae02820 100644 --- a/test/run/run.cpp.spec.ts +++ b/test/run/run.cpp.spec.ts @@ -1,6 +1,7 @@ import {execute} from '../../src/tasks/' import {expect} from 'chai' -import { RunJob } from '../../src/tasks/job' +import {RunJob} from '../../src/tasks/jobs/run' + describe('run - cpp', () => { it('.cpp file runs correctly', async () => { diff --git a/test/run/run.csharp.spec.ts b/test/run/run.csharp.spec.ts index 6cb50b2..852363d 100644 --- a/test/run/run.csharp.spec.ts +++ b/test/run/run.csharp.spec.ts @@ -1,6 +1,7 @@ import {execute} from '../../src/tasks/' import {expect} from 'chai' -import { RunJob } from '../../src/tasks/job' +import {RunJob} from '../../src/tasks/jobs/run' + describe('run - csharp', () => { it('.cs file runs correctly', async () => { diff --git a/test/run/run.java8.spec.ts b/test/run/run.java8.spec.ts index 2017918..2083a0c 100644 --- a/test/run/run.java8.spec.ts +++ b/test/run/run.java8.spec.ts @@ -1,6 +1,7 @@ import {execute} from '../../src/tasks/' import {expect} from 'chai' -import { RunJob } from '../../src/tasks/job' +import {RunJob} from '../../src/tasks/jobs/run' + describe('run - java8', () => { it('.java file runs correctly (Java8)', async () => { diff --git a/test/run/run.nodejs10.spec.ts b/test/run/run.nodejs10.spec.ts index 50a90b1..d441947 100644 --- a/test/run/run.nodejs10.spec.ts +++ b/test/run/run.nodejs10.spec.ts @@ -1,6 +1,7 @@ import {execute} from '../../src/tasks/' import {expect} from 'chai' -import { RunJob } from '../../src/tasks/job' +import {RunJob} from '../../src/tasks/jobs/run' + describe('run - nodejs10', () => { it('.js file runs correctly (NodeJS 6)', async () => { const runResult = await execute(new RunJob({ diff --git a/test/run/run.nodejs8.spec.ts b/test/run/run.nodejs8.spec.ts index f55bb4b..42e5212 100644 --- a/test/run/run.nodejs8.spec.ts +++ b/test/run/run.nodejs8.spec.ts @@ -1,6 +1,7 @@ import {execute} from '../../src/tasks/' import {expect} from 'chai' -import { RunJob } from '../../src/tasks/job' +import {RunJob} from '../../src/tasks/jobs/run' + describe('run - nodejs8', () => { it('.js file runs correctly (NodeJS 8)', async () => { diff --git a/test/run/run.py2.spec.ts b/test/run/run.py2.spec.ts index 27a0d91..3e92d37 100644 --- a/test/run/run.py2.spec.ts +++ b/test/run/run.py2.spec.ts @@ -1,6 +1,7 @@ import {execute} from '../../src/tasks/' import {expect} from 'chai' -import { RunJob } from '../../src/tasks/job' +import {RunJob} from '../../src/tasks/jobs/run' + describe('run - py2', () => { it('.py file runs correctly (Python 2.7)', async () => { diff --git a/test/run/run.py3.spec.ts b/test/run/run.py3.spec.ts index 40f3a41..0a436dd 100644 --- a/test/run/run.py3.spec.ts +++ b/test/run/run.py3.spec.ts @@ -1,6 +1,7 @@ import {execute} from '../../src/tasks/' import {expect} from 'chai' -import { RunJob } from '../../src/tasks/job' +import {RunJob} from '../../src/tasks/jobs/run' + describe('run - py3', () => { it('.py file runs correctly (Python 3.0)', async () => { diff --git a/test/run/run.ruby.spec.ts b/test/run/run.ruby.spec.ts index 6358584..e60170f 100644 --- a/test/run/run.ruby.spec.ts +++ b/test/run/run.ruby.spec.ts @@ -1,6 +1,7 @@ import {execute} from '../../src/tasks/' import {expect} from 'chai' -import { RunJob } from '../../src/tasks/job' +import {RunJob} from '../../src/tasks/jobs/run' + describe('run - ruby', () => { it('.rb file runs correctly', async () => { diff --git a/test/scenarios/projectScenario.spec.ts b/test/scenarios/projectScenario.spec.ts index 710d7be..92a8fb3 100644 --- a/test/scenarios/projectScenario.spec.ts +++ b/test/scenarios/projectScenario.spec.ts @@ -1,16 +1,16 @@ import { expect } from 'chai' -import { ProjectJob } from '../../src/tasks/job' +import { ProjectJob } from '../../src/tasks/jobs/project'; import ProjectScenarion from '../../src/tasks/scenarios/project' describe('Project Scenario', () => { it('should setup', async () => { - const job: ProjectJob = { - id: 1, - source: '', - lang: 'nodejs', - timelimit: 20, - scenario: 'problem', - problem: '' - } + // const job: ProjectJob = { + // id: 1, + // source: '', + // lang: 'nodejs', + // timelimit: 20, + // scenario: 'problem', + // problem: '' + // } }) }) diff --git a/test/scenarios/runScenario.spec.ts b/test/scenarios/runScenario.spec.ts index 172a16e..ae1896d 100644 --- a/test/scenarios/runScenario.spec.ts +++ b/test/scenarios/runScenario.spec.ts @@ -3,7 +3,7 @@ import { mkdir, rm } from 'shelljs' import RunScenario from '../../src/tasks/scenarios/run' import config = require('../../config.js') import * as path from 'path' -import { RunJob } from '../../src/tasks/job' +import {RunJob} from '../../src/tasks/jobs/run' import * as fs from 'fs' describe('Run Scenario', () => { diff --git a/test/scenarios/submissionScenario.spec.ts b/test/scenarios/submissionScenario.spec.ts index 86e5ad6..303830a 100644 --- a/test/scenarios/submissionScenario.spec.ts +++ b/test/scenarios/submissionScenario.spec.ts @@ -4,7 +4,7 @@ import { mkdir, rm } from 'shelljs' import config = require('../../config.js') import * as path from 'path' import SubmissionScenario from '../../src/tasks/scenarios/submission' -import { SubmitJob } from '../../src/tasks/job' +import { SubmitJob } from '../../src/tasks/jobs/submission' describe('Submission Scenario', () => { it('should setup', async () => { diff --git a/test/submission/submit.c.spec.ts b/test/submission/submit.c.spec.ts index e42c72a..ce8018a 100644 --- a/test/submission/submit.c.spec.ts +++ b/test/submission/submit.c.spec.ts @@ -1,6 +1,6 @@ import { execute } from '../../src/tasks/' import { expect } from 'chai' -import { SubmitJob } from '../../src/tasks/job' +import { SubmitJob } from "../../src/tasks/jobs/submission" import { SubmissionResult } from '../../src/types/result' describe('submit - c', () => { diff --git a/test/submission/submit.cpp.spec.ts b/test/submission/submit.cpp.spec.ts index 39bd8c4..dce6063 100644 --- a/test/submission/submit.cpp.spec.ts +++ b/test/submission/submit.cpp.spec.ts @@ -1,6 +1,6 @@ import { execute } from '../../src/tasks/' import { expect } from 'chai' -import { SubmitJob } from '../../src/tasks/job' +import { SubmitJob } from "../../src/tasks/jobs/submission" import { SubmissionResult } from '../../src/types/result' describe('submit - cpp', () => { diff --git a/test/submission/submit.csharp.spec.ts b/test/submission/submit.csharp.spec.ts index 7bc2ed8..0593a5e 100644 --- a/test/submission/submit.csharp.spec.ts +++ b/test/submission/submit.csharp.spec.ts @@ -1,6 +1,6 @@ import { execute } from '../../src/tasks/' import { expect } from 'chai' -import { SubmitJob } from '../../src/tasks/job' +import { SubmitJob } from "../../src/tasks/jobs/submission" import { SubmissionResult } from '../../src/types/result' describe('submit - csharp', () => { diff --git a/test/submission/submit.java8.spec.ts b/test/submission/submit.java8.spec.ts index 87d175b..56434c2 100644 --- a/test/submission/submit.java8.spec.ts +++ b/test/submission/submit.java8.spec.ts @@ -1,6 +1,6 @@ import { execute } from '../../src/tasks/' import { expect } from 'chai' -import { SubmitJob } from '../../src/tasks/job' +import { SubmitJob } from "../../src/tasks/jobs/submission" import { SubmissionResult } from '../../src/types/result' describe('submit - java8', () => { diff --git a/test/submission/submit.nodejs10.spec.ts b/test/submission/submit.nodejs10.spec.ts index f7df9f1..204a443 100644 --- a/test/submission/submit.nodejs10.spec.ts +++ b/test/submission/submit.nodejs10.spec.ts @@ -1,6 +1,6 @@ import { execute } from '../../src/tasks/' import { expect } from 'chai' -import { SubmitJob } from '../../src/tasks/job' +import { SubmitJob } from "../../src/tasks/jobs/submission" import { SubmissionResult } from '../../src/types/result' describe('submit - nodejs10', () => { diff --git a/test/submission/submit.nodejs8.spec.ts b/test/submission/submit.nodejs8.spec.ts index 9ecf188..c80cf29 100644 --- a/test/submission/submit.nodejs8.spec.ts +++ b/test/submission/submit.nodejs8.spec.ts @@ -1,6 +1,6 @@ import { execute } from '../../src/tasks/' import { expect } from 'chai' -import { SubmitJob } from '../../src/tasks/job' +import { SubmitJob } from "../../src/tasks/jobs/submission" import { SubmissionResult } from '../../src/types/result' describe('submit - nodejs8', () => { diff --git a/test/submission/submit.py2.spec.ts b/test/submission/submit.py2.spec.ts index 9e260f2..e568eef 100644 --- a/test/submission/submit.py2.spec.ts +++ b/test/submission/submit.py2.spec.ts @@ -1,6 +1,6 @@ import { execute } from '../../src/tasks/' import { expect } from 'chai' -import { SubmitJob } from '../../src/tasks/job' +import { SubmitJob } from "../../src/tasks/jobs/submission" import { SubmissionResult } from '../../src/types/result' describe('submit - py2', () => { diff --git a/test/submission/submit.py3.spec.ts b/test/submission/submit.py3.spec.ts index 9898431..6695fdb 100644 --- a/test/submission/submit.py3.spec.ts +++ b/test/submission/submit.py3.spec.ts @@ -1,6 +1,6 @@ import { execute } from '../../src/tasks/' import { expect } from 'chai' -import { SubmitJob } from '../../src/tasks/job' +import { SubmitJob } from "../../src/tasks/jobs/submission" import { SubmissionResult } from '../../src/types/result' describe('submit - py3', () => { diff --git a/test/submission/submit.ruby.spec.ts b/test/submission/submit.ruby.spec.ts index c5c5702..51762b4 100644 --- a/test/submission/submit.ruby.spec.ts +++ b/test/submission/submit.ruby.spec.ts @@ -1,6 +1,6 @@ import { execute } from '../../src/tasks/' import { expect } from 'chai' -import { SubmitJob } from '../../src/tasks/job' +import { SubmitJob } from "../../src/tasks/jobs/submission" import { SubmissionResult } from '../../src/types/result' describe('submit - ruby', () => {