( ctx context.Context, logger slog.Logger, requesterID uuid.UUID, workspace database.Workspace, workspaceBuild codersdk.WorkspaceBuild, template database.Template, allowRenames bool, latestAppStatus codersdk.WorkspaceAppStatus, )
| 2789 | } |
| 2790 | |
| 2791 | func convertWorkspace( |
| 2792 | ctx context.Context, |
| 2793 | logger slog.Logger, |
| 2794 | requesterID uuid.UUID, |
| 2795 | workspace database.Workspace, |
| 2796 | workspaceBuild codersdk.WorkspaceBuild, |
| 2797 | template database.Template, |
| 2798 | allowRenames bool, |
| 2799 | latestAppStatus codersdk.WorkspaceAppStatus, |
| 2800 | ) (codersdk.Workspace, error) { |
| 2801 | if requesterID == uuid.Nil { |
| 2802 | return codersdk.Workspace{}, xerrors.Errorf("developer error: requesterID cannot be uuid.Nil!") |
| 2803 | } |
| 2804 | var autostartSchedule *string |
| 2805 | if workspace.AutostartSchedule.Valid { |
| 2806 | autostartSchedule = &workspace.AutostartSchedule.String |
| 2807 | } |
| 2808 | |
| 2809 | var dormantAt *time.Time |
| 2810 | if workspace.DormantAt.Valid { |
| 2811 | dormantAt = &workspace.DormantAt.Time |
| 2812 | } |
| 2813 | |
| 2814 | var deletingAt *time.Time |
| 2815 | if workspace.DeletingAt.Valid { |
| 2816 | deletingAt = &workspace.DeletingAt.Time |
| 2817 | } |
| 2818 | |
| 2819 | var nextStartAt *time.Time |
| 2820 | if workspace.NextStartAt.Valid { |
| 2821 | nextStartAt = &workspace.NextStartAt.Time |
| 2822 | } |
| 2823 | |
| 2824 | failingAgents := []uuid.UUID{} |
| 2825 | for _, resource := range workspaceBuild.Resources { |
| 2826 | for _, agent := range resource.Agents { |
| 2827 | // Sub-agents (e.g., devcontainer agents) are excluded from the |
| 2828 | // workspace health calculation. Their health is managed by |
| 2829 | // their parent agent, and temporary disconnections during |
| 2830 | // devcontainer rebuilds should not affect workspace health. |
| 2831 | if agent.ParentID.Valid { |
| 2832 | continue |
| 2833 | } |
| 2834 | if !agent.Health.Healthy { |
| 2835 | failingAgents = append(failingAgents, agent.ID) |
| 2836 | } |
| 2837 | } |
| 2838 | } |
| 2839 | |
| 2840 | ttlMillis := convertWorkspaceTTLMillis(workspace.Ttl) |
| 2841 | // If the template doesn't allow a workspace-configured value, then report the |
| 2842 | // template value instead. |
| 2843 | if !template.AllowUserAutostop { |
| 2844 | ttlMillis = convertWorkspaceTTLMillis(sql.NullInt64{Valid: true, Int64: template.DefaultTTL}) |
| 2845 | } |
| 2846 | |
| 2847 | // Only show favorite status if you own the workspace. |
| 2848 | requesterFavorite := workspace.OwnerID == requesterID && workspace.Favorite |
no test coverage detected