diff options
author | ulfjack <ulfjack@google.com> | 2018-05-22 05:11:32 -0700 |
---|---|---|
committer | Copybara-Service <copybara-piper@google.com> | 2018-05-22 05:12:51 -0700 |
commit | 8ba0475d4aecd964049d22486fbbc4817a31aa9c (patch) | |
tree | 33cc096490b29b8ccfecf5f215414436aba4739a /src/main/java/com/google/devtools/build/lib | |
parent | 3da8929963e9c70dff5d8859d6e988e6e7f4f9d7 (diff) |
Add a helper method to compute timeouts with a default value
PiperOrigin-RevId: 197545650
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/actions/Spawns.java | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/actions/Spawns.java b/src/main/java/com/google/devtools/build/lib/actions/Spawns.java index a7b0e7ecf4..3174d5b112 100644 --- a/src/main/java/com/google/devtools/build/lib/actions/Spawns.java +++ b/src/main/java/com/google/devtools/build/lib/actions/Spawns.java @@ -63,6 +63,22 @@ public final class Spawns { } /** + * Parse the timeout key in the spawn execution info, if it exists. Otherwise, return + * defaultTimeout, or 0 if that is null. + */ + public static Duration getTimeout(Spawn spawn, Duration defaultTimeout) throws ExecException { + String timeoutStr = spawn.getExecutionInfo().get(ExecutionRequirements.TIMEOUT); + if (timeoutStr == null) { + return defaultTimeout == null ? Duration.ZERO : defaultTimeout; + } + try { + return Duration.ofSeconds(Integer.parseInt(timeoutStr)); + } catch (NumberFormatException e) { + throw new UserExecException("could not parse timeout: ", e); + } + } + + /** * Returns whether a local {@link Spawn} runner implementation should prefetch the inputs before * execution, based on the spawns execution info. */ |