Skip to content

refactor(agent): update agentcontainers api initialization #17600

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 16 commits into from
Apr 29, 2025
Prev Previous commit
Next Next commit
rename start to ready
  • Loading branch information
mafredri committed Apr 29, 2025
commit 17fa155d64b54cbb6cefb474b078c60f23be9272
7 changes: 4 additions & 3 deletions agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -1169,9 +1169,10 @@ func (a *agent) handleManifest(manifestOK *checkpoint) func(ctx context.Context,
a.metrics.startupScriptSeconds.WithLabelValues(label).Set(dur)
a.scriptRunner.StartCron()
if a.containerAPI != nil {
// Start the containerAPI service after
// devcontainers have been started.
a.containerAPI.Start()
// Inform the container API that the agent is ready.
// This allows us to start watching for changes to
// the devcontainer configuration files.
a.containerAPI.Ready()
}
})
if err != nil {
Expand Down
8 changes: 5 additions & 3 deletions agent/agentcontainers/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,11 @@ func NewAPI(logger slog.Logger, options ...Option) *API {
return api
}

// Start watching for devcontainer config file changes and prime the
// cache with the current list of containers.
func (api *API) Start() {
// Ready signals the API that we are ready to begin watching for file
// changes. This is used to prime the cache with the current list of
// containers and to start watching the devcontainer config files for
// changes. It should be called after the agent ready.
func (api *API) Ready() {
// Prime the cache with the current list of containers.
_, _ = api.cl.List(api.ctx)

Expand Down
2 changes: 1 addition & 1 deletion agent/agentcontainers/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -634,7 +634,7 @@ func TestAPI(t *testing.T) {
)
defer api.Close()

api.Start()
api.Ready()

r := chi.NewRouter()
r.Mount("/", api.Routes())
Expand Down
Loading