diff options
author | 2016-09-07 14:56:07 +0000 | |
---|---|---|
committer | 2016-09-08 08:43:42 +0000 | |
commit | 01573f7b004d514b8890441f1079178ef66a70c4 (patch) | |
tree | a4c6fc64159a41544d5d5db3840cce60fabeff9c /src/main/java/com/google/devtools/build/lib/actions/Spawns.java | |
parent | e1cd9509862aef684b4dbbdfd15d0b877fb8fad3 (diff) |
Refactoring getTimeoutSeconds of a Spawn into Spaws.java, becaused it is used
in places other than the sandbox code.
--
MOS_MIGRATED_REVID=132436150
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/actions/Spawns.java')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/actions/Spawns.java | 44 |
1 files changed, 44 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 new file mode 100644 index 0000000000..75046a9fd2 --- /dev/null +++ b/src/main/java/com/google/devtools/build/lib/actions/Spawns.java @@ -0,0 +1,44 @@ +// Copyright 2016 The Bazel Authors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package com.google.devtools.build.lib.actions; + +/** Helper methods relating to implementations of {@link Spawn}. */ +public final class Spawns { + private Spawns() {} + + /** + * Parse the timeout key in the spawn execution info, if it exists. Return -1 if the key does not + * exist. + */ + public static int getTimeoutSeconds(Spawn spawn) throws ExecException { + return getTimeoutSeconds(spawn, -1); + } + + /** + * Parse the timeout key in the spawn execution info, if it exists. Otherwise, return the given + * default timeout. + */ + public static int getTimeoutSeconds(Spawn spawn, int defaultTimeout) throws ExecException { + String timeoutStr = spawn.getExecutionInfo().get("timeout"); + if (timeoutStr == null) { + return defaultTimeout; + } + try { + return Integer.parseInt(timeoutStr); + } catch (NumberFormatException e) { + throw new UserExecException("could not parse timeout: ", e); + } + } +} |