(ctx context.Context, workspace database.Workspace, build database.WorkspaceBuild)
| 2630 | } |
| 2631 | |
| 2632 | func (s *server) notifyWorkspaceDeleted(ctx context.Context, workspace database.Workspace, build database.WorkspaceBuild) { |
| 2633 | var reason string |
| 2634 | initiator := build.InitiatorByUsername |
| 2635 | if build.Reason.Valid() { |
| 2636 | switch build.Reason { |
| 2637 | case database.BuildReasonInitiator: |
| 2638 | if build.InitiatorID == workspace.OwnerID { |
| 2639 | // Deletions initiated by self should not notify. |
| 2640 | return |
| 2641 | } |
| 2642 | |
| 2643 | reason = "initiated by user" |
| 2644 | case database.BuildReasonAutodelete: |
| 2645 | reason = "autodeleted due to dormancy" |
| 2646 | initiator = "autobuild" |
| 2647 | default: |
| 2648 | reason = string(build.Reason) |
| 2649 | } |
| 2650 | } else { |
| 2651 | reason = string(build.Reason) |
| 2652 | s.Logger.Warn(ctx, "invalid build reason when sending deletion notification", |
| 2653 | slog.F("reason", reason), slog.F("workspace_id", workspace.ID), slog.F("build_id", build.ID)) |
| 2654 | } |
| 2655 | |
| 2656 | if _, err := s.NotificationsEnqueuer.Enqueue(ctx, workspace.OwnerID, notifications.TemplateWorkspaceDeleted, |
| 2657 | map[string]string{ |
| 2658 | "name": workspace.Name, |
| 2659 | "reason": reason, |
| 2660 | "initiator": initiator, |
| 2661 | }, "provisionerdserver", |
| 2662 | // Associate this notification with all the related entities. |
| 2663 | workspace.ID, workspace.OwnerID, workspace.TemplateID, workspace.OrganizationID, |
| 2664 | ); err != nil { |
| 2665 | s.Logger.Warn(ctx, "failed to notify of workspace deletion", slog.Error(err)) |
| 2666 | } |
| 2667 | } |
| 2668 | |
| 2669 | func (s *server) startTrace(ctx context.Context, name string, opts ...trace.SpanStartOption) (context.Context, trace.Span) { |
| 2670 | return s.Tracer.Start(ctx, name, append(opts, trace.WithAttributes( |
no test coverage detected