@@ -197,20 +197,10 @@ func (api *API) postRefreshEntitlements(rw http.ResponseWriter, r *http.Request)
197
197
return
198
198
}
199
199
200
- err = api .updateEntitlements (ctx )
201
- if err != nil {
202
- httpapi .Write (ctx ,rw ,http .StatusInternalServerError , codersdk.Response {
203
- Message :"Failed to update entitlements" ,
204
- Detail :err .Error (),
205
- })
206
- return
207
- }
208
-
209
- err = api .Pubsub .Publish (PubsubEventLicenses , []byte ("refresh" ))
200
+ err = api .refreshEntitlements (ctx )
210
201
if err != nil {
211
- api .Logger .Error (context .Background (),"failed to publish forced entitlement update" ,slog .Error (err ))
212
202
httpapi .Write (ctx ,rw ,http .StatusInternalServerError , codersdk.Response {
213
- Message :"Failed topublish forced entitlement update. Other replicas might not be updated. " ,
203
+ Message :"Failed torefresh entitlements " ,
214
204
Detail :err .Error (),
215
205
})
216
206
return
@@ -221,6 +211,21 @@ func (api *API) postRefreshEntitlements(rw http.ResponseWriter, r *http.Request)
221
211
})
222
212
}
223
213
214
+ func (api * API )refreshEntitlements (ctx context.Context )error {
215
+ api .Logger .Info (ctx ,"refresh entitlements now" )
216
+
217
+ err := api .updateEntitlements (ctx )
218
+ if err != nil {
219
+ return xerrors .Errorf ("failed to update entitlements: %w" ,err )
220
+ }
221
+ err = api .Pubsub .Publish (PubsubEventLicenses , []byte ("refresh" ))
222
+ if err != nil {
223
+ api .Logger .Error (ctx ,"failed to publish forced entitlement update" ,slog .Error (err ))
224
+ return xerrors .Errorf ("failed to publish forced entitlement update, other replicas might not be updated: %w" ,err )
225
+ }
226
+ return nil
227
+ }
228
+
224
229
// @Summary Get licenses
225
230
// @ID get-licenses
226
231
// @Security CoderSessionToken