-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(platform): make termination of the long-running user scripts more…
… resilient
- Loading branch information
Showing
2 changed files
with
210 additions
and
38 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 |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/// Defines the reason why a script was terminated. | ||
#[derive(Debug, Clone, Copy, PartialEq)] | ||
pub enum ScriptTerminationReason { | ||
/// The script was terminated because it hit the memory limit. | ||
MemoryLimit = 0, | ||
/// The script was terminated because it hit the time limit. | ||
TimeLimit = 1, | ||
/// The script was terminated for an unknown reason. | ||
Unknown = 2, | ||
} | ||
|
||
impl From<usize> for ScriptTerminationReason { | ||
fn from(value: usize) -> Self { | ||
match value { | ||
0 => Self::MemoryLimit, | ||
1 => Self::TimeLimit, | ||
_ => Self::Unknown, | ||
} | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::ScriptTerminationReason; | ||
|
||
#[test] | ||
fn conversion() { | ||
assert_eq!( | ||
ScriptTerminationReason::MemoryLimit, | ||
ScriptTerminationReason::from(0) | ||
); | ||
assert_eq!( | ||
ScriptTerminationReason::TimeLimit, | ||
ScriptTerminationReason::from(1) | ||
); | ||
assert_eq!( | ||
ScriptTerminationReason::Unknown, | ||
ScriptTerminationReason::from(2) | ||
); | ||
assert_eq!( | ||
ScriptTerminationReason::Unknown, | ||
ScriptTerminationReason::from(100500) | ||
); | ||
} | ||
} |