mirror of
https://github.com/coder/coder.git
synced 2025-07-18 14:17:22 +00:00
feat: add activity status and autostop reason to workspace overview (#11987)
This commit is contained in:
committed by
GitHub
parent
e53d8bdb50
commit
d37b131426
@ -1,6 +1,7 @@
|
||||
package coderd
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"database/sql"
|
||||
"encoding/json"
|
||||
@ -1343,7 +1344,48 @@ func (api *API) watchWorkspace(rw http.ResponseWriter, r *http.Request) {
|
||||
<-senderClosed
|
||||
}()
|
||||
|
||||
sendUpdate := func(_ context.Context, _ []byte) {
|
||||
sendUpdate := func(_ context.Context, description []byte) {
|
||||
// The agent stats get updated frequently, so we treat these as a special case and only
|
||||
// send a partial update. We primarily care about updating the `last_used_at` and
|
||||
// `latest_build.deadline` properties.
|
||||
if bytes.Equal(description, codersdk.WorkspaceNotifyDescriptionAgentStatsOnly) {
|
||||
workspace, err := api.Database.GetWorkspaceByID(ctx, workspace.ID)
|
||||
if err != nil {
|
||||
_ = sendEvent(ctx, codersdk.ServerSentEvent{
|
||||
Type: codersdk.ServerSentEventTypeError,
|
||||
Data: codersdk.Response{
|
||||
Message: "Internal error fetching workspace.",
|
||||
Detail: err.Error(),
|
||||
},
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
workspaceBuild, err := api.Database.GetLatestWorkspaceBuildByWorkspaceID(ctx, workspace.ID)
|
||||
if err != nil {
|
||||
_ = sendEvent(ctx, codersdk.ServerSentEvent{
|
||||
Type: codersdk.ServerSentEventTypeError,
|
||||
Data: codersdk.Response{
|
||||
Message: "Internal error fetching workspace build.",
|
||||
Detail: err.Error(),
|
||||
},
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
_ = sendEvent(ctx, codersdk.ServerSentEvent{
|
||||
Type: codersdk.ServerSentEventTypePartial,
|
||||
Data: struct {
|
||||
database.Workspace
|
||||
LatestBuild database.WorkspaceBuild `json:"latest_build"`
|
||||
}{
|
||||
Workspace: workspace,
|
||||
LatestBuild: workspaceBuild,
|
||||
},
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
workspace, err := api.Database.GetWorkspaceByID(ctx, workspace.ID)
|
||||
if err != nil {
|
||||
_ = sendEvent(ctx, codersdk.ServerSentEvent{
|
||||
|
Reference in New Issue
Block a user