go routine 启动所有工作区
(startedServerWorkspaces []workspace.WorkspaceInfo, cmd *cobra.Command, args []string, LoginUrl string)
| 201 | |
| 202 | // go routine 启动所有工作区 |
| 203 | func connect(startedServerWorkspaces []workspace.WorkspaceInfo, cmd *cobra.Command, args []string, LoginUrl string) { |
| 204 | // appinsight |
| 205 | executeStartCmdFunc := func(yamlConfig config.SmartIdeConfig, workspaceInfo workspace.WorkspaceInfo, cmdtype, userguid, workspaceid string) { |
| 206 | // if config.GlobalSmartIdeConfig.IsInsightEnabled != config.IsInsightEnabledEnum_Enabled { |
| 207 | // common.SmartIDELog.Debug("Application Insights disabled") |
| 208 | // return |
| 209 | // } |
| 210 | // var imageNames []string |
| 211 | // for _, service := range yamlConfig.Workspace.Servcies { |
| 212 | // imageNames = append(imageNames, service.Image) |
| 213 | // } |
| 214 | // appinsight.SetTrack(cmd.Use, Version.TagName, trackEvent, string(workspace.WorkingMode_Remote), strings.Join(imageNames, ",")) |
| 215 | } |
| 216 | |
| 217 | var mutex sync.Mutex |
| 218 | //0. start |
| 219 | forwardFunc := func(fixWorkspaceInfo workspace.WorkspaceInfo) { |
| 220 | mutex.Lock() |
| 221 | common.SmartIDELog.Info(fmt.Sprintf("-- workspace (%v) -------------------------------", fixWorkspaceInfo.ServerWorkSpace.NO)) |
| 222 | var err error |
| 223 | if fixWorkspaceInfo.Mode == workspace.WorkingMode_Remote { |
| 224 | |
| 225 | var imageNames []string |
| 226 | for _, service := range fixWorkspaceInfo.ConfigYaml.Workspace.LinkCompose.Services { |
| 227 | imageNames = append(imageNames, service.Image) |
| 228 | } |
| 229 | appinsight.SetAllTrack(appinsight.Cli_Server_Connect, args, LoginUrl, fixWorkspaceInfo.ServerWorkSpace.OwnerGUID, fixWorkspaceInfo.ID, "", "", strings.Join(imageNames, ",")) |
| 230 | _, err = start.ExecuteServerVmStartByClientEnvCmd(fixWorkspaceInfo, executeStartCmdFunc) |
| 231 | } /* else if fixWorkspaceInfo.Mode == workspace.WorkingMode_K8s { |
| 232 | err = start.ExecuteServerK8sStartByClientEnvCmd(fixWorkspaceInfo, executeStartCmdFunc) |
| 233 | } */ |
| 234 | |
| 235 | if err != nil { |
| 236 | common.SmartIDELog.ImportanceWithError(err) |
| 237 | connectedWorkspaceIds = common.RemoveItem(connectedWorkspaceIds, fixWorkspaceInfo.ServerWorkSpace.NO) |
| 238 | } |
| 239 | time.Sleep(time.Second * 26) |
| 240 | defer mutex.Unlock() |
| 241 | |
| 242 | for { |
| 243 | if !common.Contains(connectedWorkspaceIds, fixWorkspaceInfo.ServerWorkSpace.NO) { |
| 244 | common.SmartIDELog.Info(fmt.Sprintf("-- workspace (%v) -------------------------------", fixWorkspaceInfo.ServerWorkSpace.NO)) |
| 245 | common.SmartIDELog.Importance(fmt.Sprintf("当前工作区(%v)非启动状态,端口转发停止!", fixWorkspaceInfo.ServerWorkSpace.NO)) |
| 246 | return |
| 247 | } |
| 248 | time.Sleep(time.Second * 10) |
| 249 | } |
| 250 | |
| 251 | } |
| 252 | |
| 253 | //2. 启动工作区 |
| 254 | for _, workspaceInfo := range startedServerWorkspaces { |
| 255 | if workspaceInfo.ServerWorkSpace.Status == apiResponse.WorkspaceStatusEnum_Start { |
| 256 | if !common.Contains(connectedWorkspaceIds, workspaceInfo.ServerWorkSpace.NO) { |
| 257 | // 加入到已连接数组 |
| 258 | connectedWorkspaceIds = append(connectedWorkspaceIds, workspaceInfo.ServerWorkSpace.NO) |
| 259 | |
| 260 | go forwardFunc(workspaceInfo) |
no test coverage detected