Skip to content

Commit

Permalink
fix: add type prop to job result dicts
Browse files Browse the repository at this point in the history
  • Loading branch information
williams-jack committed Jul 3, 2024
1 parent b4d52eb commit eaf190e
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 28 deletions.
1 change: 1 addition & 0 deletions orchestrator/packages/api/src/controllers/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export const errorResponse = (

export const notifyClientOfCancelledJob = async (jobConfig: GradingJobConfig) => {
const result: GradingJobResult = {
type: "GradingJobResult",
shell_responses: [],
errors: ["Job cancelled by a course professor or Orca admin."]
};
Expand Down
61 changes: 34 additions & 27 deletions worker/orca_grader/common/grading_job/grading_job_result.py
Original file line number Diff line number Diff line change
@@ -1,31 +1,38 @@
from typing import List, Optional
from orca_grader.container.grading_script.grading_script_command_response import GradingScriptCommandResponse
from orca_grader.common.types.grading_job_json_types import GradingJobOutputJSON, GradingJobOutputJSON
from orca_grader.common.types.grading_job_json_types import GradingJobResultJSON, GradingJobResultJSON

This comment has been minimized.

Copy link
@blerner

blerner Jul 4, 2024

Collaborator

This looks like a typo (duplication)



class GradingJobResult:

def __init__(self, command_responses: List[GradingScriptCommandResponse],
execution_errors: List[Exception] = [],
output: str = None) -> None:
self.__command_responses = command_responses
self.__execution_errors = execution_errors
self.__output = output

def get_command_responses(self) -> List[GradingScriptCommandResponse]:
return self.__command_responses

def get_output(self) -> Optional[str]:
return self.__output

def get_execution_errors(self) -> List[Exception]:
return self.__execution_errors

def to_json(self) -> GradingJobOutputJSON:
result = dict()
json_responses = list(map(lambda c: c.to_json(), self.__command_responses))
result["shell_responses"] = json_responses
if self.__execution_errors is not None:
result["errors"] = list(map(lambda e: f"{e.__class__.__name__}: {e}", self.__execution_errors))
if self.__output is not None:
result["output"] = self.__output
return result

def __init__(self, command_responses: List[GradingScriptCommandResponse],
execution_errors: List[Exception] = [],
output: str = None) -> None:
self.__command_responses = command_responses
self.__execution_errors = execution_errors
self.__output = output

def get_command_responses(self) -> List[GradingScriptCommandResponse]:
return self.__command_responses

def get_output(self) -> Optional[str]:
return self.__output

def get_execution_errors(self) -> List[Exception]:
return self.__execution_errors

def to_json(self) -> GradingJobResultJSON:
result = {"type": "GradingJobResult"}

This comment has been minimized.

Copy link
@blerner

blerner Jul 4, 2024

Collaborator

Is this the only line of code that changed in this entire block?

This comment has been minimized.

Copy link
@williams-jack

williams-jack Jul 4, 2024

Author Collaborator

Yes, I ran a formatter on this file but looks like GitHub isn't rendering it as an excludable White-space change

json_responses = list(
map(lambda c: c.to_json(), self.__command_responses))
result["shell_responses"] = json_responses
if self.__execution_errors is not None:
result["errors"] = list(
map(
lambda e: f"{e.__class__.__name__}: {e}",
self.__execution_errors
)
)
if self.__output is not None:
result["output"] = self.__output
return result
2 changes: 1 addition & 1 deletion worker/orca_grader/common/types/grading_job_json_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

GradingJobJSON = Dict[Any, Any]
GradingScriptCommandJSON = Dict[str, Any]
GradingJobOutputJSON = Dict[str, Any]
GradingJobResultJSON = Dict[str, Any]
CodeFileInfoJSON = Dict[str, str]

0 comments on commit eaf190e

Please sign in to comment.