-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
88 additions
and
22 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 |
---|---|---|
@@ -1 +1 @@ | ||
1 | ||
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
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,5 +1,6 @@ | ||
mod greet; | ||
mod judge; | ||
mod state; | ||
|
||
use actix_web::web; | ||
use utoipa::OpenApi; | ||
|
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,32 @@ | ||
use std::sync::RwLock; | ||
|
||
use lazy_static::lazy_static; | ||
|
||
#[derive(Clone, Debug, PartialEq)] | ||
pub enum State { | ||
Idle, | ||
Busy, | ||
} | ||
|
||
lazy_static! { | ||
pub static ref STATE: RwLock<State> = RwLock::new(State::Idle); | ||
} | ||
|
||
pub fn set_busy() -> anyhow::Result<()> { | ||
log::info!("Trying to set busy"); | ||
let mut state = STATE | ||
.try_write() | ||
.map_err(|e| anyhow::anyhow!("Failed to lock state: {:?}", e))?; | ||
log::info!("State: {:?}", *state); | ||
if *state == State::Busy { | ||
anyhow::bail!("Judge server is busy") | ||
} | ||
*state = State::Busy; | ||
|
||
Ok(()) | ||
} | ||
|
||
pub fn set_idle() { | ||
let mut state = STATE.write().unwrap(); | ||
*state = State::Idle; | ||
} |
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