Skip to content

feat: add lifecycle.Executor to manage autostart and autostop #1183

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 28 commits into from
May 11, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
a145d6d
feat: add lifecycle.Executor to autostart workspaces.
johnstcn Apr 19, 2022
8f401ca
refactor: do not expose Store in coderdtest.Options
johnstcn Apr 26, 2022
6d8f5fe
fixup! refactor: do not expose Store in coderdtest.Options
johnstcn Apr 26, 2022
cfd0d1e
stop accessing db directly, only query workspaces with autostart enabled
johnstcn Apr 26, 2022
ce63810
refactor unit tests, add tests for autostop
johnstcn Apr 26, 2022
579f362
make the new tests pass with some refactoring
johnstcn Apr 30, 2022
6e88f67
gitignore *.swp
johnstcn Apr 30, 2022
2b1a383
remove unused methods
johnstcn Apr 30, 2022
f31588e
fixup! remove unused methods
johnstcn Apr 30, 2022
80e0581
fix: range over channel, add continue to default switch case
johnstcn May 9, 2022
d176478
add test for deleted workspace
johnstcn May 9, 2022
bd97c1a
workspaces.sql: remove unused methods
johnstcn May 10, 2022
0931d25
unexport test helper methods
johnstcn May 10, 2022
faebe2e
chore: rename package autostart/lifecycle to lifecycle/executor
johnstcn May 10, 2022
abc0854
add test to ensure workspaces are not autostarted before time
johnstcn May 10, 2022
e53946a
wire up executor to coderd
johnstcn May 10, 2022
364a27c
fix: executor: skip workspaces whose last build was not successful
johnstcn May 10, 2022
e96414f
address PR comments
johnstcn May 11, 2022
b5bf50e
add goleak TestMain
johnstcn May 11, 2022
d37cc2b
fmt
johnstcn May 11, 2022
d11f5d7
mustTransitionWorkspace should return the updated workspace
johnstcn May 11, 2022
f6388b4
remove usage of require.Eventually/Never which is flaky on Windows
johnstcn May 11, 2022
fd0f8a3
make lifecycle executor spawn a new goroutine automatically
johnstcn May 11, 2022
7b6f2e1
rename unit tests
johnstcn May 11, 2022
a7143bd
s/doBuild/build
johnstcn May 11, 2022
7d9b696
rename parent package lifecycle to autobuild
johnstcn May 11, 2022
5cba737
add unit test for behaviour with an updated template
johnstcn May 11, 2022
7627372
add ticket to reference TODO
johnstcn May 11, 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
Prev Previous commit
Next Next commit
chore: rename package autostart/lifecycle to lifecycle/executor
  • Loading branch information
johnstcn committed May 10, 2022
commit faebe2e27e0917b6481a941212d8d3dec82ff2fe
2 changes: 1 addition & 1 deletion cli/autostart.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

"github.com/spf13/cobra"

"github.com/coder/coder/coderd/autostart/schedule"
"github.com/coder/coder/coderd/lifecycle/schedule"
"github.com/coder/coder/codersdk"
)

Expand Down
2 changes: 1 addition & 1 deletion cli/autostop.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

"github.com/spf13/cobra"

"github.com/coder/coder/coderd/autostart/schedule"
"github.com/coder/coder/coderd/lifecycle/schedule"
"github.com/coder/coder/codersdk"
)

Expand Down
5 changes: 2 additions & 3 deletions coderd/coderdtest/coderdtest.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ import (
"testing"
"time"

"github.com/coder/coder/coderd/autostart/lifecycle"

"cloud.google.com/go/compute/metadata"
"github.com/fullsailor/pkcs7"
"github.com/golang-jwt/jwt"
Expand All @@ -43,6 +41,7 @@ import (
"github.com/coder/coder/coderd/database/databasefake"
"github.com/coder/coder/coderd/database/postgres"
"github.com/coder/coder/coderd/gitsshkey"
"github.com/coder/coder/coderd/lifecycle/executor"
"github.com/coder/coder/coderd/turnconn"
"github.com/coder/coder/codersdk"
"github.com/coder/coder/cryptorand"
Expand Down Expand Up @@ -105,7 +104,7 @@ func New(t *testing.T, options *Options) *codersdk.Client {
}

ctx, cancelFunc := context.WithCancel(context.Background())
lifecycleExecutor := lifecycle.NewExecutor(
lifecycleExecutor := executor.New(
ctx,
db,
slogtest.Make(t, nil).Named("lifecycle.executor").Leveled(slog.LevelDebug),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package lifecycle
package executor
Copy link
Member

Choose a reason for hiding this comment

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

What do you think about calling the lifecycle package autobuild or cronbuild? I'm concerned about calling it lifecycle, since that term could be interpreted very broadly.

Copy link
Member Author

Choose a reason for hiding this comment

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

autobuild is better and does what it says on the tin.

Copy link
Contributor

@greyscaled greyscaled May 11, 2022

Choose a reason for hiding this comment

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

comment(in-support): autobuild seems intuitive/useful to me.


import (
"context"
Expand All @@ -7,8 +7,8 @@ import (

"cdr.dev/slog"

"github.com/coder/coder/coderd/autostart/schedule"
"github.com/coder/coder/coderd/database"
"github.com/coder/coder/coderd/lifecycle/schedule"

"github.com/google/uuid"
"github.com/moby/moby/pkg/namesgenerator"
Expand All @@ -23,8 +23,8 @@ type Executor struct {
tick <-chan time.Time
}

// NewExecutor returns a new instance of Executor.
func NewExecutor(ctx context.Context, db database.Store, log slog.Logger, tick <-chan time.Time) *Executor {
// New returns a new lifecycle executor.
func New(ctx context.Context, db database.Store, log slog.Logger, tick <-chan time.Time) *Executor {
le := &Executor{
ctx: ctx,
db: db,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package lifecycle_test
package executor_test

import (
"context"
"testing"
"time"

"github.com/coder/coder/coderd/autostart/schedule"
"github.com/coder/coder/coderd/coderdtest"
"github.com/coder/coder/coderd/database"
"github.com/coder/coder/coderd/lifecycle/schedule"
"github.com/coder/coder/codersdk"

"github.com/google/uuid"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

"github.com/stretchr/testify/require"

"github.com/coder/coder/coderd/autostart/schedule"
"github.com/coder/coder/coderd/lifecycle/schedule"
)

func Test_Weekly(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion coderd/workspaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ import (
"github.com/moby/moby/pkg/namesgenerator"
"golang.org/x/xerrors"

"github.com/coder/coder/coderd/autostart/schedule"
"github.com/coder/coder/coderd/database"
"github.com/coder/coder/coderd/httpapi"
"github.com/coder/coder/coderd/httpmw"
"github.com/coder/coder/coderd/lifecycle/schedule"
"github.com/coder/coder/codersdk"
)

Expand Down
2 changes: 1 addition & 1 deletion coderd/workspaces_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import (
"github.com/google/uuid"
"github.com/stretchr/testify/require"

"github.com/coder/coder/coderd/autostart/schedule"
"github.com/coder/coder/coderd/coderdtest"
"github.com/coder/coder/coderd/database"
"github.com/coder/coder/coderd/lifecycle/schedule"
"github.com/coder/coder/codersdk"
"github.com/coder/coder/provisioner/echo"
"github.com/coder/coder/provisionersdk/proto"
Expand Down