Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit71d3405

Browse files
committed
Cancel jobs when exiting workspace step
Especially important for the update job, since it has a loop.
1 parent2126fe1 commit71d3405

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

‎src/main/kotlin/com/coder/gateway/views/steps/CoderWorkspacesStepView.kt‎

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ import java.net.SocketTimeoutException
7171
importjava.net.URL
7272
importjava.net.UnknownHostException
7373
importjava.time.Duration
74+
importjava.util.*
7475
importjavax.net.ssl.SSLHandshakeException
7576
importjavax.swing.Icon
7677
importjavax.swing.JCheckBox
@@ -87,6 +88,7 @@ private const val SESSION_TOKEN = "session-token"
8788

8889
classCoderWorkspacesStepView(valsetNextButtonEnabled: (Boolean)->Unit) : CoderWorkspacesWizardStep, Disposable {
8990
privateval cs=CoroutineScope(Dispatchers.Main)
91+
privateval jobs:MutableMap<UUID,Job>=mutableMapOf()
9092
privatevar localWizardModel=CoderWorkspacesWizardModel()
9193
privateval settings:CoderSettingsService= service<CoderSettingsService>()
9294

@@ -249,7 +251,8 @@ class CoderWorkspacesStepView(val setNextButtonEnabled: (Boolean) -> Unit) : Cod
249251
val c= localWizardModel.client
250252
if (tableOfWorkspaces.selectedObject!=null&& c!=null) {
251253
val workspace= (tableOfWorkspaces.selectedObjectasWorkspaceAgentListModel).workspace
252-
cs.launch {
254+
jobs[workspace.id]?.cancel()
255+
jobs[workspace.id]= cs.launch {
253256
withContext(Dispatchers.IO) {
254257
try {
255258
c.startWorkspace(workspace)
@@ -269,7 +272,8 @@ class CoderWorkspacesStepView(val setNextButtonEnabled: (Boolean) -> Unit) : Cod
269272
val c= localWizardModel.client
270273
if (tableOfWorkspaces.selectedObject!=null&& c!=null) {
271274
val workspace= (tableOfWorkspaces.selectedObjectasWorkspaceAgentListModel).workspace
272-
cs.launch {
275+
jobs[workspace.id]?.cancel()
276+
jobs[workspace.id]= cs.launch {
273277
withContext(Dispatchers.IO) {
274278
try {
275279
// Stop the workspace first if it is running.
@@ -278,7 +282,7 @@ class CoderWorkspacesStepView(val setNextButtonEnabled: (Boolean) -> Unit) : Cod
278282
c.stopWorkspace(workspace)
279283
loadWorkspaces()
280284
var elapsed=Duration.ofSeconds(0)
281-
val timeout=Duration.ofSeconds(1)
285+
val timeout=Duration.ofSeconds(5)
282286
val maxWait=Duration.ofMinutes(10)
283287
while (isActive) {// Wait for the workspace to fully stop.
284288
delay(timeout.toMillis())
@@ -330,7 +334,8 @@ class CoderWorkspacesStepView(val setNextButtonEnabled: (Boolean) -> Unit) : Cod
330334
val c= localWizardModel.client
331335
if (tableOfWorkspaces.selectedObject!=null&& c!=null) {
332336
val workspace= (tableOfWorkspaces.selectedObjectasWorkspaceAgentListModel).workspace
333-
cs.launch {
337+
jobs[workspace.id]?.cancel()
338+
jobs[workspace.id]= cs.launch {
334339
withContext(Dispatchers.IO) {
335340
try {
336341
c.stopWorkspace(workspace)
@@ -457,6 +462,7 @@ class CoderWorkspacesStepView(val setNextButtonEnabled: (Boolean) -> Unit) : Cod
457462
localWizardModel.cliManager=null
458463
localWizardModel.client=null
459464
poller?.cancel()
465+
jobs.forEach { it.value.cancel() }
460466
tfUrlComment?.foreground=UIUtil.getContextHelpForeground()
461467
tfUrlComment?.text=CoderGatewayBundle.message("gateway.connector.view.coder.workspaces.connect.text.connecting", deploymentURL.host)
462468
tableOfWorkspaces.setEmptyState(CoderGatewayBundle.message("gateway.connector.view.coder.workspaces.connect.text.connecting", deploymentURL.host))
@@ -555,6 +561,7 @@ class CoderWorkspacesStepView(val setNextButtonEnabled: (Boolean) -> Unit) : Cod
555561

556562
privatefuntriggerWorkspacePolling(fetchNow:Boolean) {
557563
poller?.cancel()
564+
jobs.forEach { it.value.cancel() }
558565

559566
poller= cs.launch {
560567
if (fetchNow) {
@@ -643,6 +650,7 @@ class CoderWorkspacesStepView(val setNextButtonEnabled: (Boolean) -> Unit) : Cod
643650
super.onPrevious()
644651
logger.info("Going back to the main view")
645652
poller?.cancel()
653+
jobs.forEach { it.value.cancel() }
646654
}
647655

648656
overridefunonNext(wizardModel:CoderWorkspacesWizardModel):Boolean {
@@ -673,6 +681,7 @@ class CoderWorkspacesStepView(val setNextButtonEnabled: (Boolean) -> Unit) : Cod
673681
configDirectory= cliManager?.coderConfigPath?.toString()?:""
674682
}
675683
poller?.cancel()
684+
jobs.forEach { it.value.cancel() }
676685

677686
logger.info("Opening IDE selection window for${selected.name}")
678687
returntrue

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp