Skip to content

Commit 7e370a0

Browse files
committed
refactor: abstract ssh disconnect logic into a new method
1 parent 00ff51e commit 7e370a0

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

src/main/kotlin/com/coder/toolbox/CoderRemoteEnvironment.kt

+13-9
Original file line numberDiff line numberDiff line change
@@ -111,15 +111,7 @@ class CoderRemoteEnvironment(
111111
} else {
112112
actions.add(Action(context.i18n.ptrl("Stop")) {
113113
context.cs.launch {
114-
if (isConnected.value) {
115-
connectionRequest.update {
116-
false
117-
}
118-
119-
if (isConnected.waitForFalseWithTimeout(10.seconds) == null) {
120-
context.logger.warn("The SSH connection to workspace $name could not be dropped in time, going to stop the workspace while the SSH connection is live")
121-
}
122-
}
114+
tryStopSshConnection()
123115

124116
val build = client.stopWorkspace(workspace)
125117
update(workspace.copy(latestBuild = build), agent)
@@ -130,6 +122,18 @@ class CoderRemoteEnvironment(
130122
return actions
131123
}
132124

125+
private suspend fun tryStopSshConnection() {
126+
if (isConnected.value) {
127+
connectionRequest.update {
128+
false
129+
}
130+
131+
if (isConnected.waitForFalseWithTimeout(10.seconds) == null) {
132+
context.logger.warn("The SSH connection to workspace $name could not be dropped in time, going to stop the workspace while the SSH connection is live")
133+
}
134+
}
135+
}
136+
133137
override fun getBeforeConnectionHooks(): List<BeforeConnectionHook> = listOf(this)
134138

135139
override fun getAfterDisconnectHooks(): List<AfterDisconnectHook> = listOf(this)

0 commit comments

Comments
 (0)