Compare commits
No commits in common. "160832fb935e1697de8772e136f866b93a4246af" and "1835ab5cab354e79f05e052b4c58c3ecc2ba9617" have entirely different histories.
160832fb93
...
1835ab5cab
|
@ -114,13 +114,6 @@ const options = [
|
|||
'https://github.com/engineer-man/piston/releases/download/pkgs/index',
|
||||
validators: [],
|
||||
},
|
||||
{
|
||||
key: 'max_concurrent_jobs',
|
||||
desc: 'Maximum number of concurrent jobs to run at one time',
|
||||
default: 64,
|
||||
parser: parse_int,
|
||||
validators: [(x) => x > 0 || `${x} cannot be negative`]
|
||||
}
|
||||
];
|
||||
|
||||
logger.info(`Loading Configuration from environment`);
|
||||
|
|
|
@ -16,19 +16,6 @@ const job_states = {
|
|||
let uid = 0;
|
||||
let gid = 0;
|
||||
|
||||
let remainingJobSpaces = config.max_concurrent_jobs;
|
||||
let jobQueue = [];
|
||||
|
||||
|
||||
setInterval(()=>{
|
||||
// Every 10ms try resolve a new job, if there is an available slot
|
||||
if(jobQueue.length > 0 && remainingJobSpaces > 0){
|
||||
jobQueue.shift()()
|
||||
}
|
||||
}, 10)
|
||||
|
||||
|
||||
|
||||
class Job {
|
||||
constructor({ runtime, files, args, stdin, timeouts, memory_limits }) {
|
||||
this.uuid = uuidv4();
|
||||
|
@ -61,15 +48,8 @@ class Job {
|
|||
}
|
||||
|
||||
async prime() {
|
||||
if(remainingJobSpaces < 1){
|
||||
logger.info(`Awaiting job slot uuid=${this.uuid}`)
|
||||
await new Promise((resolve)=>{
|
||||
jobQueue.push(resolve)
|
||||
})
|
||||
}
|
||||
|
||||
logger.info(`Priming job uuid=${this.uuid}`);
|
||||
remainingJobSpaces--;
|
||||
|
||||
logger.debug('Writing files to job cache');
|
||||
|
||||
logger.debug(`Transfering ownership uid=${this.uid} gid=${this.gid}`);
|
||||
|
@ -172,23 +152,21 @@ class Job {
|
|||
}
|
||||
});
|
||||
|
||||
const exit_cleanup = async () => {
|
||||
const exit_cleanup = () => {
|
||||
clear_timeout(kill_timeout);
|
||||
|
||||
proc.stderr.destroy();
|
||||
proc.stdout.destroy();
|
||||
|
||||
await this.cleanup_processes()
|
||||
};
|
||||
|
||||
proc.on('exit', async (code, signal) => {
|
||||
await exit_cleanup();
|
||||
proc.on('exit', (code, signal) => {
|
||||
exit_cleanup();
|
||||
|
||||
resolve({stdout, stderr, code, signal, output });
|
||||
});
|
||||
|
||||
proc.on('error', async err => {
|
||||
await exit_cleanup();
|
||||
proc.on('error', err => {
|
||||
exit_cleanup();
|
||||
|
||||
reject({ error: err, stdout, stderr, output });
|
||||
});
|
||||
|
@ -361,13 +339,11 @@ class Job {
|
|||
async cleanup() {
|
||||
logger.info(`Cleaning up job uuid=${this.uuid}`);
|
||||
|
||||
await this.cleanup_processes();
|
||||
await this.cleanup_filesystem();
|
||||
|
||||
remainingJobSpaces++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
module.exports = {
|
||||
Job,
|
||||
};
|
||||
|
|
|
@ -145,12 +145,3 @@ default: https://github.com/engineer-man/piston/releases/download/pkgs/index
|
|||
```
|
||||
|
||||
URL for repository index, where packages will be downloaded from.
|
||||
|
||||
## Maximum Concurrent Jobs
|
||||
|
||||
```yaml
|
||||
key: PISTON_MAX_CONCURRENT_JOBS
|
||||
default: 64
|
||||
```
|
||||
|
||||
Maximum number of jobs to run concurrently.
|
||||
|
|
Loading…
Reference in New Issue