Skip to content

Commit

Permalink
remote: small refactoring that splits download and spawn result
Browse files Browse the repository at this point in the history
Closes bazelbuild#7792.

PiperOrigin-RevId: 239608769
  • Loading branch information
buchgr authored and copybara-github committed Mar 21, 2019
1 parent fc01ea7 commit 1b8cf02
Showing 1 changed file with 11 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -196,10 +196,8 @@ public SpawnResult exec(Spawn spawn, SpawnExecutionContext context)
acceptCachedResult = false;
} else {
try (SilentCloseable c = Profiler.instance().profile("Remote.downloadRemoteResults")) {
return downloadRemoteResults(cachedResult, context.getFileOutErr())
.setCacheHit(true)
.setRunnerName("remote cache hit")
.build();
remoteCache.download(cachedResult, execRoot, context.getFileOutErr());
return createSpawnResult(cachedResult.getExitCode(), /* cacheHit= */ true);
} catch (CacheNotFoundException e) {
// No cache hit, so we fall through to local or remote execution.
// We set acceptCachedResult to false in order to force the action re-execution.
Expand Down Expand Up @@ -251,7 +249,8 @@ public SpawnResult exec(Spawn spawn, SpawnExecutionContext context)

FileOutErr outErr = context.getFileOutErr();
String message = reply.getMessage();
if ((reply.getResult().getExitCode() != 0
ActionResult actionResult = reply.getResult();
if ((actionResult.getExitCode() != 0
|| reply.getStatus().getCode() != Code.OK.value())
&& !message.isEmpty()) {
outErr.printErr(message + "\n");
Expand All @@ -264,11 +263,9 @@ public SpawnResult exec(Spawn spawn, SpawnExecutionContext context)

try (SilentCloseable c =
Profiler.instance().profile("Remote.downloadRemoteResults")) {
return downloadRemoteResults(reply.getResult(), outErr)
.setRunnerName(reply.getCachedResult() ? "remote cache hit" : getName())
.setCacheHit(reply.getCachedResult())
.build();
remoteCache.download(actionResult, execRoot, outErr);
}
return createSpawnResult(actionResult.getExitCode(), reply.getCachedResult());
});
} catch (IOException e) {
return execLocallyAndUploadOrFail(
Expand Down Expand Up @@ -330,13 +327,13 @@ private void maybeDownloadServerLogs(ExecuteResponse resp, ActionKey actionKey)
}
}

private SpawnResult.Builder downloadRemoteResults(ActionResult result, FileOutErr outErr)
throws ExecException, IOException, InterruptedException {
remoteCache.download(result, execRoot, outErr);
int exitCode = result.getExitCode();
private SpawnResult createSpawnResult(int exitCode, boolean cacheHit) {
return new SpawnResult.Builder()
.setStatus(exitCode == 0 ? Status.SUCCESS : Status.NON_ZERO_EXIT)
.setExitCode(exitCode);
.setExitCode(exitCode)
.setRunnerName(cacheHit ? getName() + " cache hit" : getName())
.setCacheHit(cacheHit)
.build();
}

private SpawnResult execLocally(Spawn spawn, SpawnExecutionContext context)
Expand Down

0 comments on commit 1b8cf02

Please sign in to comment.