-
Notifications
You must be signed in to change notification settings - Fork 894
feat: add activity status and autostop reason to workspace overview #11987
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 15 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
cdc0ea2
yay!!!
aslilac aa7adf8
:^)
aslilac a20a570
Merge branch 'main' into clarify-stop-warning
aslilac 276dffc
😎
aslilac c4d85e5
✨
aslilac a5b2dbb
🧹
aslilac c5ad3db
notify frontend about new agent activity
aslilac 3a4fb5e
color tweaks
aslilac 7c692d4
finishing touches
aslilac 2fe1d45
🧹
aslilac 201eef6
🧪
aslilac 4a9d862
🧹
aslilac b2ce1dd
🧪
aslilac fa52350
Merge branch 'main' into clarify-stop-warning
aslilac d13f91e
fmt
aslilac 8a52a23
`dbM`
aslilac 3972eb9
test pubsub delivery
aslilac File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { useEffect, useState } from "react"; | ||
|
||
/** | ||
* useTime allows a component to rerender over time without a corresponding state change. | ||
* An example could be a relative timestamp (eg. "in 5 minutes") that should count down as it | ||
* approaches. | ||
* | ||
* This hook should only be used in components that are very simple, and that will not | ||
* create a lot of unnecessary work for the reconciler. Given that this hook will result in | ||
* the entire subtree being rerendered on a frequent interval, it's important that the subtree | ||
* remains small. | ||
* | ||
* @param active Can optionally be set to false in circumstances where updating over time is | ||
* not necessary. | ||
*/ | ||
export function useTime(active: boolean = true) { | ||
const [, setTick] = useState(0); | ||
|
||
useEffect(() => { | ||
if (!active) { | ||
return; | ||
} | ||
|
||
const interval = setInterval(() => { | ||
setTick((i) => i + 1); | ||
}, 1000); | ||
|
||
return () => { | ||
clearInterval(interval); | ||
}; | ||
}, [active]); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import dayjs from "dayjs"; | ||
import type { Workspace } from "api/typesGenerated"; | ||
|
||
export type WorkspaceActivityStatus = | ||
| "ready" | ||
| "connected" | ||
| "inactive" | ||
| "notConnected" | ||
| "notRunning"; | ||
|
||
export function getWorkspaceActivityStatus( | ||
workspace: Workspace, | ||
): WorkspaceActivityStatus { | ||
const builtAt = dayjs(workspace.latest_build.created_at); | ||
const usedAt = dayjs(workspace.last_used_at); | ||
const now = dayjs(); | ||
|
||
if (workspace.latest_build.status !== "running") { | ||
return "notRunning"; | ||
} | ||
|
||
// This needs to compare to `usedAt` instead of `now`, because the "grace period" for | ||
// marking a workspace as "Connected" is a lot longer. If you compared `builtAt` to `now`, | ||
// you could end up switching from "Ready" to "Connected" without ever actually connecting. | ||
const isBuiltRecently = builtAt.isAfter(usedAt.subtract(1, "second")); | ||
// By default, agents report connection stats every 30 seconds, so 2 minutes should be | ||
// plenty. Disconnection will be reflected relatively-quickly | ||
const isUsedRecently = usedAt.isAfter(now.subtract(2, "minute")); | ||
|
||
// If the build is still "fresh", it'll be a while before the `last_used_at` gets bumped in | ||
// a significant way by the agent, so just label it as ready instead of connected. | ||
// Wait until `last_used_at` is after the time that the build finished, _and_ still | ||
// make sure to check that it's recent, so that we don't show "Ready" indefinitely. | ||
if (isUsedRecently && isBuiltRecently && workspace.health.healthy) { | ||
return "ready"; | ||
} | ||
|
||
if (isUsedRecently) { | ||
return "connected"; | ||
} | ||
|
||
// TODO: It'd be nice if we could differentiate between "connected but inactive" and | ||
// "not connected", but that will require some relatively substantial backend work. | ||
return "inactive"; | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.