-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refact: API 스키마 및 에러 핸들링 개선 #38
Merged
Merged
Changes from 3 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
ebd8e99
feat: 개발용 도커 파일 추가
minkyu97 6ee22ad
refact: serde 속성 사용하여 응답 스키마 생성 로직 단순화
minkyu97 bd83edf
feat: futures 크레이트 사용하여 async panic 핸들링
minkyu97 8e3b197
fix test
minkyu97 1768980
Merge remote-tracking branch 'origin/main' into refactor/api-schema-a…
minkyu97 9a08af5
rename: Dockerfile.dev -> Dockerfile.local
minkyu97 25fd342
Merge remote-tracking branch 'origin/main' into refactor/api-schema-a…
minkyu97 6bf463d
Revert "rename: Dockerfile.dev -> Dockerfile.local"
minkyu97 3ffd31c
rename: Dockerfile.dev -> Dockerfile.local
minkyu97 d297177
Merge remote-tracking branch 'origin/main' into refactor/api-schema-a…
minkyu97 5bc8fe9
fix: MarkResultStatus 변경사항 대응
minkyu97 17e56cf
fix test
minkyu97 4922b9f
fix test 2
minkyu97 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,41 @@ | ||
# Isolate builder | ||
FROM debian:12.6-slim AS isolate-builder | ||
|
||
# install isolate | ||
RUN apt-get update && apt-get --no-install-recommends install -y \ | ||
git build-essential pkg-config libcap-dev | ||
RUN git config --global http.sslVerify false | ||
RUN git clone --depth 1 --branch v2.0 https://github.com/ioi/isolate.git /usr/src/isolate | ||
WORKDIR /usr/src/isolate | ||
RUN make isolate | ||
|
||
# Dev image | ||
# docker run -it --rm -v $PWD:/usr/src/hodu --privileged -p 8080:8080 hodu-dev | ||
FROM rust:1.80.0-slim AS runner | ||
|
||
# should run docker with `-v $PWD:/usr/src/hodu` | ||
WORKDIR /usr/src/hodu | ||
RUN cargo install cargo-watch | ||
|
||
# install language specific tools | ||
RUN apt-get update && apt-get --no-install-recommends install -y \ | ||
# language: c | ||
gcc libc6-dev \ | ||
# language: c++ | ||
g++ \ | ||
# language: java | ||
openjdk-17-jdk \ | ||
# language: python | ||
python3 \ | ||
# language: javascript | ||
nodejs \ | ||
# clean | ||
&& rm -rf /var/lib/apt/lists/* \ | ||
&& apt-get clean | ||
|
||
# copy bin | ||
COPY --from=isolate-builder /usr/src/isolate/isolate /usr/local/bin/isolate | ||
COPY --from=isolate-builder /usr/src/isolate/isolate-check-environment /usr/local/bin/isolate-check-environment | ||
COPY --from=isolate-builder /usr/src/isolate/default.cf /usr/local/etc/isolate | ||
|
||
ENTRYPOINT ["cargo", "watch", "-x", "run"] |
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,28 +1,30 @@ | ||
use actix_web::{http::StatusCode, HttpResponse, ResponseError}; | ||
use serde::Serialize; | ||
|
||
#[derive(thiserror::Error, Debug)] | ||
#[derive(thiserror::Error, Debug, Serialize)] | ||
#[serde(rename_all = "SCREAMING_SNAKE_CASE", tag = "detail")] | ||
pub enum JudgeError { | ||
#[error("PayloadParseError: {0}")] | ||
PayloadParseError(#[source] actix_web::Error), | ||
} | ||
|
||
#[derive(Serialize, Debug)] | ||
struct JudgeErrorResponse { | ||
detail: String, | ||
PayloadParseError( | ||
#[source] | ||
#[serde(skip)] | ||
actix_web::Error, | ||
), | ||
#[error("HoduCoreError")] | ||
HoduCoreError, | ||
} | ||
|
||
impl ResponseError for JudgeError { | ||
fn status_code(&self) -> StatusCode { | ||
match self { | ||
JudgeError::PayloadParseError(_) => StatusCode::BAD_REQUEST, | ||
JudgeError::HoduCoreError => StatusCode::INTERNAL_SERVER_ERROR, | ||
} | ||
} | ||
|
||
fn error_response(&self) -> HttpResponse { | ||
let status_code = self.status_code(); | ||
let detail = self.to_string(); | ||
let error_response = JudgeErrorResponse { detail }; | ||
let error_response = self; | ||
HttpResponse::build(status_code).json(error_response) | ||
} | ||
} |
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,6 +1,10 @@ | ||
use std::panic::AssertUnwindSafe; | ||
|
||
use actix_web::{post, web, Responder}; | ||
use hodu_core::{mark, MarkParams}; | ||
|
||
use futures::FutureExt; | ||
|
||
use crate::api::judge::{ | ||
error::JudgeError, | ||
schema::{CodeSubmission, MarkResponse}, | ||
|
@@ -17,15 +21,17 @@ async fn submit_code( | |
submission.language | ||
); | ||
|
||
let output = mark(MarkParams { | ||
let output = AssertUnwindSafe(mark(MarkParams { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 주의) 장기적으로는 |
||
language: &submission.language.clone().into(), | ||
code: &submission.code, | ||
expected_stdout: &submission.expected_stdout, | ||
stdin: &submission.stdin, | ||
memory_limit: submission.memory_limit, | ||
time_limit: submission.time_limit, | ||
}) | ||
.await; | ||
})) | ||
.catch_unwind() | ||
.await | ||
.map_err(|_| JudgeError::HoduCoreError)?; | ||
|
||
Ok(web::Json( | ||
serde_json::to_value(MarkResponse::new(&output, &submission.fields)).unwrap(), | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dockerfile.local
은 어때요?dev
는 약간 dev 환경에 대해 써야 되는 단어같아서요!