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

Commit1d83f50

Browse files
committed
Fix environment status not updating
It looks like you have to use the per-environment listener. My guess isthat they do not update an environment if the ID is the same. I madethe environment comparable, which also lets use use a set instead.
1 parent59e0bd6 commit1d83f50

File tree

2 files changed

+42
-18
lines changed

2 files changed

+42
-18
lines changed

‎src/main/kotlin/com/coder/gateway/CoderRemoteEnvironment.kt‎

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,19 @@ class CoderRemoteEnvironment(
2525
) : AbstractRemoteProviderEnvironment(observablePropertiesFactory) {
2626
overridefungetId():String="${workspace.name}.${agent.name}"
2727
overridefungetName():String="${workspace.name}.${agent.name}"
28-
privateval status=WorkspaceAndAgentStatus.from(workspace, agent)
28+
privatevar status=WorkspaceAndAgentStatus.from(workspace, agent)
2929

30-
31-
// Map each state to whether a connection can be attempted.
32-
privatevar state= status.toRemoteEnvironmentState()
30+
/**
31+
* Update the workspace/agent status to the listeners, if it has changed.
32+
*/
33+
funupdate(workspace:Workspace,agent:WorkspaceAgent) {
34+
val newStatus=WorkspaceAndAgentStatus.from(workspace, agent)
35+
if (newStatus!= status) {
36+
status= newStatus
37+
val state= status.toRemoteEnvironmentState()
38+
listenerSet.forEach { it.consume(state) }
39+
}
40+
}
3341

3442
/**
3543
* The contents are provided by the SSH view provided by Toolbox, all we
@@ -47,14 +55,26 @@ class CoderRemoteEnvironment(
4755
overridefunsetVisible(visibilityState:EnvironmentVisibilityState) {}
4856

4957
/**
50-
* Immediately send the state to the listener.
51-
*
52-
* Currently we consume the entire workspace list and are not updating
53-
* individual workspaces, so the state here is static and the listener is
54-
* only used once.
58+
* Immediately send the state to the listener and store for updates.
5559
*/
5660
overridefunaddStateListener(consumer:EnvironmentStateConsumer):Boolean {
57-
consumer.consume(state)
61+
consumer.consume(status.toRemoteEnvironmentState())
5862
returnsuper.addStateListener(consumer)
5963
}
64+
65+
/**
66+
* An environment is equal if it has the same ID.
67+
*/
68+
overridefunequals(other:Any?):Boolean {
69+
if (other==null)returnfalse
70+
if (this=== other)returntrue// Note the triple ===
71+
if (other!isCoderRemoteEnvironment)returnfalse
72+
if (getId()!= other.getId())returnfalse
73+
returntrue
74+
}
75+
76+
/**
77+
* Companion to equals, for sets.
78+
*/
79+
overridefunhashCode():Int= getId().hashCode()
6080
}

‎src/main/kotlin/com/coder/gateway/CoderRemoteProvider.kt‎

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class CoderRemoteProvider(
5151

5252
// Current polling job.
5353
privatevar pollJob:Job?=null
54-
privatevar lastEnvironments:List<CoderRemoteEnvironment>?=null
54+
privatevar lastEnvironments:Set<CoderRemoteEnvironment>?=null
5555

5656
// Create our services from the Toolbox ones.
5757
privateval settingsService=CoderSettingsService(settingsStore)
@@ -96,23 +96,27 @@ class CoderRemoteProvider(
9696
// different information?
9797
it.name
9898
}?.map { agent->
99-
CoderRemoteEnvironment(client, ws, agent, observablePropertiesFactory)
99+
// If we have an environment already, update that.
100+
val env=CoderRemoteEnvironment(client, ws, agent, observablePropertiesFactory)
101+
lastEnvironments?.firstOrNull { it== env }?.let {
102+
it.update(ws, agent)
103+
it
104+
}?: env
100105
}?: emptyList()
101106
}
102-
}
107+
}.toSet()
103108

104109
// In case we logged out while running the query.
105110
if (!isActive) {
106111
return@launch
107112
}
108113

109114
// Reconfigure if a new environment is found.
110-
val newEnvironments= environments
111-
.filter { a-> lastEnvironments?.any { b-> a.id== b.id }!=true }
112-
.map { it.name }.toSet()
113-
if (newEnvironments.isNotEmpty()) {
115+
// TODO@JB: Should we use the add/remove listeners instead?
116+
val newEnvironments= lastEnvironments?.let { environments.subtract(it) }
117+
if (newEnvironments?.isNotEmpty()==true) {
114118
logger.info("Found new environment(s), reconfiguring CLI: {}", newEnvironments)
115-
cli.configSsh(newEnvironments)
119+
cli.configSsh(newEnvironments.map { it.name }.toSet())
116120
}
117121

118122
consumer.consumeEnvironments(environments)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp