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

Commit977a883

Browse files
committed
add agent names
1 parent97ac5bc commit977a883

File tree

10 files changed

+51
-12
lines changed

10 files changed

+51
-12
lines changed

‎coderd/database/dbmem/dbmem.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11116,7 +11116,7 @@ func (q *FakeQuerier) GetAuthorizedWorkspacesAndAgents(ctx context.Context, prep
1111611116
returnnil,xerrors.Errorf("get provisioner job: %w",err)
1111711117
}
1111811118

11119-
agentIDs:=make([]uuid.UUID,0)
11119+
outAgents:=make([]database.AgentIDNamePair,0)
1112011120
resources,err:=q.getWorkspaceResourcesByJobIDNoLock(ctx,job.ID)
1112111121
iferr!=nil {
1112211122
returnnil,xerrors.Errorf("get workspace resources: %w",err)
@@ -11127,7 +11127,10 @@ func (q *FakeQuerier) GetAuthorizedWorkspacesAndAgents(ctx context.Context, prep
1112711127
returnnil,xerrors.Errorf("get workspace agents: %w",err)
1112811128
}
1112911129
for_,a:=rangeagents {
11130-
agentIDs=append(agentIDs,a.ID)
11130+
outAgents=append(outAgents, database.AgentIDNamePair{
11131+
ID:a.ID,
11132+
Name:a.Name,
11133+
})
1113111134
}
1113211135
}
1113311136

@@ -11136,7 +11139,7 @@ func (q *FakeQuerier) GetAuthorizedWorkspacesAndAgents(ctx context.Context, prep
1113611139
WorkspaceName:w.Name,
1113711140
JobStatus:job.JobStatus,
1113811141
Transition:build.Transition,
11139-
AgentIds:agentIDs,
11142+
Agents:outAgents,
1114011143
})
1114111144
}
1114211145

‎coderd/database/dump.sql

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
DROPTYPE agent_id_name_pair;
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
CREATETYPEagent_id_name_pairAS (
2+
id uuid,
3+
nametext
4+
);

‎coderd/database/modelqueries.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ func (q *sqlQuerier) GetAuthorizedWorkspacesAndAgents(ctx context.Context, prepa
337337
&i.WorkspaceName,
338338
&i.JobStatus,
339339
&i.Transition,
340-
pq.Array(&i.AgentIds),
340+
pq.Array(&i.Agents),
341341
);err!=nil {
342342
returnnil,err
343343
}

‎coderd/database/querier_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -691,17 +691,17 @@ func TestGetAuthorizedWorkspacesAndAgents(t *testing.T) {
691691
for_,row:=rangeownerRows {
692692
switchrow.WorkspaceID {
693693
casependingID:
694-
require.Len(t,row.AgentIds,1)
694+
require.Len(t,row.Agents,1)
695695
require.Equal(t,database.ProvisionerJobStatusPending,row.JobStatus)
696696
casefailedID:
697-
require.Len(t,row.AgentIds,1)
697+
require.Len(t,row.Agents,1)
698698
require.Equal(t,database.ProvisionerJobStatusFailed,row.JobStatus)
699699
casesucceededID:
700-
require.Len(t,row.AgentIds,2)
700+
require.Len(t,row.Agents,2)
701701
require.Equal(t,database.ProvisionerJobStatusSucceeded,row.JobStatus)
702702
require.Equal(t,database.WorkspaceTransitionStart,row.Transition)
703703
casedeletedID:
704-
require.Len(t,row.AgentIds,0)
704+
require.Len(t,row.Agents,0)
705705
require.Equal(t,database.ProvisionerJobStatusSucceeded,row.JobStatus)
706706
require.Equal(t,database.WorkspaceTransitionDelete,row.Transition)
707707
default:

‎coderd/database/queries.sql.go

Lines changed: 4 additions & 3 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎coderd/database/queries/workspaces.sql

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -694,7 +694,7 @@ SELECT
694694
workspaces.nameas workspace_name,
695695
job_status,
696696
transition,
697-
(array_agg(agent_id) FILTER (WHERE agent_idIS NOT NULL))::uuid[]asagent_ids
697+
(array_agg(ROW(agent_id, agent_name)::agent_id_name_pair) FILTER (WHERE agent_idIS NOT NULL))::agent_id_name_pair[]asagents
698698
FROM workspaces
699699
LEFT JOIN LATERAL (
700700
SELECT
@@ -711,6 +711,7 @@ LEFT JOIN LATERAL (
711711
LEFT JOIN (
712712
SELECT
713713
workspace_agents.idas agent_id,
714+
workspace_agents.nameas agent_name,
714715
job_id
715716
FROM workspace_resources
716717
JOIN workspace_agentsONworkspace_agents.resource_id=workspace_resources.id
@@ -719,3 +720,4 @@ LEFT JOIN (
719720
-- @authorize_filter
720721
GROUP BYworkspaces.id,workspaces.name,latest_build.job_status,latest_build.job_id,latest_build.transition;
721722

723+

‎coderd/database/sqlc.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ sql:
2828
emit_enum_valid_method:true
2929
emit_all_enum_values:true
3030
overrides:
31+
-db_type:"agent_id_name_pair"
32+
go_type:
33+
type:"AgentIDNamePair"
3134
# Used in 'CustomRoles' query to filter by (name,organization_id)
3235
-db_type:"name_organization_pair"
3336
go_type:

‎coderd/database/types.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,3 +174,23 @@ func (*NameOrganizationPair) Scan(_ interface{}) error {
174174
func (aNameOrganizationPair)Value() (driver.Value,error) {
175175
returnfmt.Sprintf(`(%s,%s)`,a.Name,a.OrganizationID.String()),nil
176176
}
177+
178+
// AgentIDNamePair is used as a result tuple for workspace and agent rows.
179+
typeAgentIDNamePairstruct {
180+
ID uuid.UUID`db:"id" json:"id"`
181+
Namestring`db:"name" json:"name"`
182+
}
183+
184+
func (p*AgentIDNamePair)Scan(srcinterface{})error {
185+
switchv:=src.(type) {
186+
case []byte:
187+
returnjson.Unmarshal(v,&p)
188+
casestring:
189+
returnjson.Unmarshal([]byte(v),&p)
190+
}
191+
returnxerrors.Errorf("unexpected type %T",src)
192+
}
193+
194+
func (pAgentIDNamePair)Value() (driver.Value,error) {
195+
returnfmt.Sprintf(`(%s,%s)`,p.ID.String(),p.Name),nil
196+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp