Skip to content

fix(UI): workspace restart button stops build before starting a new one #7301

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 7 commits into from
Apr 28, 2023

Conversation

Kira-Pilot
Copy link
Member

Resolves #6241 and replaces the reverted #7268.

I've added a test to ensure the restart button hook is called appropriately but React Query makes it difficult to test side effects so I'm effectively mocking the stopWorkspace api call and not the startWorkspace api call. I will take a second look at this during a quieter day, but for the time being, smoke testing would be appreciated!

Kira-Pilot and others added 6 commits April 24, 2023 19:55
* Refactor primary buttons

* refactor(site): Always show the main actions

* Remove tests that are testes on Storybook

* Fix tests

* Fix keys

* added restart btn

---------

Co-authored-by: BrunoQuaresma <bruno_nonato_quaresma@hotmail.com>
}
},
})
}
Copy link
Member Author

Choose a reason for hiding this comment

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

Originally, I wanted to use an implementation closer to the following, which react query's docs suggest is possible:

 const requestStopWorkspace = useMutation({ mutationFn: stopWorkspace })
 const requestStartWorkspace = useMutation({ mutationFn: startWorkspace })

  const restartWorkspace = async () => {
    try {
      await requestStopWorkspace.mutateAsync(workspace.id)
      await waitForStop(requestStopWorkspace.data)
      await requestStartWorkspace.mutateAsync({
        workspaceId,
        templateVersionId,
      })
    } catch (error) {
      ...   
    }
  }

but mutateAsync does not seem to be working and the queries are not treated asynchronously. @BrunoQuaresma is this something you've run into before?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I put a comment above, I think you don't need to have each API call into a "query". You can have a single function to restart the workspace and wrap this function into a query.

Copy link
Member Author

Choose a reason for hiding this comment

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

Hmmm that's a good idea. Let me try it!

Copy link
Member Author

Choose a reason for hiding this comment

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

@BrunoQuaresma Woo that's a lot better! Thanks!

@ammario
Copy link
Member

ammario commented Apr 26, 2023

Thank you for fixing this so quickly :)

@Kira-Pilot Kira-Pilot requested a review from bpmct April 27, 2023 20:08
Copy link
Member

@bpmct bpmct left a comment

Choose a reason for hiding this comment

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

Works as expected with AWS template (stops workspace then starts)

@Kira-Pilot Kira-Pilot merged commit a2ff674 into main Apr 28, 2023
@Kira-Pilot Kira-Pilot deleted the restart-button-3/kira-pilot branch April 28, 2023 18:16
@github-actions github-actions bot locked and limited conversation to collaborators Apr 28, 2023
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.

feat: add a restart button
4 participants