-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #43 from prabalsingh24/project-worker-prabal
feature: ProjectWorker
- Loading branch information
Showing
30 changed files
with
163 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import {Job, JobConstructorOpts} from '../job'; | ||
|
||
interface TestcaseOpts { | ||
id: number, | ||
input: string, | ||
output: string | ||
} | ||
|
||
interface SubmitJobConstructorOpts extends JobConstructorOpts { | ||
testcases: Array<TestcaseOpts> | ||
} | ||
|
||
export class SubmitJob extends Job { | ||
testcases: Array<TestcaseOpts> | ||
|
||
constructor({ id, source, lang, timelimit, scenario, testcases }: SubmitJobConstructorOpts) { | ||
super({id, source, lang, timelimit, scenario}) | ||
this.testcases = testcases | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,74 @@ | ||
import config = require('../../../config.js') | ||
import {cat, exec, mkdir, rm, touch, head} from 'shelljs' | ||
import { ProjectJob } from 'tasks/job' | ||
import { cat, exec, mkdir} from 'shelljs' | ||
import { ProjectJob } from '../jobs/project' | ||
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 problemZipDir = path.join(currentJobDir, 'problem.zip') | ||
const solutionZipDir = path.join(currentJobDir, 'solution.zip') | ||
await download(job.problem, problemZipDir) | ||
await download(job.source, solutionZipDir) | ||
|
||
const solutionDir = path.join(currentJobDir, job.source) | ||
await download(job.problem, solutionDir) | ||
const problemDir = path.join(currentJobDir, 'problem') | ||
mkdir('-p', problemDir) | ||
exec(`unzip ${problemZipDir} -d ${problemDir}`) | ||
|
||
const solutionDir = path.join(currentJobDir, 'solution') | ||
mkdir('-p', solutionDir) | ||
exec(`unzip ${solutionZipDir} -d ${solutionDir}`) | ||
} | ||
|
||
run(currentJobDir: string, job: ProjectJob) { | ||
const PROJECT_CONFIG = config.PROJECT[job.lang] | ||
return exec(`docker run \\ | ||
--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}" \\ | ||
/bin/judge.sh -s "${job.submissionDirs}" | ||
`); | ||
} | ||
|
||
async result(currentJobDir: string, job: ProjectJob): Promise<ProjectResult> { | ||
// TODO | ||
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 | ||
} | ||
} | ||
|
||
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 { | ||
id: job.id, | ||
stderr: build_stderr, | ||
stdout: '', | ||
code: parseInt(result_code), | ||
time: parseFloat(result_time), | ||
score: 0 | ||
} | ||
} | ||
|
||
return { | ||
id: job.id, | ||
stderr: '', | ||
stdout: '', | ||
time: 0, | ||
code: 0, | ||
score: 0 | ||
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 | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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: '' | ||
// } | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.