-
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
✨ fix many(implemented LocalJudge in traopy)
- Loading branch information
Showing
26 changed files
with
618 additions
and
584 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
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,89 +1,56 @@ | ||
use crate::identifiers::ResourceId; | ||
use futures::future::Future; | ||
use std::process::Output; | ||
use tokio::sync::broadcast; | ||
|
||
/// 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( | ||
pub trait JobApi<ReservationToken, OutcomeToken: Clone>: Clone { | ||
fn reserve_execution( | ||
&self, | ||
job_conf: ExecutionJob<JobOutcome>, | ||
) -> impl Future< | ||
Output = Result< | ||
impl Future<Output = Result<ExecutionJobFinished<JobOutcome>, ExecutionJobError>>, | ||
ExecutionJobPreparationError, | ||
>, | ||
>; | ||
count: usize, | ||
) -> impl Future<Output = Result<Vec<ReservationToken>, ReservationError>>; | ||
|
||
fn place_file( | ||
&self, | ||
job_conf: FilePlacementJob, | ||
) -> impl Future<Output = Result<JobOutcome, FilePlacementJobError>>; | ||
} | ||
|
||
#[derive(Debug, Clone)] | ||
pub enum ExecutionJobFinished<JobOutcome: Clone> { | ||
/// Job finished successfully. | ||
Succeeded(JobOutcome, Output), | ||
/// Job failed expectedly. | ||
FailedExpectedly((JobOutcome, Output)), | ||
/// Preceding job failed expectedly. | ||
PrecedingJobFailedExpectedly, | ||
} | ||
file_conf: FileConf, | ||
) -> impl Future<Output = Result<OutcomeToken, FilePlacementError>>; | ||
|
||
#[derive(Debug, Clone)] | ||
pub enum JobOutcomeAcquisitionResult<JobOutcome: Clone> { | ||
/// Received JobOutcome successfully. | ||
Succeeded(JobOutcome), | ||
/// Failed to receive JobOutcome expectedly. | ||
FailedExpectedly, | ||
/// Failed to receive JobOutcome unexpectedly. | ||
FailedUnexpectedly(String), | ||
} | ||
|
||
pub struct JobOutcomeLink<JobOutcome: Clone> { | ||
pub job_outcome_rx: broadcast::Receiver<JobOutcomeAcquisitionResult<JobOutcome>>, | ||
pub envvar_name: String, | ||
fn execute( | ||
&self, | ||
reservation: ReservationToken, | ||
dependencies: Vec<Dependency<OutcomeToken>>, | ||
) -> impl Future<Output = Result<(OutcomeToken, Output), ExecutionError>>; | ||
} | ||
|
||
pub struct ExecutionJob<JobOutcome: Clone> { | ||
pub script: String, | ||
pub depends_on_with_names: Vec<JobOutcomeLink<JobOutcome>>, | ||
#[derive(Debug, Clone, thiserror::Error)] | ||
pub enum ReservationError { | ||
#[error("Failed to reserve execution with error: {0}")] | ||
ReserveFailed(String), | ||
} | ||
|
||
#[derive(Debug, Clone, thiserror::Error)] | ||
pub enum ExecutionJobPreparationError { | ||
#[error("Internal error while preparing a job: {0}")] | ||
InternalError(String), | ||
pub enum FilePlacementError { | ||
#[error("Failed to place file with error: {0}")] | ||
PlaceFailed(String), | ||
#[error("Invalid resource ID: {0}")] | ||
InvalidResourceId(ResourceId), | ||
} | ||
|
||
#[derive(Debug, Clone, thiserror::Error)] | ||
pub enum ExecutionJobError { | ||
#[error("Internal error while running a job: {0}")] | ||
pub enum ExecutionError { | ||
#[error("Internal error while executing a job: {0}")] | ||
InternalError(String), | ||
#[error("Preceding job failed unexpectedly: {0}")] | ||
PrecedingJobFailed(String), | ||
#[error("Judge process failed with error: {0}")] | ||
JudgeFailed(String), | ||
} | ||
|
||
pub enum FilePlacementJob { | ||
PlaceEmptyDirectory, | ||
/// Content of the text file | ||
PlaceRuntimeTextFile(String), | ||
/// Global project-wide unique identifier | ||
PlaceTextFile(ResourceId), | ||
#[derive(Debug, Clone)] | ||
pub enum FileConf { | ||
EmptyDirectory, | ||
Text(ResourceId), | ||
RuntimeText(String), | ||
} | ||
|
||
#[derive(Debug, thiserror::Error)] | ||
pub enum FilePlacementJobError { | ||
#[error("Invalid resource id: {0}")] | ||
InvalidResourceId(ResourceId), | ||
#[error("Internal error while placing a file: {0}")] | ||
InternalError(String), | ||
#[derive(Debug, Clone)] | ||
pub struct Dependency<OutcomeToken> { | ||
pub envvar: String, | ||
pub outcome: OutcomeToken, | ||
} |
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
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.