-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Feat/#101 v1 runner
- Loading branch information
Showing
7 changed files
with
435 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,5 +30,6 @@ members = [ | |
"judge_control_app", | ||
"writerutil", | ||
"grpc_schema", | ||
"judge_core", | ||
] | ||
resolver = "2" |
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,11 @@ | ||
[package] | ||
name = "judge_core" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[dependencies] | ||
thiserror = { workspace = true } | ||
anyhow = { workspace = true } | ||
futures = { workspace = true } | ||
tokio = { workspace = true } | ||
uuid = { workspace = true } |
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,5 @@ | ||
pub struct ShellOutput { | ||
pub stdout: String, | ||
pub stderr: String, | ||
pub exit_code: i32, | ||
} |
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,65 @@ | ||
use crate::common::ShellOutput; | ||
use futures::future::Future; | ||
use tokio::sync::broadcast; | ||
use uuid::Uuid; | ||
|
||
/// JobAPI is a set of shell environment and cache of outcome files of previous jobs. | ||
/// | ||
/// Instances must be initialized once per submission. | ||
pub trait JobApi<JobOutcome: Clone>: Clone { | ||
/// Greater the priority is, sooner the job will be executed. | ||
/// | ||
/// Files created by this job will be deleted immediately after all returned JobOutcome are dropped. | ||
/// | ||
/// Outer future only creates a kind of reservasion for shell environment and returns inner future synchronously. | ||
fn run_future( | ||
&self, | ||
job_conf: ExecutionJob<JobOutcome>, | ||
priority: i32, | ||
) -> impl Future<Output = impl Future<Output = Result<(JobOutcome, ShellOutput), ExecutionJobError>>>; | ||
|
||
fn place_file( | ||
&self, | ||
job_conf: FilePlacementJob, | ||
) -> impl Future<Output = Result<JobOutcome, FilePlacementJobError>>; | ||
} | ||
|
||
#[derive(Debug, Clone)] | ||
pub enum JobOutcomeAcquisitionResult<JobOutcome: Clone> { | ||
/// Received JobOutcome successfully. | ||
Succeeded(JobOutcome), | ||
/// Failed to receive JobOutcome. | ||
Failed(String), | ||
} | ||
|
||
pub struct JobOutcomeLink<JobOutcome: Clone> { | ||
pub job_outcome_rx: broadcast::Receiver<JobOutcomeAcquisitionResult<JobOutcome>>, | ||
pub envvar_name: String, | ||
} | ||
|
||
pub struct ExecutionJob<JobOutcome: Clone> { | ||
pub script: String, | ||
pub depends_on_with_names: Vec<JobOutcomeLink<JobOutcome>>, | ||
} | ||
|
||
#[derive(Debug, Clone, thiserror::Error)] | ||
pub enum ExecutionJobError { | ||
#[error("Internal error while running a job: {0}")] | ||
InternalError(String), | ||
} | ||
|
||
pub enum FilePlacementJob { | ||
PlaceEmptyDirectory, | ||
/// Content of the text file | ||
PlaceOnetimeTextFile(String), | ||
/// Global project-wide unique identifier | ||
PlaceTextFile(Uuid), | ||
} | ||
|
||
#[derive(Debug, thiserror::Error)] | ||
pub enum FilePlacementJobError { | ||
#[error("Invalid file id: {0}")] | ||
InvalidFileId(Uuid), | ||
#[error("Internal error while placing a file: {0}")] | ||
InternalError(String), | ||
} |
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 @@ | ||
pub mod common; | ||
pub mod job; | ||
pub mod procedure; | ||
pub mod runner; |
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,35 @@ | ||
use uuid::Uuid; | ||
|
||
/// All runtime_id must be unique application-wide for each submission. | ||
pub struct Procedure { | ||
pub onetime_texts: Vec<OnetimeText>, | ||
pub texts: Vec<Text>, | ||
pub empty_directories: Vec<EmptyDirectory>, | ||
pub executions: Vec<Execution>, | ||
} | ||
|
||
pub struct OnetimeText { | ||
pub content: String, | ||
pub runtime_id: Uuid, | ||
} | ||
|
||
pub struct Text { | ||
pub resource_id: Uuid, | ||
pub runtime_id: Uuid, | ||
} | ||
|
||
pub struct EmptyDirectory { | ||
pub runtime_id: Uuid, | ||
} | ||
|
||
pub struct Execution { | ||
pub script: String, | ||
pub depends_on: Vec<DependsOn>, | ||
pub runtime_id: Uuid, | ||
pub priority: i32, | ||
} | ||
|
||
pub struct DependsOn { | ||
pub runtime_id: Uuid, | ||
pub envvar_name: String, | ||
} |
Oops, something went wrong.