Skip to content

Commit

Permalink
Merge pull request #104 from traP-jp/feat/#101-v1-runner
Browse files Browse the repository at this point in the history
Feat/#101 v1 runner
  • Loading branch information
comavius authored Feb 14, 2025
2 parents b429d7e + 6d07895 commit 4ba3324
Show file tree
Hide file tree
Showing 7 changed files with 435 additions and 0 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,6 @@ members = [
"judge_control_app",
"writerutil",
"grpc_schema",
"judge_core",
]
resolver = "2"
11 changes: 11 additions & 0 deletions judge_core/Cargo.toml
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 }
5 changes: 5 additions & 0 deletions judge_core/src/common.rs
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,
}
65 changes: 65 additions & 0 deletions judge_core/src/job.rs
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),
}
4 changes: 4 additions & 0 deletions judge_core/src/lib.rs
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;
35 changes: 35 additions & 0 deletions judge_core/src/procedure.rs
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,
}
Loading

0 comments on commit 4ba3324

Please sign in to comment.