Skip to content

Commit 20f421a

Browse files
committed
send "going away" mesasge on licenses pubsub on close
1 parent 1b6431b commit 20f421a

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

enterprise/coderd/coderd.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -800,6 +800,13 @@ func (api *API) runEntitlementsLoop(ctx context.Context) {
800800
updates := make(chan struct{}, 1)
801801
subscribed := false
802802

803+
defer func() {
804+
// If this function ends, it means the context was cancelled and this
805+
// coderd is shutting down. In this case, post a pubsub message to
806+
// tell other coderd's to resync their entitlements. This is required to
807+
// make sure things like replica counts are updated in the UI.
808+
_ = api.Pubsub.Publish(PubsubEventLicenses, []byte("going away"))
809+
}()
803810
for {
804811
select {
805812
case <-ctx.Done():

enterprise/coderd/licenses.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,13 +184,22 @@ func (api *API) postRefreshEntitlements(rw http.ResponseWriter, r *http.Request)
184184
wait := time.Minute - diff
185185
rw.Header().Set("Retry-After", strconv.Itoa(int(wait.Seconds())))
186186
httpapi.Write(ctx, rw, http.StatusBadRequest, codersdk.Response{
187-
Message: fmt.Sprintf("Entitlements already recently refreshed, please wait %d seconds to force a new refresh", wait),
187+
Message: fmt.Sprintf("Entitlements already recently refreshed, please wait %d seconds to force a new refresh", int(wait.Seconds())),
188188
Detail: fmt.Sprintf("Last refresh at %s", now.UTC().String()),
189189
})
190190
return
191191
}
192192

193-
err := api.updateEntitlements(ctx)
193+
err := api.replicaManager.UpdateNow(ctx)
194+
if err != nil {
195+
httpapi.Write(ctx, rw, http.StatusInternalServerError, codersdk.Response{
196+
Message: "Failed to sync replicas",
197+
Detail: err.Error(),
198+
})
199+
return
200+
}
201+
202+
err = api.updateEntitlements(ctx)
194203
if err != nil {
195204
httpapi.Write(ctx, rw, http.StatusInternalServerError, codersdk.Response{
196205
Message: "Failed to update entitlements",

site/src/api/api.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -821,6 +821,7 @@ export const getEntitlements = async (): Promise<TypesGen.Entitlements> => {
821821
require_telemetry: false,
822822
trial: false,
823823
warnings: [],
824+
refreshed_at:"",
824825
}
825826
}
826827
throw ex

0 commit comments

Comments
 (0)