1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
|
package server
import (
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"google.golang.org/protobuf/types/known/timestamppb"
"github.com/hashicorp/vagrant/internal/server/proto/vagrant_server"
)
// NewStatus returns a new Status message with the given initial state.
func NewStatus(init vagrant_server.Status_State) *vagrant_server.Status {
return &vagrant_server.Status{
State: init,
StartTime: timestamppb.Now(),
}
}
// StatusSetError sets the error state on the status and marks the
// completion time.
func StatusSetError(s *vagrant_server.Status, err error) {
st, ok := status.FromError(err)
if !ok {
st = status.Newf(codes.Internal, "Non-status error %T: %s", err, err)
}
s.State = vagrant_server.Status_ERROR
s.Error = st.Proto()
s.CompleteTime = timestamppb.Now()
}
// StatusSetSuccess sets state of the status to success and marks the
// completion time.
func StatusSetSuccess(s *vagrant_server.Status) {
s.State = vagrant_server.Status_SUCCESS
s.CompleteTime = timestamppb.Now()
}
|