in go/pkg/rexec/rexec.go [300:379]
func (ec *Context) ExecuteRemotely() {
if err := ec.computeInputs(); err != nil {
ec.Result = command.NewLocalErrorResult(err)
return
}
cmdID, executionID := ec.cmd.Identifiers.ExecutionID, ec.cmd.Identifiers.CommandID
log.V(1).Infof("%s %s> Checking inputs to upload...", cmdID, executionID)
// TODO(olaola): compute input cache hit stats.
ec.Metadata.EventTimes[command.EventUploadInputs] = &command.TimeInterval{From: time.Now()}
missing, bytesMoved, err := ec.client.GrpcClient.UploadIfMissing(ec.ctx, ec.inputBlobs...)
ec.Metadata.EventTimes[command.EventUploadInputs].To = time.Now()
if err != nil {
ec.Result = command.NewRemoteErrorResult(err)
return
}
ec.Metadata.MissingDigests = missing
for _, d := range missing {
ec.Metadata.LogicalBytesUploaded += d.Size
}
ec.Metadata.RealBytesUploaded = bytesMoved
log.V(1).Infof("%s %s> Executing remotely...\n%s", cmdID, executionID, strings.Join(ec.cmd.Args, " "))
ec.Metadata.EventTimes[command.EventExecuteRemotely] = &command.TimeInterval{From: time.Now()}
op, err := ec.client.GrpcClient.ExecuteAndWait(ec.ctx, &repb.ExecuteRequest{
InstanceName: ec.client.GrpcClient.InstanceName,
SkipCacheLookup: !ec.opt.AcceptCached || ec.opt.DoNotCache,
ActionDigest: ec.Metadata.ActionDigest.ToProto(),
})
ec.Metadata.EventTimes[command.EventExecuteRemotely].To = time.Now()
if err != nil {
ec.Result = command.NewRemoteErrorResult(err)
return
}
or := op.GetResponse()
if or == nil {
ec.Result = command.NewRemoteErrorResult(fmt.Errorf("unexpected operation result type: %v", or))
return
}
resp := &repb.ExecuteResponse{}
if err := ptypes.UnmarshalAny(or, resp); err != nil {
ec.Result = command.NewRemoteErrorResult(err)
return
}
ec.resPb = resp.Result
setTimingMetadata(ec.Metadata, resp.Result.GetExecutionMetadata())
st := status.FromProto(resp.Status)
message := resp.Message
if message != "" && (st.Code() != codes.OK || ec.resPb != nil && ec.resPb.ExitCode != 0) {
ec.oe.WriteErr([]byte(message + "\n"))
}
if ec.resPb != nil {
ec.setOutputMetadata()
ec.Result = command.NewResultFromExitCode((int)(ec.resPb.ExitCode))
if ec.opt.DownloadOutErr {
ec.Result = ec.downloadOutErr()
}
if ec.Result.Err == nil && ec.opt.DownloadOutputs {
log.V(1).Infof("%s %s> Downloading outputs...", cmdID, executionID)
stats, res := ec.downloadOutputs(ec.cmd.ExecRoot)
ec.Metadata.LogicalBytesDownloaded += stats.LogicalMoved
ec.Metadata.RealBytesDownloaded += stats.RealMoved
ec.Result = res
}
if resp.CachedResult && ec.Result.Err == nil {
ec.Result.Status = command.CacheHitResultStatus
}
}
if st.Code() == codes.DeadlineExceeded {
ec.Result = command.NewTimeoutResult()
return
}
if st.Code() != codes.OK {
ec.Result = command.NewRemoteErrorResult(rc.StatusDetailedError(st))
return
}
if ec.resPb == nil {
ec.Result = command.NewRemoteErrorResult(fmt.Errorf("execute did not return action result"))
}
}