SyncStatus gets the status of a unit and lists its dependencies.
(_ context.Context, req *proto.SyncStatusRequest)
| 134 | |
| 135 | // SyncStatus gets the status of a unit and lists its dependencies. |
| 136 | func (s *DRPCAgentSocketService) SyncStatus(_ context.Context, req *proto.SyncStatusRequest) (*proto.SyncStatusResponse, error) { |
| 137 | if s.unitManager == nil { |
| 138 | return nil, xerrors.Errorf("cannot get status for unit %q: %w", req.Unit, ErrUnitManagerNotAvailable) |
| 139 | } |
| 140 | |
| 141 | unitID := unit.ID(req.Unit) |
| 142 | |
| 143 | isReady, err := s.unitManager.IsReady(unitID) |
| 144 | if err != nil { |
| 145 | return nil, xerrors.Errorf("cannot check readiness: %w", err) |
| 146 | } |
| 147 | |
| 148 | dependencies, err := s.unitManager.GetAllDependencies(unitID) |
| 149 | switch { |
| 150 | case errors.Is(err, unit.ErrUnitNotFound): |
| 151 | dependencies = []unit.Dependency{} |
| 152 | case err != nil: |
| 153 | return nil, xerrors.Errorf("cannot get dependencies: %w", err) |
| 154 | } |
| 155 | |
| 156 | var depInfos []*proto.DependencyInfo |
| 157 | for _, dep := range dependencies { |
| 158 | depInfos = append(depInfos, &proto.DependencyInfo{ |
| 159 | Unit: string(dep.Unit), |
| 160 | DependsOn: string(dep.DependsOn), |
| 161 | RequiredStatus: string(dep.RequiredStatus), |
| 162 | CurrentStatus: string(dep.CurrentStatus), |
| 163 | IsSatisfied: dep.IsSatisfied, |
| 164 | }) |
| 165 | } |
| 166 | |
| 167 | u, err := s.unitManager.Unit(unitID) |
| 168 | if err != nil { |
| 169 | return nil, xerrors.Errorf("cannot get status for unit %q: %w", req.Unit, err) |
| 170 | } |
| 171 | return &proto.SyncStatusResponse{ |
| 172 | Status: string(u.Status()), |
| 173 | IsReady: isReady, |
| 174 | Dependencies: depInfos, |
| 175 | }, nil |
| 176 | } |
| 177 | |
| 178 | // UpdateAppStatus forwards an app status update to coderd via the |
| 179 | // agent API. Returns an error if the agent is not connected. |