MCPcopy Index your code
hub / github.com/coder/coder / workspaceProxyDeregister

Method workspaceProxyDeregister

enterprise/coderd/workspaceproxy.go:794–855  ·  view source on GitHub ↗

@Summary Deregister workspace proxy @ID deregister-workspace-proxy @Security CoderSessionToken @Accept json @Tags Enterprise @Param request body wsproxysdk.DeregisterWorkspaceProxyRequest true "Deregister workspace proxy request" @Success 204 @Router /api/v2/workspaceproxies/me/deregister [post] @x-

(rw http.ResponseWriter, r *http.Request)

Source from the content-addressed store, hash-verified

792// @Router /api/v2/workspaceproxies/me/deregister [post]
793// @x-apidocgen {"skip": true}
794func (api *API) workspaceProxyDeregister(rw http.ResponseWriter, r *http.Request) {
795 ctx := r.Context()
796
797 var req wsproxysdk.DeregisterWorkspaceProxyRequest
798 if !httpapi.Read(ctx, rw, r, &req) {
799 return
800 }
801
802 err := api.Database.InTx(func(db database.Store) error {
803 now := time.Now()
804 replica, err := db.GetReplicaByID(ctx, req.ReplicaID)
805 if err != nil {
806 return xerrors.Errorf("get replica: %w", err)
807 }
808
809 if replica.StoppedAt.Valid && !replica.StartedAt.IsZero() {
810 // TODO: sadly this results in 500 when it should be 400
811 return xerrors.Errorf("replica %s is already marked stopped", replica.ID)
812 }
813
814 replica, err = db.UpdateReplica(ctx, database.UpdateReplicaParams{
815 ID: replica.ID,
816 UpdatedAt: now,
817 StartedAt: replica.StartedAt,
818 StoppedAt: sql.NullTime{
819 Valid: true,
820 Time: now,
821 },
822 RelayAddress: replica.RelayAddress,
823 RegionID: replica.RegionID,
824 Hostname: replica.Hostname,
825 Version: replica.Version,
826 Error: replica.Error,
827 DatabaseLatency: replica.DatabaseLatency,
828 Primary: replica.Primary,
829 })
830 if err != nil {
831 return xerrors.Errorf("update replica: %w", err)
832 }
833
834 return nil
835 }, nil)
836 if httpapi.Is404Error(err) {
837 httpapi.ResourceNotFound(rw)
838 return
839 }
840 if err != nil {
841 httpapi.InternalServerError(rw, err)
842 return
843 }
844
845 // Publish a replicasync event with a nil ID so every replica (yes, even the
846 // current replica) will refresh its replicas list.
847 err = api.Pubsub.Publish(replicasync.PubsubEvent, []byte(uuid.Nil.String()))
848 if err != nil {
849 httpapi.InternalServerError(rw, err)
850 return
851 }

Callers

nothing calls this directly

Calls 14

ReadFunction · 0.92
Is404ErrorFunction · 0.92
ResourceNotFoundFunction · 0.92
InternalServerErrorFunction · 0.92
ContextMethod · 0.65
InTxMethod · 0.65
GetReplicaByIDMethod · 0.65
UpdateReplicaMethod · 0.65
PublishMethod · 0.65
ErrorfMethod · 0.45
IsZeroMethod · 0.45

Tested by

no test coverage detected