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

coderd: autostart: codersdk, http api, database plumbing#879

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

Merged
johnstcn merged 16 commits intomainfromcj/autostart_dbschema
Apr 7, 2022
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
Show all changes
16 commits
Select commitHold shift + click to select a range
1438444
feat: add columns autostart_schedule, autostop_schedule to database s…
johnstcnApr 4, 2022
400a787
feat: database: add UpdateWorkspaceAutostart and UpdateWorkspaceAutos…
johnstcnApr 4, 2022
c581615
fix: sqlc generate
johnstcnApr 5, 2022
9a3b186
fix: databasefake: implement now-missing AutoStop/AutoStart methods
johnstcnApr 5, 2022
6fa386d
feat: add AutostartSchedule/AutostopSchedule to api workspace struct
johnstcnApr 5, 2022
f6895b7
feat: implement update workspace autostart
johnstcnApr 5, 2022
1884766
refactor: make test table-driven
johnstcnApr 5, 2022
9854f9b
fix: autostart: add more test cases
johnstcnApr 5, 2022
270af35
fix: autostart: ensure we handle DST changes properly
johnstcnApr 5, 2022
ff80571
fix: coderd: add test for nonexistent workspace
johnstcnApr 5, 2022
3b4664c
fix: codersdk: add documentation for UpdateWorkspaceAutostartRequest …
johnstcnApr 5, 2022
ccd67cc
fix: appease the linter gods
johnstcnApr 5, 2022
316501d
fix: address PR comments
johnstcnApr 6, 2022
3037d98
fix: workspaces_test.go: missed project -> template after rebase
johnstcnApr 6, 2022
4a7e6eb
fix: bump migration
johnstcnApr 6, 2022
be0e6f3
feat: implement autostop database/http/api plumbing
johnstcnApr 6, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletionscoderd/coderd.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -184,6 +184,12 @@ func New(options *Options) (http.Handler, func()) {
r.Post("/", api.postWorkspaceBuilds)
r.Get("/{workspacebuildname}", api.workspaceBuildByName)
})
r.Route("/autostart", func(r chi.Router) {
r.Put("/", api.putWorkspaceAutostart)
})
r.Route("/autostop", func(r chi.Router) {
r.Put("/", api.putWorkspaceAutostop)
})
})
r.Route("/workspacebuilds/{workspacebuild}", func(r chi.Router) {
r.Use(
Expand Down
52 changes: 42 additions & 10 deletionscoderd/database/databasefake/databasefake.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -27,7 +27,7 @@ func New() database.Store {
provisionerDaemons: make([]database.ProvisionerDaemon, 0),
provisionerJobs: make([]database.ProvisionerJob, 0),
provisionerJobLog: make([]database.ProvisionerJobLog, 0),
workspace: make([]database.Workspace, 0),
workspaces: make([]database.Workspace, 0),
provisionerJobResource: make([]database.WorkspaceResource, 0),
workspaceBuild: make([]database.WorkspaceBuild, 0),
provisionerJobAgent: make([]database.WorkspaceAgent, 0),
Expand DownExpand Up@@ -56,7 +56,7 @@ type fakeQuerier struct {
provisionerJobAgent []database.WorkspaceAgent
provisionerJobResource []database.WorkspaceResource
provisionerJobLog []database.ProvisionerJobLog
workspace []database.Workspace
workspaces []database.Workspace
workspaceBuild []database.WorkspaceBuild
GitSSHKey []database.GitSSHKey
}
Expand DownExpand Up@@ -169,7 +169,7 @@ func (q *fakeQuerier) GetWorkspacesByTemplateID(_ context.Context, arg database.
defer q.mutex.RUnlock()

workspaces := make([]database.Workspace, 0)
for _, workspace := range q.workspace {
for _, workspace := range q.workspaces {
if workspace.TemplateID.String() != arg.TemplateID.String() {
continue
}
Expand All@@ -188,7 +188,7 @@ func (q *fakeQuerier) GetWorkspaceByID(_ context.Context, id uuid.UUID) (databas
q.mutex.RLock()
defer q.mutex.RUnlock()

for _, workspace := range q.workspace {
for _, workspace := range q.workspaces {
if workspace.ID.String() == id.String() {
return workspace, nil
}
Expand All@@ -200,7 +200,7 @@ func (q *fakeQuerier) GetWorkspaceByUserIDAndName(_ context.Context, arg databas
q.mutex.RLock()
defer q.mutex.RUnlock()

for _, workspace := range q.workspace {
for _, workspace := range q.workspaces {
if workspace.OwnerID != arg.OwnerID {
continue
}
Expand All@@ -222,7 +222,7 @@ func (q *fakeQuerier) GetWorkspaceOwnerCountsByTemplateIDs(_ context.Context, te
counts := map[uuid.UUID]map[uuid.UUID]struct{}{}
for _, templateID := range templateIDs {
found := false
for _, workspace := range q.workspace {
for _, workspace := range q.workspaces {
if workspace.TemplateID != templateID {
continue
}
Expand DownExpand Up@@ -350,7 +350,7 @@ func (q *fakeQuerier) GetWorkspacesByUserID(_ context.Context, req database.GetW
defer q.mutex.RUnlock()

workspaces := make([]database.Workspace, 0)
for _, workspace := range q.workspace {
for _, workspace := range q.workspaces {
if workspace.OwnerID != req.OwnerID {
continue
}
Expand DownExpand Up@@ -1040,7 +1040,7 @@ func (q *fakeQuerier) InsertWorkspace(_ context.Context, arg database.InsertWork
TemplateID: arg.TemplateID,
Name: arg.Name,
}
q.workspace = append(q.workspace, workspace)
q.workspaces = append(q.workspaces, workspace)
return workspace, nil
}

Expand DownExpand Up@@ -1210,6 +1210,38 @@ func (q *fakeQuerier) UpdateProvisionerJobWithCompleteByID(_ context.Context, ar
return sql.ErrNoRows
}

func (q *fakeQuerier) UpdateWorkspaceAutostart(_ context.Context, arg database.UpdateWorkspaceAutostartParams) error {
q.mutex.Lock()
defer q.mutex.Unlock()

for index, workspace := range q.workspaces {
if workspace.ID.String() != arg.ID.String() {
continue
}
workspace.AutostartSchedule = arg.AutostartSchedule
q.workspaces[index] = workspace
return nil
}

return sql.ErrNoRows
}

func (q *fakeQuerier) UpdateWorkspaceAutostop(_ context.Context, arg database.UpdateWorkspaceAutostopParams) error {
q.mutex.Lock()
defer q.mutex.Unlock()

for index, workspace := range q.workspaces {
if workspace.ID.String() != arg.ID.String() {
continue
}
workspace.AutostopSchedule = arg.AutostopSchedule
q.workspaces[index] = workspace
return nil
}

return sql.ErrNoRows
}

func (q *fakeQuerier) UpdateWorkspaceBuildByID(_ context.Context, arg database.UpdateWorkspaceBuildByIDParams) error {
q.mutex.Lock()
defer q.mutex.Unlock()
Expand All@@ -1231,12 +1263,12 @@ func (q *fakeQuerier) UpdateWorkspaceDeletedByID(_ context.Context, arg database
q.mutex.Lock()
defer q.mutex.Unlock()

for index, workspace := range q.workspace {
for index, workspace := range q.workspaces {
if workspace.ID.String() != arg.ID.String() {
continue
}
workspace.Deleted = arg.Deleted
q.workspace[index] = workspace
q.workspaces[index] = workspace
return nil
}
return sql.ErrNoRows
Expand Down
4 changes: 3 additions & 1 deletioncoderd/database/dump.sql
View file
Open in desktop

Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.

View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
ALTER TABLE ONLY workspaces
DROP COLUMN IF EXISTS autostart_schedule,
DROP COLUMN IF EXISTS autostop_schedule;
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
ALTER TABLE ONLY workspaces
ADD COLUMN IF NOT EXISTS autostart_schedule text DEFAULT NULL,
ADD COLUMN IF NOT EXISTS autostop_schedule text DEFAULT NULL;
16 changes: 9 additions & 7 deletionscoderd/database/models.go
View file
Open in desktop

Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.

2 changes: 2 additions & 0 deletionscoderd/database/querier.go
View file
Open in desktop

Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.

58 changes: 53 additions & 5 deletionscoderd/database/queries.sql.go
View file
Open in desktop

Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.

16 changes: 16 additions & 0 deletionscoderd/database/queries/workspaces.sql
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -68,3 +68,19 @@ SET
deleted = $2
WHERE
id = $1;

-- name: UpdateWorkspaceAutostart :exec
UPDATE
workspaces
SET
autostart_schedule = $2
WHERE
id = $1;

-- name: UpdateWorkspaceAutostop :exec
UPDATE
workspaces
SET
autostop_schedule = $2
WHERE
id = $1;
Loading

[8]ページ先頭

©2009-2025 Movatter.jp