-
Notifications
You must be signed in to change notification settings - Fork 1
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 #61 from CodeGrade/refactor/more-informative-job-s…
…tatus Refactor: More Informative Job Status
- Loading branch information
Showing
20 changed files
with
137 additions
and
47 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
15 changes: 15 additions & 0 deletions
15
orchestrator/packages/api/src/controllers/holding-pen-controller.ts
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,15 @@ | ||
import { Request, Response } from "express"; | ||
import { errorResponse } from "./utils"; | ||
import { jobConfigInHoldingPen } from "@codegrade-orca/db"; | ||
|
||
export const holdingPenStatus = async (req: Request, res: Response) => { | ||
const jobConfigID = parseInt(req.params.jobConfigID); | ||
if (isNaN(jobConfigID)) { | ||
return errorResponse(res, 400, [`Given job config ID ${jobConfigID} is not a number.`]); | ||
} | ||
if (await jobConfigInHoldingPen(jobConfigID)) { | ||
res.json("This job is waiting of a grader image to build."); | ||
} else { | ||
res.json("This job could not be found in a holding pen. Please contact an admin or professor."); | ||
} | ||
} |
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,8 @@ | ||
import { Router } from "express"; | ||
import { holdingPenStatus } from "../controllers/holding-pen-controller"; | ||
|
||
const holdingPenRouter = Router(); | ||
|
||
holdingPenRouter.get("/holding_pen/:jobConfigID/status", holdingPenStatus); | ||
|
||
export default holdingPenRouter; |
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,3 +1,4 @@ | ||
export * from "./grading-queue"; | ||
export * from "./image-build-service"; | ||
export * from "./job-result"; | ||
export * from "./job-status"; |
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,4 @@ | ||
export interface JobStatus { | ||
location: "HoldingPen" | "Queue", | ||
id: number, | ||
}; |
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 @@ | ||
export * from './push-status-update'; |
12 changes: 12 additions & 0 deletions
12
orchestrator/packages/common/src/utils/push-status-update.ts
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,12 @@ | ||
import { JobStatus } from "../types"; | ||
|
||
export const pushStatusUpdate = async (status: JobStatus, responseURL: string, key: string): Promise<void> => { | ||
// NOTE: This is meant to be 'fire-and-forget,' -- we don't care about errors | ||
// beyond logging. | ||
try { | ||
const body = JSON.stringify({ key, status }); | ||
await fetch(responseURL, { body, method: 'POST', headers: { 'Content-Type': 'application/json' } }); | ||
} catch (err) { | ||
console.error(`Could not POST status update to ${responseURL}; ${err instanceof Error ? err.message : err}`); | ||
} | ||
}; |
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,4 @@ | ||
import prismaInstance from '../prisma-instance'; | ||
|
||
export const jobConfigInHoldingPen = async (jobConfigID: number): Promise<boolean> => | ||
Boolean(await prismaInstance.jobConfigAwaitingImage.count({ where: { id: jobConfigID } })); |
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,5 +1,6 @@ | ||
export * from "./exceptions"; | ||
export * from "./server-operations"; | ||
export * from "./image-builder-operations"; | ||
export * from "./holding-pen-operations"; | ||
export * from "./shared"; | ||
export * from "./api-key-operations"; |
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
Oops, something went wrong.