Skip to content

Commit

Permalink
chore: cancel context on signals
Browse files Browse the repository at this point in the history
  • Loading branch information
alecthomas committed Oct 9, 2024
1 parent e25fcf7 commit 09d4f30
Show file tree
Hide file tree
Showing 128 changed files with 63 additions and 217 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,4 @@ junit*.xml
.ftl.lock
docker-build/
**/.ftl
/.frontend.lock
1 change: 0 additions & 1 deletion backend/controller/admin/testdata/go/dischema/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ require (
connectrpc.com/otelconnect v0.7.1 // indirect
github.com/XSAM/otelsql v0.34.0 // indirect
github.com/alecthomas/atomic v0.1.0-alpha2 // indirect
github.com/alecthomas/concurrency v0.0.2 // indirect
github.com/alecthomas/participle/v2 v2.1.1 // indirect
github.com/alecthomas/types v0.16.0 // indirect
github.com/alessio/shellescape v1.4.2 // indirect
Expand Down
2 changes: 0 additions & 2 deletions backend/controller/admin/testdata/go/dischema/go.sum

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

1 change: 0 additions & 1 deletion backend/controller/console/testdata/go/console/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ require (
connectrpc.com/otelconnect v0.7.1 // indirect
github.com/XSAM/otelsql v0.34.0 // indirect
github.com/alecthomas/atomic v0.1.0-alpha2 // indirect
github.com/alecthomas/concurrency v0.0.2 // indirect
github.com/alecthomas/participle/v2 v2.1.1 // indirect
github.com/alecthomas/types v0.16.0 // indirect
github.com/alessio/shellescape v1.4.2 // indirect
Expand Down
2 changes: 0 additions & 2 deletions backend/controller/console/testdata/go/console/go.sum

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

1 change: 0 additions & 1 deletion backend/controller/cronjobs/testdata/go/cron/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ require (
connectrpc.com/otelconnect v0.7.1 // indirect
github.com/XSAM/otelsql v0.34.0 // indirect
github.com/alecthomas/atomic v0.1.0-alpha2 // indirect
github.com/alecthomas/concurrency v0.0.2 // indirect
github.com/alecthomas/participle/v2 v2.1.1 // indirect
github.com/alecthomas/types v0.16.0 // indirect
github.com/alessio/shellescape v1.4.2 // indirect
Expand Down
2 changes: 0 additions & 2 deletions backend/controller/cronjobs/testdata/go/cron/go.sum

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

1 change: 0 additions & 1 deletion backend/controller/dal/testdata/go/fsm/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ require (
github.com/TBD54566975/scaffolder v1.1.0 // indirect
github.com/XSAM/otelsql v0.34.0 // indirect
github.com/alecthomas/atomic v0.1.0-alpha2 // indirect
github.com/alecthomas/concurrency v0.0.2 // indirect
github.com/alecthomas/kong v1.2.1 // indirect
github.com/alecthomas/participle/v2 v2.1.1 // indirect
github.com/alecthomas/repr v0.4.0 // indirect
Expand Down
2 changes: 0 additions & 2 deletions backend/controller/dal/testdata/go/fsm/go.sum

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

1 change: 0 additions & 1 deletion backend/controller/dal/testdata/go/fsmnext/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ require (
github.com/TBD54566975/scaffolder v1.1.0 // indirect
github.com/XSAM/otelsql v0.34.0 // indirect
github.com/alecthomas/atomic v0.1.0-alpha2 // indirect
github.com/alecthomas/concurrency v0.0.2 // indirect
github.com/alecthomas/kong v1.2.1 // indirect
github.com/alecthomas/participle/v2 v2.1.1 // indirect
github.com/alecthomas/repr v0.4.0 // indirect
Expand Down
2 changes: 0 additions & 2 deletions backend/controller/dal/testdata/go/fsmnext/go.sum

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

1 change: 0 additions & 1 deletion backend/controller/dal/testdata/go/fsmretry/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ require (
connectrpc.com/otelconnect v0.7.1 // indirect
github.com/XSAM/otelsql v0.34.0 // indirect
github.com/alecthomas/atomic v0.1.0-alpha2 // indirect
github.com/alecthomas/concurrency v0.0.2 // indirect
github.com/alecthomas/participle/v2 v2.1.1 // indirect
github.com/alecthomas/types v0.16.0 // indirect
github.com/alessio/shellescape v1.4.2 // indirect
Expand Down
2 changes: 0 additions & 2 deletions backend/controller/dal/testdata/go/fsmretry/go.sum

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

Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ require (
connectrpc.com/otelconnect v0.7.1 // indirect
github.com/XSAM/otelsql v0.34.0 // indirect
github.com/alecthomas/atomic v0.1.0-alpha2 // indirect
github.com/alecthomas/concurrency v0.0.2 // indirect
github.com/alecthomas/participle/v2 v2.1.1 // indirect
github.com/alecthomas/types v0.16.0 // indirect
github.com/alessio/shellescape v1.4.2 // indirect
Expand Down
2 changes: 0 additions & 2 deletions backend/controller/encryption/testdata/go/encryption/go.sum

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

1 change: 0 additions & 1 deletion backend/controller/ingress/testdata/go/httpingress/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ require (
connectrpc.com/otelconnect v0.7.1 // indirect
github.com/XSAM/otelsql v0.34.0 // indirect
github.com/alecthomas/atomic v0.1.0-alpha2 // indirect
github.com/alecthomas/concurrency v0.0.2 // indirect
github.com/alecthomas/participle/v2 v2.1.1 // indirect
github.com/alecthomas/types v0.16.0 // indirect
github.com/alessio/shellescape v1.4.2 // indirect
Expand Down
2 changes: 0 additions & 2 deletions backend/controller/ingress/testdata/go/httpingress/go.sum

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

1 change: 0 additions & 1 deletion backend/controller/leases/testdata/go/leases/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ require (
github.com/TBD54566975/scaffolder v1.1.0 // indirect
github.com/XSAM/otelsql v0.34.0 // indirect
github.com/alecthomas/atomic v0.1.0-alpha2 // indirect
github.com/alecthomas/concurrency v0.0.2 // indirect
github.com/alecthomas/kong v1.2.1 // indirect
github.com/alecthomas/participle/v2 v2.1.1 // indirect
github.com/alecthomas/repr v0.4.0 // indirect
Expand Down
2 changes: 0 additions & 2 deletions backend/controller/leases/testdata/go/leases/go.sum

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

1 change: 0 additions & 1 deletion backend/controller/pubsub/testdata/go/publisher/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ require (
connectrpc.com/otelconnect v0.7.1 // indirect
github.com/XSAM/otelsql v0.34.0 // indirect
github.com/alecthomas/atomic v0.1.0-alpha2 // indirect
github.com/alecthomas/concurrency v0.0.2 // indirect
github.com/alecthomas/participle/v2 v2.1.1 // indirect
github.com/alecthomas/types v0.16.0 // indirect
github.com/alessio/shellescape v1.4.2 // indirect
Expand Down
2 changes: 0 additions & 2 deletions backend/controller/pubsub/testdata/go/publisher/go.sum

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

1 change: 0 additions & 1 deletion backend/controller/pubsub/testdata/go/slow/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ require (
connectrpc.com/otelconnect v0.7.1 // indirect
github.com/XSAM/otelsql v0.34.0 // indirect
github.com/alecthomas/atomic v0.1.0-alpha2 // indirect
github.com/alecthomas/concurrency v0.0.2 // indirect
github.com/alecthomas/participle/v2 v2.1.1 // indirect
github.com/alecthomas/types v0.16.0 // indirect
github.com/alessio/shellescape v1.4.2 // indirect
Expand Down
2 changes: 0 additions & 2 deletions backend/controller/pubsub/testdata/go/slow/go.sum

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

1 change: 0 additions & 1 deletion backend/controller/pubsub/testdata/go/subscriber/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ require (
connectrpc.com/grpcreflect v1.2.0 // indirect
connectrpc.com/otelconnect v0.7.1 // indirect
github.com/XSAM/otelsql v0.34.0 // indirect
github.com/alecthomas/concurrency v0.0.2 // indirect
github.com/alecthomas/participle/v2 v2.1.1 // indirect
github.com/alecthomas/types v0.16.0 // indirect
github.com/alessio/shellescape v1.4.2 // indirect
Expand Down
2 changes: 0 additions & 2 deletions backend/controller/pubsub/testdata/go/subscriber/go.sum

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

1 change: 0 additions & 1 deletion backend/controller/sql/testdata/go/database/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ require (
github.com/TBD54566975/scaffolder v1.1.0 // indirect
github.com/XSAM/otelsql v0.34.0 // indirect
github.com/alecthomas/atomic v0.1.0-alpha2 // indirect
github.com/alecthomas/concurrency v0.0.2 // indirect
github.com/alecthomas/kong v1.2.1 // indirect
github.com/alecthomas/participle/v2 v2.1.1 // indirect
github.com/alecthomas/repr v0.4.0 // indirect
Expand Down
2 changes: 0 additions & 2 deletions backend/controller/sql/testdata/go/database/go.sum

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

2 changes: 1 addition & 1 deletion backend/runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ type Config struct {
Language []string `short:"l" help:"Languages the runner supports." env:"FTL_LANGUAGE" default:"go,kotlin,rust,java"`
HeartbeatPeriod time.Duration `help:"Minimum period between heartbeats." default:"3s"`
HeartbeatJitter time.Duration `help:"Jitter to add to heartbeat period." default:"2s"`
Deployment string `help:"The deployment this runner is for." env:"FTL_DEPLOYMENT"`
Deployment string `help:"The deployment this runner is for." env:"FTL_DEPLOYMENT" placeholder:"DEPLOYMENT" required:""`
DebugPort int `help:"The port to use for debugging." env:"FTL_DEBUG_PORT"`
}

Expand Down
6 changes: 4 additions & 2 deletions cmd/ftl-controller/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ import (
"github.com/TBD54566975/ftl/backend/controller"
"github.com/TBD54566975/ftl/backend/controller/leases/dbleaser"
"github.com/TBD54566975/ftl/backend/controller/scaling/k8sscaling"
_ "github.com/TBD54566975/ftl/internal/automaxprocs" // Set GOMAXPROCS to match Linux container CPU quota.
cf "github.com/TBD54566975/ftl/internal/configuration"
cfdal "github.com/TBD54566975/ftl/internal/configuration/dal"
"github.com/TBD54566975/ftl/internal/configuration/manager"
"github.com/TBD54566975/ftl/internal/configuration/providers"
"github.com/TBD54566975/ftl/internal/configuration/routers"
"github.com/TBD54566975/ftl/internal/log"
"github.com/TBD54566975/ftl/internal/observability"
"github.com/TBD54566975/ftl/internal/server"
)

var cli struct {
Expand Down Expand Up @@ -75,6 +75,8 @@ func main() {
kctx.FatalIfErrorf(err)
ctx = manager.ContextWithSecrets(ctx, sm)

err = controller.Start(ctx, cli.ControllerConfig, k8sscaling.NewK8sScaling(cli.DisableIstio), conn, false)
err = server.RunWithSignalHandler(ctx, func(ctx context.Context) error {
return controller.Start(ctx, cli.ControllerConfig, k8sscaling.NewK8sScaling(cli.DisableIstio), conn, false)
})
kctx.FatalIfErrorf(err)
}
6 changes: 4 additions & 2 deletions cmd/ftl-provisioner/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import (

"github.com/TBD54566975/ftl"
"github.com/TBD54566975/ftl/backend/provisioner"
_ "github.com/TBD54566975/ftl/internal/automaxprocs" // Set GOMAXPROCS to match Linux container CPU quota.
"github.com/TBD54566975/ftl/internal/log"
"github.com/TBD54566975/ftl/internal/observability"
"github.com/TBD54566975/ftl/internal/server"
)

var cli struct {
Expand Down Expand Up @@ -43,6 +43,8 @@ func main() {
registry, err := provisioner.RegistryFromConfigFile(ctx, cli.ProvisionerConfig.PluginConfigFile)
kctx.FatalIfErrorf(err, "failed to create provisioner registry")

err = provisioner.Start(ctx, cli.ProvisionerConfig, registry)
err = server.RunWithSignalHandler(ctx, func(ctx context.Context) error {
return provisioner.Start(ctx, cli.ProvisionerConfig, registry)
})
kctx.FatalIfErrorf(err, "failed to start provisioner")
}
8 changes: 6 additions & 2 deletions cmd/ftl-runner/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import (

"github.com/TBD54566975/ftl"
"github.com/TBD54566975/ftl/backend/runner"
_ "github.com/TBD54566975/ftl/internal/automaxprocs" // Set GOMAXPROCS to match Linux container CPU quota.
"github.com/TBD54566975/ftl/internal/log"
"github.com/TBD54566975/ftl/internal/observability"
"github.com/TBD54566975/ftl/internal/server"
)

var cli struct {
Expand Down Expand Up @@ -42,10 +42,14 @@ and route to user code.
}
return key
})

logger := log.Configure(os.Stderr, cli.LogConfig)
ctx := log.ContextWithLogger(context.Background(), logger)

err = observability.Init(ctx, false, "", "ftl-runner", ftl.Version, cli.ObservabilityConfig)
kctx.FatalIfErrorf(err, "failed to initialize observability")
err = runner.Start(ctx, cli.RunnerConfig)
err = server.RunWithSignalHandler(ctx, func(ctx context.Context) error {
return runner.Start(ctx, cli.RunnerConfig)
})
kctx.FatalIfErrorf(err)
}
2 changes: 1 addition & 1 deletion common/plugin/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"golang.org/x/net/http2"
"golang.org/x/net/http2/h2c"

_ "github.com/TBD54566975/ftl/internal/automaxprocs" // Set GOMAXPROCS to match Linux container CPU quota.
_ "github.com/TBD54566975/ftl/internal/server" // Set GOMAXPROCS to match Linux container CPU quota.
ftlhttp "github.com/TBD54566975/ftl/internal/http"
"github.com/TBD54566975/ftl/internal/log"
"github.com/TBD54566975/ftl/internal/rpc"
Expand Down
Loading

0 comments on commit 09d4f30

Please sign in to comment.