|
1 | 1 | import {Response, Router, Request} from 'express' |
2 | 2 | import axios from 'axios' |
3 | 3 |
|
4 | | -import {SubmissionAttributes, Submissions} from '../../db/models' |
| 4 | +import {SubmissionAttributes, Submissions, db} from '../../db/models' |
5 | 5 | import {RunJob, queueJob, successListener} from '../../rabbitmq/jobqueue' |
6 | 6 | import {isInvalidRunRequest} from '../../validators/SubmissionValidators' |
| 7 | +import {upload} from '../../utils/s3' |
7 | 8 | import config = require('../../../config') |
8 | 9 |
|
9 | 10 | const route: Router = Router() |
@@ -58,7 +59,22 @@ const handleSuccessForSubmission = function (result: RunResponse) { |
58 | 59 | break; |
59 | 60 | case 'callback': |
60 | 61 | // send a post request to callback |
61 | | - axios.post(job.callback, result) |
| 62 | + (async () => { |
| 63 | + // 1. upload the result to s3 and get the url |
| 64 | + const {url} = await upload(result) |
| 65 | + |
| 66 | + // 2. save the url in db |
| 67 | + await Submissions.update({ |
| 68 | + outputs: [url] |
| 69 | + }, { |
| 70 | + where: { |
| 71 | + id: result.id |
| 72 | + } |
| 73 | + }) |
| 74 | + |
| 75 | + // make the callback request |
| 76 | + await axios.post(job.callback, {id: result.id, outputs: [url]}) |
| 77 | + })() |
62 | 78 | break; |
63 | 79 | } |
64 | 80 | } |
@@ -112,6 +128,13 @@ const getRunPoolElement = function (body: RunRequestBody, res: Response): RunPoo |
112 | 128 | * } |
113 | 129 | * @apiSuccessExample {JSON} Success-Response(mode=callback): |
114 | 130 | * HTTP/1.1 200 OK |
| 131 | + * |
| 132 | + * @apiSuccessExample {JSON} Body for Callback(mode=callback): |
| 133 | + * HTTP/1.1 200 OK |
| 134 | + * { |
| 135 | + * "id": 10, |
| 136 | + * "outputs": ["http://localhost/judge-submissions/file.json"] |
| 137 | + * } |
115 | 138 | */ |
116 | 139 | route.post('/', (req, res, next) => { |
117 | 140 | const invalidRequest = isInvalidRunRequest(req) |
|
0 commit comments