Skip to content

Commit 659e2e4

Browse files
committed
Merge branch 'main' into jobstreaming
2 parents 081ffa3 + c3bae67 commit 659e2e4

30 files changed

+8419
-404
lines changed

.github/workflows/coder.yaml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,7 @@ jobs:
7979
- uses: actions/setup-go@v2
8080
with:
8181
go-version: "^1.17"
82-
- run:
83-
curl -sSL
82+
- run: curl -sSL
8483
https://github.com/kyleconroy/sqlc/releases/download/v1.11.0/sqlc_1.11.0_linux_amd64.tar.gz
8584
| sudo tar -C /usr/bin -xz sqlc
8685

@@ -156,15 +155,13 @@ jobs:
156155
terraform_wrapper: false
157156

158157
- name: Test with Mock Database
159-
run:
160-
gotestsum --jsonfile="gotests.json" --packages="./..." --
158+
run: gotestsum --jsonfile="gotests.json" --packages="./..." --
161159
-covermode=atomic -coverprofile="gotests.coverage" -timeout=3m
162-
-count=3 -race -short -parallel=2
160+
-count=5 -race -short -parallel=2
163161

164162
- name: Test with PostgreSQL Database
165163
if: runner.os == 'Linux'
166-
run:
167-
DB=true gotestsum --jsonfile="gotests.json" --packages="./..." --
164+
run: DB=true gotestsum --jsonfile="gotests.json" --packages="./..." --
168165
-covermode=atomic -coverprofile="gotests.coverage" -timeout=3m
169166
-count=1 -race -parallel=2
170167

@@ -201,6 +198,9 @@ jobs:
201198
- run: yarn build
202199
working-directory: site
203200

201+
- run: yarn storybook:build
202+
working-directory: site
203+
204204
- run: yarn test:coverage
205205
working-directory: site
206206

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ yarn-error.log
1919
site/.eslintcache
2020
site/.next/
2121
site/node_modules/
22+
site/storybook-static/
2223
site/yarn-error.log
2324
coverage/
2425

.golangci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,7 @@ linters:
241241
- staticcheck
242242
- structcheck
243243
- tenv
244+
- testpackage
244245
- tparallel
245246
- typecheck
246247
- unconvert

.vscode/settings.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
"goleak",
3535
"hashicorp",
3636
"httpmw",
37+
"Jobf",
3738
"moby",
3839
"nhooyr",
3940
"nolint",

coderd/coderd.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ type Options struct {
2222
// New constructs the Coder API into an HTTP handler.
2323
func New(options *Options) http.Handler {
2424
api := &api{
25-
Logger: options.Logger,
2625
Database: options.Database,
26+
Logger: options.Logger,
2727
Pubsub: options.Pubsub,
2828
}
2929

@@ -116,7 +116,7 @@ func New(options *Options) http.Handler {
116116
// API contains all route handlers. Only HTTP handlers should
117117
// be added to this struct for code clarity.
118118
type api struct {
119-
Logger slog.Logger
120119
Database database.Store
120+
Logger slog.Logger
121121
Pubsub database.Pubsub
122122
}

coderd/coderdtest/coderdtest.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ func New(t *testing.T) Server {
125125
}
126126

127127
handler := coderd.New(&coderd.Options{
128-
Logger: slogtest.Make(t, nil),
128+
Logger: slogtest.Make(t, nil).Leveled(slog.LevelDebug),
129129
Database: db,
130130
Pubsub: pubsub,
131131
})

coderd/provisionerdaemons.go

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ import (
1919
"storj.io/drpc/drpcmux"
2020
"storj.io/drpc/drpcserver"
2121

22+
"cdr.dev/slog"
23+
2224
"github.com/coder/coder/coderd/projectparameter"
2325
"github.com/coder/coder/database"
2426
"github.com/coder/coder/httpapi"
@@ -84,6 +86,7 @@ func (api *api) provisionerDaemonsServe(rw http.ResponseWriter, r *http.Request)
8486
Database: api.Database,
8587
Pubsub: api.Pubsub,
8688
Provisioners: daemon.Provisioners,
89+
Logger: api.Logger.Named(fmt.Sprintf("provisionerd-%s", daemon.Name)),
8790
})
8891
if err != nil {
8992
_ = conn.Close(websocket.StatusInternalError, fmt.Sprintf("drpc register provisioner daemon: %s", err))
@@ -109,6 +112,7 @@ type projectImportJob struct {
109112
// Implementation of the provisioner daemon protobuf server.
110113
type provisionerdServer struct {
111114
ID uuid.UUID
115+
Logger slog.Logger
112116
Provisioners []database.ProvisionerType
113117
Database database.Store
114118
Pubsub database.Pubsub
@@ -136,9 +140,11 @@ func (server *provisionerdServer) AcquireJob(ctx context.Context, _ *proto.Empty
136140
if err != nil {
137141
return nil, xerrors.Errorf("acquire job: %w", err)
138142
}
143+
server.Logger.Debug(ctx, "locked job from database", slog.F("id", job.ID))
144+
139145
// Marks the acquired job as failed with the error message provided.
140146
failJob := func(errorMessage string) error {
141-
err = server.Database.UpdateProvisionerJobByID(ctx, database.UpdateProvisionerJobByIDParams{
147+
err = server.Database.UpdateProvisionerJobWithCompleteByID(ctx, database.UpdateProvisionerJobWithCompleteByIDParams{
142148
ID: job.ID,
143149
CompletedAt: sql.NullTime{
144150
Time: database.Now(),
@@ -381,8 +387,12 @@ func (server *provisionerdServer) CancelJob(ctx context.Context, cancelJob *prot
381387
if err != nil {
382388
return nil, xerrors.Errorf("parse job id: %w", err)
383389
}
384-
err = server.Database.UpdateProvisionerJobByID(ctx, database.UpdateProvisionerJobByIDParams{
390+
err = server.Database.UpdateProvisionerJobWithCompleteByID(ctx, database.UpdateProvisionerJobWithCompleteByIDParams{
385391
ID: jobID,
392+
CompletedAt: sql.NullTime{
393+
Time: database.Now(),
394+
Valid: true,
395+
},
386396
CancelledAt: sql.NullTime{
387397
Time: database.Now(),
388398
Valid: true,
@@ -476,7 +486,7 @@ func (server *provisionerdServer) CompleteJob(ctx context.Context, completed *pr
476486

477487
// This must occur in a transaction in case of failure.
478488
err = server.Database.InTx(func(db database.Store) error {
479-
err = db.UpdateProvisionerJobByID(ctx, database.UpdateProvisionerJobByIDParams{
489+
err = db.UpdateProvisionerJobWithCompleteByID(ctx, database.UpdateProvisionerJobWithCompleteByIDParams{
480490
ID: jobID,
481491
UpdatedAt: database.Now(),
482492
CompletedAt: sql.NullTime{
@@ -495,6 +505,7 @@ func (server *provisionerdServer) CompleteJob(ctx context.Context, completed *pr
495505
return xerrors.Errorf("insert project parameter %q: %w", projectParameter.Name, err)
496506
}
497507
}
508+
server.Logger.Debug(ctx, "marked import job as completed", slog.F("job_id", jobID))
498509
return nil
499510
})
500511
if err != nil {
@@ -513,7 +524,7 @@ func (server *provisionerdServer) CompleteJob(ctx context.Context, completed *pr
513524
}
514525

515526
err = server.Database.InTx(func(db database.Store) error {
516-
err = db.UpdateProvisionerJobByID(ctx, database.UpdateProvisionerJobByIDParams{
527+
err = db.UpdateProvisionerJobWithCompleteByID(ctx, database.UpdateProvisionerJobWithCompleteByIDParams{
517528
ID: jobID,
518529
UpdatedAt: database.Now(),
519530
CompletedAt: sql.NullTime{

coderd/provisioners.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ type ProvisionerJobStatus string
1212

1313
// Completed returns whether the job is still processing.
1414
func (p ProvisionerJobStatus) Completed() bool {
15-
return p == ProvisionerJobStatusSucceeded || p == ProvisionerJobStatusFailed
15+
return p == ProvisionerJobStatusSucceeded || p == ProvisionerJobStatusFailed || p == ProvisionerJobStatusCancelled
1616
}
1717

1818
const (

coderd/workspacehistory.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,10 @@ func (api *api) postWorkspaceHistoryByUser(rw http.ResponseWriter, r *http.Reque
8383
Message: fmt.Sprintf("The provided project history %q has failed to import. You cannot create workspaces using it!", projectHistory.Name),
8484
})
8585
return
86+
case ProvisionerJobStatusCancelled:
87+
httpapi.Write(rw, http.StatusPreconditionFailed, httpapi.Response{
88+
Message: "The provided project history was canceled during import. You cannot create workspaces using it!",
89+
})
8690
}
8791

8892
project, err := api.Database.GetProjectByID(r.Context(), projectHistory.ProjectID)

coderd/workspacehistory_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ func TestWorkspaceHistory(t *testing.T) {
5656
require.Eventually(t, func() bool {
5757
hist, err := client.ProjectHistory(context.Background(), user.Organization, project.Name, projectHistory.Name)
5858
require.NoError(t, err)
59+
t.Logf("Import status: %s\n", hist.Import.Status)
5960
return hist.Import.Status.Completed()
6061
}, 15*time.Second, 50*time.Millisecond)
6162
return projectHistory

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy