@@ -1098,7 +1098,8 @@ func (s *server) FailJob(ctx context.Context, failJob *proto.FailedJob) (*proto.
1098
1098
func (s * server ) notifyWorkspaceBuildFailed (ctx context.Context , workspace database.Workspace , build database.WorkspaceBuild ) {
1099
1099
var reason string
1100
1100
if build .Reason .Valid () && build .Reason == database .BuildReasonInitiator {
1101
- return // failed workspace build initiated by a user should not notify
1101
+ s .notifyWorkspaceManualBuildFailed (ctx , workspace , build )
1102
+ return
1102
1103
}
1103
1104
reason = string (build .Reason )
1104
1105
@@ -1114,6 +1115,43 @@ func (s *server) notifyWorkspaceBuildFailed(ctx context.Context, workspace datab
1114
1115
}
1115
1116
}
1116
1117
1118
+ func (s * server ) notifyWorkspaceManualBuildFailed (ctx context.Context , workspace database.Workspace , build database.WorkspaceBuild ) {
1119
+ templateAdmins , err := s .Database .GetUsers (ctx , database.GetUsersParams {
1120
+ RbacRole : []string {codersdk .RoleTemplateAdmin },
1121
+ })
1122
+ if err != nil {
1123
+ s .Logger .Error (ctx , "unable to fetch template admins" , slog .Error (err ))
1124
+ return
1125
+ }
1126
+
1127
+ template , err := s .Database .GetTemplateByID (ctx , workspace .TemplateID )
1128
+ if err != nil {
1129
+ s .Logger .Error (ctx , "unable to fetch template" , slog .Error (err ))
1130
+ return
1131
+ }
1132
+
1133
+ workspaceOwner , err := s .Database .GetUserByID (ctx , workspace .OwnerID )
1134
+ if err != nil {
1135
+ s .Logger .Error (ctx , "unable to fetch workspace owner" , slog .Error (err ))
1136
+ return
1137
+ }
1138
+
1139
+ for _ , templateAdmin := range templateAdmins {
1140
+ if _ , err := s .NotificationsEnqueuer .Enqueue (ctx , templateAdmin .ID , notifications .TemplateWorkspaceManualBuildFailed ,
1141
+ map [string ]string {
1142
+ "name" : workspace .Name ,
1143
+ "template_name" : template .Name ,
1144
+ "initiator" : build .InitiatorByUsername ,
1145
+ "workspace_owner_username" : workspaceOwner .Name ,
1146
+ }, "provisionerdserver" ,
1147
+ // Associate this notification with all the related entities.
1148
+ workspace .ID , workspace .OwnerID , workspace .TemplateID , workspace .OrganizationID ,
1149
+ ); err != nil {
1150
+ s .Logger .Warn (ctx , "failed to notify of failed workspace autobuild" , slog .Error (err ))
1151
+ }
1152
+ }
1153
+ }
1154
+
1117
1155
// CompleteJob is triggered by a provision daemon to mark a provisioner job as completed.
1118
1156
func (s * server ) CompleteJob (ctx context.Context , completed * proto.CompletedJob ) (* proto.Empty , error ) {
1119
1157
ctx , span := s .startTrace (ctx , tracing .FuncName ())
0 commit comments