@@ -363,6 +363,49 @@ func (c *StoreReconciler) ReconcilePreset(ctx context.Context, ps prebuilds.Pres
363
363
364
364
if ps .IsHardLimited {
365
365
logger .Debug (ctx , "skipping hard limited preset" , slog .F ("preset_id" , ps .Preset .ID ), slog .F ("name" , ps .Preset .Name ))
366
+
367
+ // TODO(yevhenii): move into separate func
368
+ // TODO(yevhenii): finish it
369
+ // Send notification to template admins.
370
+ if c .notifEnq == nil {
371
+ c .logger .Warn (ctx , "notification enqueuer not set, cannot send resource replacement notification(s)" )
372
+ return nil
373
+ }
374
+
375
+ templateAdmins , err := c .store .GetUsers (ctx , database.GetUsersParams {
376
+ RbacRole : []string {codersdk .RoleTemplateAdmin },
377
+ })
378
+ if err != nil {
379
+ return xerrors .Errorf ("fetch template admins: %w" , err )
380
+ }
381
+
382
+ for _ , templateAdmin := range templateAdmins {
383
+ if _ , err := c .notifEnq .EnqueueWithData (ctx , templateAdmin .ID , notifications .TemplateWorkspaceResourceReplaced ,
384
+ map [string ]string {
385
+ //"org": org.Name,
386
+ //"workspace": workspace.Name,
387
+ //"template": workspace.TemplateName,
388
+ //"template_version": templateVersion.Name,
389
+ //"preset": prebuildPreset.Name,
390
+ //"workspace_build_num": fmt.Sprintf("%d", build.BuildNumber),
391
+ //"claimant": claimant.Username,
392
+ },
393
+ map [string ]any {
394
+ //"replacements": repls,
395
+ }, "prebuilds_reconciler" ,
396
+ // Associate this notification with all the related entities.
397
+ //workspace.ID, workspace.OwnerID, workspace.TemplateID, templateVersion.ID, prebuildPreset.ID, workspace.OrganizationID,
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