11import * as amqp from 'amqplib/callback_api'
2- import { Channel , Connection } from 'amqplib/callback_api'
3- import { EventEmitter } from 'events'
4- import { RunResponse } from '../routes/api/run'
2+ import { Channel , Connection } from 'amqplib/callback_api'
3+ import { EventEmitter } from 'events'
54const debug = require ( 'debug' ) ( 'judge:api:jobqueue' )
65import config = require( '../../config' )
76
87export interface SubmissionJob {
98 id : number
109 source : string ,
1110 lang : string ,
12- testcases : [ { input : string , output : string } ] ,
13- getstdout : boolean
11+ timelimit : number ,
12+ testcases : [ {
13+ id : number ,
14+ stdin : string ,
15+ stodut : string
16+ } ] ,
1417}
1518
1619export interface RunJob {
@@ -36,18 +39,18 @@ amqp.connect(`amqp://${config.AMQP.USER}:${config.AMQP.PASS}@${config.AMQP.HOST}
3639 ( err , connection ) => {
3740 if ( err ) throw err
3841
39- connection . createChannel ( ( err , channel ) => {
42+ connection . createChannel ( ( err , channel ) => {
4043 if ( err ) throw err
4144
42- channel . assertQueue ( jobQ , { durable : true } )
43- channel . assertQueue ( successQ , { durable : true } )
45+ channel . assertQueue ( jobQ , { durable : true } )
46+ channel . assertQueue ( successQ , { durable : true } )
4447 jobChannel = channel
4548 jobChannel . consume ( successQ , ( msg ) => {
4649 debug ( `SUCCESS:CONSUME: msg.content = ${ msg . content . toString ( ) } ` )
4750
4851 const payload = JSON . parse ( msg . content . toString ( ) )
4952 const eventName = payload . testcases ? 'submit_result' : 'run_result'
50-
53+
5154 successListener . emit ( eventName , payload )
5255 jobChannel . ack ( msg )
5356 } )
@@ -60,7 +63,7 @@ amqp.connect(`amqp://${config.AMQP.USER}:${config.AMQP.PASS}@${config.AMQP.HOST}
6063 * @returns {boolean } true if job was put on queue successfully
6164 */
6265function queueJob ( job : JudgeJob ) {
63- return jobChannel . sendToQueue ( jobQ , Buffer . from ( JSON . stringify ( job ) ) , { persistent : true } )
66+ return jobChannel . sendToQueue ( jobQ , Buffer . from ( JSON . stringify ( job ) ) , { persistent : true } )
6467}
6568export {
6669 queueJob ,
0 commit comments