@@ -362,7 +362,50 @@ func (c *StoreReconciler) ReconcilePreset(ctx context.Context, ps prebuilds.Pres
362
362
)
363
363
364
364
if ps .IsHardLimited {
365
- logger .Debug (ctx , "skipping hard limited preset" , slog .F ("preset_id" , ps .Preset .ID ), slog .F ("name" , ps .Preset .Name ))
365
+ logger .Warn (ctx , "skipping hard limited preset" , slog .F ("preset_id" , ps .Preset .ID ), slog .F ("name" , ps .Preset .Name ))
366
+
367
+ // TODO: rename ctx?
368
+ // nolint:gocritic // Necessary to query all the required data.
369
+ ctx := dbauthz .AsSystemRestricted (ctx )
370
+
371
+ // TODO(yevhenii): move into separate function
372
+ // Send notification to template admins.
373
+ if c .notifEnq == nil {
374
+ c .logger .Warn (ctx , "notification enqueuer not set, cannot send resource replacement notification(s)" )
375
+ return nil
376
+ }
377
+
378
+ // TODO(yevhenii): remove owner from the list
379
+ templateAdmins , err := c .store .GetUsers (ctx , database.GetUsersParams {
380
+ RbacRole : []string {codersdk .RoleTemplateAdmin , codersdk .RoleOwner },
381
+ })
382
+ if err != nil {
383
+ return xerrors .Errorf ("fetch template admins: %w" , err )
384
+ }
385
+
386
+ for _ , templateAdmin := range templateAdmins {
387
+ if _ , err := c .notifEnq .EnqueueWithData (ctx , templateAdmin .ID , notifications .PrebuildFailureLimitReached ,
388
+ map [string ]string {
389
+ "org" : ps .Preset .OrganizationName ,
390
+ "template" : ps .Preset .TemplateName ,
391
+ "template_version" : ps .Preset .TemplateVersionName ,
392
+ "preset" : ps .Preset .Name ,
393
+ },
394
+ map [string ]any {},
395
+ "prebuilds_reconciler" ,
396
+ // Associate this notification with all the related entities.
397
+ ps .Preset .TemplateID , ps .Preset .TemplateVersionID , ps .Preset .ID ,
398
+ ); err != nil {
399
+ c .logger .Error (ctx ,
400
+ "failed to send notification" ,
401
+ slog .Error (err ),
402
+ slog .F ("template_admin_id" , templateAdmin .ID .String ()),
403
+ )
404
+
405
+ continue
406
+ }
407
+ }
408
+
366
409
return nil
367
410
}
368
411
0 commit comments