Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feat(coderd): add task status tracking and RBAC#20212

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Draft
mafredri wants to merge3 commits intomain
base:main
Choose a base branch
Loading
frommafredri/feat-coderd-tasks-data-model

Conversation

mafredri
Copy link
Member

This is a continuation of#19773.

  • Modifytask_workspace_apps to link to workspace build number, allowing us to utilize sorting for the latest entry as well as retaining history
  • Droppedtask_workspace_appsworkspace_build_id sinceworkspace_build_number makes it redundant (except for tracking foreign keys, if we want it can be added back)
  • Add tasks as a new RBAC object
  • Wire intasks <->task_workspace_apps linking inwsbuild andprovisionerdserver
    • wsbuild creates an early link to properly track build/job status of task ASAP
    • provisionerdserver updates agent and app IDs upon completion
  • Noticed task name uniqueness constraint was missing and added it (can be split to separate PR)

Closescoder/internal#948


Notes:

  • We probably need a query to update WorkspaceID for a task after-the-fact, but that can come later

// the agent to a task. For now we overwrite the
// protoAgent.Id because that matches old behavior.
agentID:=uuid.New()
protoAgent.Id=agentID.String()
Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Review: This is potentially the most controversial change. I've retain previous behavior inInsertWorkspaceResource if this value isn't set (e.g. template import).

This basically moves the behavior one level up so that we can access the ID here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I definitely want to defer review of this section to someone with more provisioner knowledge than myself.

@mafredrimafredriforce-pushed themafredri/feat-coderd-tasks-data-model branch from5fa8a93 tob1e8378CompareOctober 8, 2025 12:24
Copy link
Contributor

@DanielleMaywoodDanielleMaywood left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I think this touches on some areas (namelywsbuilder andprovisionerdserver) that I don't feel knowledgeable enough to give this the green light, but it looks good for the most part 👍

Comment on lines +6772 to +6812

ifagentState!="" {
agent:=dbgen.WorkspaceAgent(t,db, database.WorkspaceAgent{
ResourceID:resource.ID,
})
workspaceAgentID:=agent.ID

_,err:=db.UpsertTaskWorkspaceApp(ctx, database.UpsertTaskWorkspaceAppParams{
TaskID:task.ID,
WorkspaceBuildNumber:workspaceBuildNumber,
WorkspaceAgentID: uuid.NullUUID{UUID:workspaceAgentID,Valid:true},
})
require.NoError(t,err)

err=db.UpdateWorkspaceAgentLifecycleStateByID(ctx, database.UpdateWorkspaceAgentLifecycleStateByIDParams{
ID:agent.ID,
LifecycleState:agentState,
})
require.NoError(t,err)

fori,health:=rangeappHealths {
app:=dbgen.WorkspaceApp(t,db, database.WorkspaceApp{
AgentID:workspaceAgentID,
Slug:fmt.Sprintf("test-app-%d",i),
DisplayName:fmt.Sprintf("Test App %d",i+1),
Health:health,
})
ifi==0 {
// Assume the first app is the tasks app.
_,err:=db.UpsertTaskWorkspaceApp(ctx, database.UpsertTaskWorkspaceAppParams{
TaskID:task.ID,
WorkspaceBuildNumber:workspaceBuildNumber,
WorkspaceAgentID: uuid.NullUUID{UUID:workspaceAgentID,Valid:true},
WorkspaceAppID: uuid.NullUUID{UUID:app.ID,Valid:true},
})
require.NoError(t,err)
}
}
}

returntask
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Invert the condition to reduce nesting

Suggested change
ifagentState!="" {
agent:=dbgen.WorkspaceAgent(t,db, database.WorkspaceAgent{
ResourceID:resource.ID,
})
workspaceAgentID:=agent.ID
_,err:=db.UpsertTaskWorkspaceApp(ctx, database.UpsertTaskWorkspaceAppParams{
TaskID:task.ID,
WorkspaceBuildNumber:workspaceBuildNumber,
WorkspaceAgentID: uuid.NullUUID{UUID:workspaceAgentID,Valid:true},
})
require.NoError(t,err)
err=db.UpdateWorkspaceAgentLifecycleStateByID(ctx, database.UpdateWorkspaceAgentLifecycleStateByIDParams{
ID:agent.ID,
LifecycleState:agentState,
})
require.NoError(t,err)
fori,health:=rangeappHealths {
app:=dbgen.WorkspaceApp(t,db, database.WorkspaceApp{
AgentID:workspaceAgentID,
Slug:fmt.Sprintf("test-app-%d",i),
DisplayName:fmt.Sprintf("Test App %d",i+1),
Health:health,
})
ifi==0 {
// Assume the first app is the tasks app.
_,err:=db.UpsertTaskWorkspaceApp(ctx, database.UpsertTaskWorkspaceAppParams{
TaskID:task.ID,
WorkspaceBuildNumber:workspaceBuildNumber,
WorkspaceAgentID: uuid.NullUUID{UUID:workspaceAgentID,Valid:true},
WorkspaceAppID: uuid.NullUUID{UUID:app.ID,Valid:true},
})
require.NoError(t,err)
}
}
}
returntask
ifagentState=="" {
returntask
}
agent:=dbgen.WorkspaceAgent(t,db, database.WorkspaceAgent{
ResourceID:resource.ID,
})
workspaceAgentID:=agent.ID
_,err:=db.UpsertTaskWorkspaceApp(ctx, database.UpsertTaskWorkspaceAppParams{
TaskID:task.ID,
WorkspaceBuildNumber:workspaceBuildNumber,
WorkspaceAgentID: uuid.NullUUID{UUID:workspaceAgentID,Valid:true},
})
require.NoError(t,err)
err=db.UpdateWorkspaceAgentLifecycleStateByID(ctx, database.UpdateWorkspaceAgentLifecycleStateByIDParams{
ID:agent.ID,
LifecycleState:agentState,
})
require.NoError(t,err)
fori,health:=rangeappHealths {
app:=dbgen.WorkspaceApp(t,db, database.WorkspaceApp{
AgentID:workspaceAgentID,
Slug:fmt.Sprintf("test-app-%d",i),
DisplayName:fmt.Sprintf("Test App %d",i+1),
Health:health,
})
ifi==0 {
// Assume the first app is the tasks app.
_,err:=db.UpsertTaskWorkspaceApp(ctx, database.UpsertTaskWorkspaceAppParams{
TaskID:task.ID,
WorkspaceBuildNumber:workspaceBuildNumber,
WorkspaceAgentID: uuid.NullUUID{UUID:workspaceAgentID,Valid:true},
WorkspaceAppID: uuid.NullUUID{UUID:app.ID,Valid:true},
})
require.NoError(t,err)
}
}
returntask

buildStatus:database.ProvisionerJobStatusRunning,
buildTransition:database.WorkspaceTransitionStart,
agentState:database.WorkspaceAgentLifecycleStateReady,
appHealths: []database.WorkspaceAppHealth{database.WorkspaceAppHealthHealthy,database.WorkspaceAppHealthHealthy},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

It looks like this is the only test with two app healths, did we want any other tests that validate the behavior when an appthat isn't the task app is unhealthy?

// the agent to a task. For now we overwrite the
// protoAgent.Id because that matches old behavior.
agentID:=uuid.New()
protoAgent.Id=agentID.String()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I definitely want to defer review of this section to someone with more provisioner knowledge than myself.

@mafredrimafredriforce-pushed themafredri/feat-coderd-tasks-data-model branch fromb1e8378 to9f9d402CompareOctober 8, 2025 13:34
@mafredrimafredriforce-pushed themafredri/feat-coderd-tasks-data-model branch 2 times, most recently from36ff30a tofde6689CompareOctober 8, 2025 14:15
@mafredrimafredriforce-pushed themafredri/feat-coderd-tasks-data-model branch fromfde6689 to12dc05eCompareOctober 8, 2025 14:58
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@DanielleMaywoodDanielleMaywoodDanielleMaywood left review comments

@johnstcnjohnstcnAwaiting requested review from johnstcn

@EmyrkEmyrkAwaiting requested review from EmyrkEmyrk will be requested when the pull request is marked ready for reviewEmyrk is a code owner

At least 1 approving review is required to merge this pull request.

Assignees

@mafredrimafredri

Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

Tasks API: Design and implement tasks data model in database
2 participants
@mafredri@DanielleMaywood

[8]ページ先頭

©2009-2025 Movatter.jp