@@ -25,6 +25,7 @@ import com.jetbrains.toolbox.api.remoteDev.states.RemoteEnvironmentState
25
25
import com.jetbrains.toolbox.api.ui.actions.ActionDescription
26
26
import com.jetbrains.toolbox.api.ui.components.TextType
27
27
import com.squareup.moshi.Moshi
28
+ import kotlinx.coroutines.CoroutineName
28
29
import kotlinx.coroutines.Job
29
30
import kotlinx.coroutines.delay
30
31
import kotlinx.coroutines.flow.MutableStateFlow
@@ -81,72 +82,65 @@ class CoderRemoteEnvironment(
81
82
private fun getAvailableActions (): List <ActionDescription > {
82
83
val actions = mutableListOf<ActionDescription >()
83
84
if (wsRawStatus.canStop()) {
84
- actions.add(Action (context.i18n.ptrl(" Open web terminal" )) {
85
- context.cs.launch {
86
- context.desktop.browse(client.url.withPath(" /${workspace.ownerName} /$name /terminal" ).toString()) {
87
- context.ui.showErrorInfoPopup(it)
88
- }
85
+ actions.add(Action (context, " Open web terminal" ) {
86
+ context.desktop.browse(client.url.withPath(" /${workspace.ownerName} /$name /terminal" ).toString()) {
87
+ context.ui.showErrorInfoPopup(it)
89
88
}
90
- })
89
+ }
90
+ )
91
91
}
92
92
actions.add(
93
- Action (context.i18n.ptrl(" Open in dashboard" )) {
94
- context.cs.launch {
95
- context.desktop.browse(
96
- client.url.withPath(" /@${workspace.ownerName} /${workspace.name} " ).toString()
97
- ) {
98
- context.ui.showErrorInfoPopup(it)
99
- }
100
- }
101
- })
102
-
103
- actions.add(Action (context.i18n.ptrl(" View template" )) {
104
- context.cs.launch {
105
- context.desktop.browse(client.url.withPath(" /templates/${workspace.templateName} " ).toString()) {
93
+ Action (context, " Open in dashboard" ) {
94
+ context.desktop.browse(
95
+ client.url.withPath(" /@${workspace.ownerName} /${workspace.name} " ).toString()
96
+ ) {
106
97
context.ui.showErrorInfoPopup(it)
107
98
}
108
99
}
109
- })
100
+ )
101
+
102
+ actions.add(Action (context, " View template" ) {
103
+ context.desktop.browse(client.url.withPath(" /templates/${workspace.templateName} " ).toString()) {
104
+ context.ui.showErrorInfoPopup(it)
105
+ }
106
+ }
107
+ )
110
108
111
109
if (wsRawStatus.canStart()) {
112
110
if (workspace.outdated) {
113
- actions.add(Action (context.i18n.ptrl(" Update and start" )) {
114
- context.cs.launch {
115
- val build = client.updateWorkspace(workspace)
116
- update(workspace.copy(latestBuild = build), agent)
117
- }
118
- })
111
+ actions.add(Action (context, " Update and start" ) {
112
+ val build = client.updateWorkspace(workspace)
113
+ update(workspace.copy(latestBuild = build), agent)
114
+ }
115
+ )
119
116
} else {
120
- actions.add(Action (context.i18n.ptrl(" Start" )) {
121
- context.cs.launch {
122
- val build = client.startWorkspace(workspace)
123
- update(workspace.copy(latestBuild = build), agent)
117
+ actions.add(Action (context, " Start" ) {
118
+ val build = client.startWorkspace(workspace)
119
+ update(workspace.copy(latestBuild = build), agent)
124
120
125
- }
126
- } )
121
+ }
122
+ )
127
123
}
128
124
}
129
125
if (wsRawStatus.canStop()) {
130
126
if (workspace.outdated) {
131
- actions.add(Action (context.i18n.ptrl(" Update and restart" )) {
132
- context.cs.launch {
133
- val build = client.updateWorkspace(workspace)
134
- update(workspace.copy(latestBuild = build), agent)
135
- }
136
- })
137
- }
138
- actions.add(Action (context.i18n.ptrl(" Stop" )) {
139
- context.cs.launch {
140
- tryStopSshConnection()
141
-
142
- val build = client.stopWorkspace(workspace)
127
+ actions.add(Action (context, " Update and restart" ) {
128
+ val build = client.updateWorkspace(workspace)
143
129
update(workspace.copy(latestBuild = build), agent)
144
130
}
145
- })
131
+ )
132
+ }
133
+ actions.add(Action (context, " Stop" ) {
134
+ tryStopSshConnection()
135
+
136
+ val build = client.stopWorkspace(workspace)
137
+ update(workspace.copy(latestBuild = build), agent)
138
+ }
139
+ )
146
140
}
147
141
actions.add(CoderDelimiter (context.i18n.pnotr(" " )))
148
- actions.add(Action (context.i18n.ptrl( " Delete workspace" ) , highlightInRed = true ) {
149
- context.cs.launch {
142
+ actions.add(Action (context, " Delete workspace" , highlightInRed = true ) {
143
+ context.cs.launch( CoroutineName ( " Delete Workspace Action " )) {
150
144
var dialogText =
151
145
if (wsRawStatus.canStop()) " This will close the workspace and remove all its information, including files, unsaved changes, history, and usage data."
152
146
else " This will remove all information from the workspace, including files, unsaved changes, history, and usage data."
@@ -192,7 +186,7 @@ class CoderRemoteEnvironment(
192
186
pollJob = pollNetworkMetrics()
193
187
}
194
188
195
- private fun pollNetworkMetrics (): Job = context.cs.launch {
189
+ private fun pollNetworkMetrics (): Job = context.cs.launch( CoroutineName ( " Network Metrics Poller " )) {
196
190
context.logger.info(" Starting the network metrics poll job for $id " )
197
191
while (isActive) {
198
192
context.logger.debug(" Searching SSH command's PID for workspace $id ..." )
@@ -250,7 +244,7 @@ class CoderRemoteEnvironment(
250
244
actionsList.update {
251
245
getAvailableActions()
252
246
}
253
- context.cs.launch {
247
+ context.cs.launch( CoroutineName ( " Workspace Status Updater " )) {
254
248
state.update {
255
249
wsRawStatus.toRemoteEnvironmentState(context)
256
250
}
@@ -285,7 +279,7 @@ class CoderRemoteEnvironment(
285
279
*/
286
280
fun startSshConnection (): Boolean {
287
281
if (wsRawStatus.ready() && ! isConnected.value) {
288
- context.cs.launch {
282
+ context.cs.launch( CoroutineName ( " SSH Connection Trigger " )) {
289
283
connectionRequest.update {
290
284
true
291
285
}
@@ -306,7 +300,7 @@ class CoderRemoteEnvironment(
306
300
WorkspaceAndAgentStatus .DELETING .toRemoteEnvironmentState(context)
307
301
}
308
302
309
- context.cs.launch {
303
+ context.cs.launch( CoroutineName ( " Workspace Deletion Poller " )) {
310
304
withTimeout(5 .minutes) {
311
305
var workspaceStillExists = true
312
306
while (context.cs.isActive && workspaceStillExists) {
0 commit comments