toolsetStatusFor builds a ToolsetStatus for ts. tools.As walks the wrapper chain so Statable/Describer can live anywhere in the stack.
(ts tools.ToolSet)
| 1061 | // toolsetStatusFor builds a ToolsetStatus for ts. tools.As walks the |
| 1062 | // wrapper chain so Statable/Describer can live anywhere in the stack. |
| 1063 | func toolsetStatusFor(ts tools.ToolSet) tools.ToolsetStatus { |
| 1064 | status := tools.ToolsetStatus{ |
| 1065 | Description: tools.DescribeToolSet(ts), |
| 1066 | } |
| 1067 | if kinder, ok := tools.As[tools.Kinder](ts); ok { |
| 1068 | status.Kind = kinder.Kind() |
| 1069 | } |
| 1070 | if statable, ok := tools.As[tools.Statable](ts); ok { |
| 1071 | info := statable.State() |
| 1072 | status.State = info.State |
| 1073 | status.LastError = info.LastError |
| 1074 | status.RestartCount = info.RestartCount |
| 1075 | } else { |
| 1076 | // Toolsets without a supervisor are considered ready by default; |
| 1077 | // the StartableToolSet wrapper would have surfaced an error |
| 1078 | // earlier if Start failed. |
| 1079 | status.State = lifecycleStateForUnsupervised(ts) |
| 1080 | } |
| 1081 | status.Name = nameFor(ts, status.Description) |
| 1082 | return status |
| 1083 | } |
| 1084 | |
| 1085 | func lifecycleStateForUnsupervised(ts tools.ToolSet) lifecycle.State { |
| 1086 | if s, ok := ts.(*tools.StartableToolSet); ok && !s.IsStarted() { |