Skip to content

Commit 17cf23c

Browse files
author
williams-jack
committed
feat: replace all calls to redis with new db package
1 parent e26370c commit 17cf23c

File tree

19 files changed

+84
-502
lines changed

19 files changed

+84
-502
lines changed

orchestrator/packages/api/src/controllers/docker-image-controller.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,22 @@
11
import { Request, Response } from "express";
22
import { errorResponse } from "./utils";
33
import {
4-
GradingQueueOperationError,
54
validations,
65
} from "@codegrade-orca/common";
7-
import enqueueImageBuild from "../grading-queue/mutations/enqueue-image-build";
6+
import { GradingQueueOperationException, enqueueImageBuild } from "@codegrade-orca/db";
87

98
export const createGraderImage = async (req: Request, res: Response) => {
10-
console.log("This works.");
119
if (!validations.graderImageBuildRequest(req.body)) {
1210
return errorResponse(res, 400, [
1311
"The request body to build a grader image is invalid.",
1412
]);
1513
}
16-
console.log("This req was valid.");
1714
try {
1815
await enqueueImageBuild(req.body);
1916
return res.status(200).json({ message: "OK" });
2017
} catch (error) {
21-
if (error instanceof GradingQueueOperationError) {
18+
console.error(error);
19+
if (error instanceof GradingQueueOperationException) {
2220
return errorResponse(res, 400, [error.message]);
2321
} else {
2422
return errorResponse(res, 500, [

orchestrator/packages/api/src/controllers/grading-queue-controller.ts

Lines changed: 28 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,20 @@ import {
66
} from "../utils/pagination";
77
import { validateFilterRequest } from "../utils/validate";
88
import { errorResponse } from "./utils";
9-
import { GradingJobRequestError } from "./exceptions";
10-
import getAllGradingJobs from "../grading-queue/queries/get-grading-jobs";
119
import {
1210
GradingJob,
13-
GradingQueueOperationError,
1411
filterGradingJobs,
1512
getFilterInfo,
1613
getGradingQueueStats,
1714
validations,
1815
} from "@codegrade-orca/common";
19-
import mutations from "../grading-queue/mutations";
16+
import {
17+
deleteJob as deleteJobInQueue,
18+
createOrUpdateJob as putJobInQueue,
19+
getAllGradingJobs,
20+
GradingQueueOperationException
21+
} from "@codegrade-orca/db";
22+
import { isNaN } from "lodash";
2023

2124
export const getGradingJobs = async (req: Request, res: Response) => {
2225
if (
@@ -89,7 +92,7 @@ export const getGradingJobs = async (req: Request, res: Response) => {
8992
filter_info: filterInfo,
9093
});
9194
} catch (err) {
92-
if (err instanceof GradingQueueOperationError) {
95+
if (err instanceof GradingQueueOperationException) {
9396
return errorResponse(res, 400, [err.message]);
9497
}
9598
return errorResponse(res, 500, [
@@ -108,11 +111,11 @@ export const createOrUpdateImmediateJob = async (
108111
const gradingJobConfig = req.body;
109112

110113
try {
111-
await mutations.createOrUpdateJob(gradingJobConfig, Date.now(), true);
114+
await putJobInQueue(req.body, true);
112115
return res.status(200).json({ message: "OK" });
113116
} catch (error) {
114117
console.error(error);
115-
if (error instanceof GradingQueueOperationError) {
118+
if (error instanceof GradingQueueOperationException) {
116119
return errorResponse(res, 400, [error.message]);
117120
}
118121
return errorResponse(res, 500, [
@@ -127,13 +130,12 @@ export const createOrUpdateJob = async (req: Request, res: Response) => {
127130
return errorResponse(res, 400, ["The given grading job was invalid."]);
128131
}
129132

130-
const gradingJobConfig = req.body;
131-
132133
try {
133-
await mutations.createOrUpdateJob(gradingJobConfig, Date.now(), false);
134+
await putJobInQueue(req.body, false);
134135
return res.status(200).json({ message: "OK" });
135136
} catch (err) {
136-
if (err instanceof GradingQueueOperationError) {
137+
console.error(err);
138+
if (err instanceof GradingQueueOperationException) {
137139
return errorResponse(res, 400, [err.message]);
138140
} else {
139141
return errorResponse(res, 500, [
@@ -143,34 +145,27 @@ export const createOrUpdateJob = async (req: Request, res: Response) => {
143145
}
144146
};
145147

146-
export const moveJob = async (req: Request, res: Response) => {
147-
if (!validations.moveJobRequest(req.body)) {
148-
errorResponse(res, 400, ["Invalid move request."]);
149-
return;
150-
}
151-
try {
152-
await mutations.moveJob(req.body);
153-
return res.status(200).json("OK");
154-
} catch (err) {
155-
if (err instanceof GradingQueueOperationError) {
156-
return errorResponse(res, 500, [err.message]);
157-
}
158-
return errorResponse(res, 500, [
159-
`An error occurred while trying to move job with key ${req.body.orcaKey}.`,
160-
]);
161-
}
148+
export const moveJob = async (_req: Request, res: Response) => {
149+
return errorResponse(res, 500, ["Functionality to move a job remains to be implemented. " +
150+
"Please contact [email protected] for more info."]);
151+
// if (!validations.moveJobRequest(req.body)) {
152+
// errorResponse(res, 400, ["Invalid move request."]);
153+
// return;
154+
// }
162155
};
163156

164157
export const deleteJob = async (req: Request, res: Response) => {
165-
if (!validations.deleteJobRequest(req.body)) {
166-
return errorResponse(res, 400, ["Invalid delete request."]);
167-
}
158+
const { jobID: rawJobID } = req.params;
168159
try {
169-
await mutations.deleteJob(req.body);
160+
const jobID = parseInt(rawJobID);
161+
if (isNaN(jobID)) {
162+
return errorResponse(res, 400, ["Given job ID is not a number."]);
163+
}
164+
await deleteJobInQueue(jobID);
170165
return res.status(200).json({ message: "OK" });
171166
} catch (err) {
172-
if (err instanceof GradingQueueOperationError) {
173-
return errorResponse(res, 500, [err.message]);
167+
if (err instanceof GradingQueueOperationException) {
168+
return errorResponse(res, 400, [err.message]);
174169
} else {
175170
return errorResponse(res, 500, [
176171
`Something went wrong when trying to delete job with key ${req.body.orcaKey}.`,

orchestrator/packages/api/src/grading-queue/mutations/create-or-update-job.ts

Lines changed: 0 additions & 69 deletions
This file was deleted.

orchestrator/packages/api/src/grading-queue/mutations/delete-job.ts

Lines changed: 0 additions & 40 deletions
This file was deleted.

orchestrator/packages/api/src/grading-queue/mutations/enqueue-image-build.ts

Lines changed: 0 additions & 26 deletions
This file was deleted.

orchestrator/packages/api/src/grading-queue/mutations/index.ts

Lines changed: 0 additions & 11 deletions
This file was deleted.

orchestrator/packages/api/src/grading-queue/mutations/move-job.ts

Lines changed: 0 additions & 81 deletions
This file was deleted.

0 commit comments

Comments
 (0)