Skip to content

feat: filter for running workspaces #4157

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 19 commits into from
Oct 11, 2022
Merged

Conversation

presleyp
Copy link
Contributor

@presleyp presleyp commented Sep 22, 2022

I meant to merge the xservice refactor alone but had some kind of branch mixup, so now it's all in one PR, and closes #3655

  • xservice refactor: I saw a comment pointing to this discussion, which never really got resolved. In it, someone from Stately says we shouldn't be using send and stop inside assign, so I broke what we have into two functions, a service and an action, to address that. Often, XState issues can be resolved by adding a new state. While I was there I realized we weren't using the idle state, and are free to start right in with gettingWorkspaces, which means we don't need to useEffect.
  • add "running" workspace status filter to frontend
  • make backend filter on workspace status, with help from @coadler.

You can filter by any status but only Running is in the dropdown.
Screen Shot 2022-10-10 at 6 28 57 PM
Screen Shot 2022-10-10 at 6 29 22 PM

@presleyp presleyp requested a review from a team as a code owner September 22, 2022 18:31
@presleyp presleyp requested review from BrunoQuaresma and removed request for a team September 22, 2022 18:31
id: "workspacesState",
on: {
GET_WORKSPACES: {
actions: "assignFilter",
target: "gettingWorkspaces",
target: ".gettingWorkspaces",
internal: false,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The vscode extension adds that automatically :/, it's just a more precise name of the state.

},
}),
},
services: {
getWorkspaces: (context) => API.getWorkspaces(queryToFilter(context.filter)),
updateWorkspaceRefs: (context, event) => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I can understand what is happening here but I would add a comment about the refsToKeep and what the ref.stop is doing. Also, do we need to make this a service since it does not run any async ops.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I made it a service because we don't want to do stop and send in an assign action, and it's okay in another action, but then it's harder to send data from one action to the next (which is by design, I think). I think I would need to save refsToKeep and newWorkspaces in context, and that felt like clutter.

Copy link
Collaborator

@BrunoQuaresma BrunoQuaresma left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, just minor questions to better understand the changes. Thanks for making this.

@BrunoQuaresma
Copy link
Collaborator

I also question myself if I made a good decision by spawning refs inside of this machine. Unfortunately, managing the refs and keeping them in sync is very hard with the current XState tooling.

@presleyp presleyp changed the title chore: refactor workspaces xservice feat: filter for running workspaces Oct 10, 2022
@presleyp
Copy link
Contributor Author

@BrunoQuaresma I thought I had merged the part of this that you reviewed before, but I had some kind of mix-up, so feel free to skip the xservice part, it hasn't changed since you reviewed it.

Copy link
Collaborator

@BrunoQuaresma BrunoQuaresma left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lgtm!

Copy link
Contributor

@f0ssel f0ssel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly reviewed backend and it looks good - got a question about the query but nothing blocking.

Comment on lines +40 to +102
AND CASE
WHEN @status :: text != '' THEN
CASE
WHEN @status = 'pending' THEN
latest_build.started_at IS NULL
WHEN @status = 'starting' THEN
latest_build.started_at IS NOT NULL AND
latest_build.canceled_at IS NULL AND
latest_build.completed_at IS NULL AND
latest_build.updated_at - INTERVAL '30 seconds' < NOW() AND
latest_build.transition = 'start'::workspace_transition

WHEN @status = 'running' THEN
latest_build.completed_at IS NOT NULL AND
latest_build.canceled_at IS NULL AND
latest_build.error IS NULL AND
latest_build.transition = 'start'::workspace_transition

WHEN @status = 'stopping' THEN
latest_build.started_at IS NOT NULL AND
latest_build.canceled_at IS NULL AND
latest_build.completed_at IS NULL AND
latest_build.updated_at - INTERVAL '30 seconds' < NOW() AND
latest_build.transition = 'stop'::workspace_transition

WHEN @status = 'stopped' THEN
latest_build.completed_at IS NOT NULL AND
latest_build.canceled_at IS NULL AND
latest_build.error IS NULL AND
latest_build.transition = 'stop'::workspace_transition

WHEN @status = 'failed' THEN
(latest_build.canceled_at IS NOT NULL AND
latest_build.error IS NOT NULL) OR
(latest_build.completed_at IS NOT NULL AND
latest_build.error IS NOT NULL)

WHEN @status = 'canceling' THEN
latest_build.canceled_at IS NOT NULL AND
latest_build.completed_at IS NULL

WHEN @status = 'canceled' THEN
latest_build.canceled_at IS NOT NULL AND
latest_build.completed_at IS NOT NULL

WHEN @status = 'deleted' THEN
latest_build.started_at IS NOT NULL AND
latest_build.canceled_at IS NULL AND
latest_build.completed_at IS NOT NULL AND
latest_build.updated_at - INTERVAL '30 seconds' < NOW() AND
latest_build.transition = 'delete'::workspace_transition

WHEN @status = 'deleting' THEN
latest_build.completed_at IS NOT NULL AND
latest_build.canceled_at IS NULL AND
latest_build.error IS NULL AND
latest_build.transition = 'delete'::workspace_transition

ELSE
true
END
ELSE true
END
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@coadler I'm curious why we went this route of deriving this in the sql instead of just adding a state field and keeping it up to date in the go code when we change something. Is it because it is difficult to constantly keep this state up to date because of the fact that the build can change state independently?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While writing I thought that's something we could do to improve this, but I wasn't interested in doing it in this PR due to the possible consistency issues.

@presleyp presleyp merged commit 6235708 into main Oct 11, 2022
@presleyp presleyp deleted the running-workspaces/presleyp/3655 branch October 11, 2022 17:50
@github-actions github-actions bot locked and limited conversation to collaborators Oct 11, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Show only running workspaces
4 participants