Skip to content

Commit

Permalink
Add NoHTTP init mode for ephemeral tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
vearutop committed Feb 14, 2023
1 parent 60a0668 commit 8dc75e7
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ type StartOptions struct {
// it can be used to override defaults via env vars.
EnvPrepare func() error

// NoHTTP instructs application to exit instead of starting HTTP server.
NoHTTP bool

// OnHTTPStart is called after the HTTP server is started.
OnHTTPStart func(addr string)
}
Expand Down Expand Up @@ -61,18 +64,22 @@ func Start(cfg WithBaseConfig, init func(docsMode bool) (*BaseLocator, http.Hand

loc, router := init(false)

addr, err := loc.StartHTTPServer(router)
if err != nil {
loc.CtxdLogger().Error(context.Background(), "failed to start http server: %v", "error", err)
os.Exit(1)
}
if !opt.NoHTTP {
addr, err := loc.StartHTTPServer(router)
if err != nil {
loc.CtxdLogger().Error(context.Background(), "failed to start http server: %v", "error", err)
os.Exit(1)
}

Check notice on line 72 in cmd.go

View workflow job for this annotation

GitHub Actions / test (1.20.x)

9 statement(s) on lines 63:72 are not covered by tests.

if opt.OnHTTPStart != nil {
opt.OnHTTPStart(addr)
if opt.OnHTTPStart != nil {
opt.OnHTTPStart(addr)
}
} else {
loc.Shutdown()

Check notice on line 78 in cmd.go

View workflow job for this annotation

GitHub Actions / test (1.20.x)

3 statement(s) on lines 74:79 are not covered by tests.
}

// Wait for service loc termination finished.
err = <-loc.Wait()
// Wait for service locator termination finished.
err := <-loc.Wait()

Check notice on line 82 in cmd.go

View workflow job for this annotation

GitHub Actions / test (1.20.x)

2 statement(s) on lines 82:83 are not covered by tests.
if err != nil {
loc.CtxdLogger().Error(context.Background(), err.Error())
}
Expand Down

0 comments on commit 8dc75e7

Please sign in to comment.