Skip to content

Commit

Permalink
Add poll interval flag to CLI dev command (#1318)
Browse files Browse the repository at this point in the history
* Add poll interval flag to CLI dev command

* Fix duration. Adjust polling on discovery.
  • Loading branch information
djfarrelly committed May 3, 2024
1 parent 19dc235 commit ade79fe
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
3 changes: 3 additions & 0 deletions cmd/commands/dev.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ func NewCmdDev() *cobra.Command {
cmd.Flags().StringSliceP("sdk-url", "u", []string{}, "SDK URLs to load functions from")
cmd.Flags().Bool("no-discovery", false, "Disable autodiscovery")
cmd.Flags().Bool("no-poll", false, "Disable polling of apps for updates")
cmd.Flags().Int("poll-interval", 5, "Interval in seconds between polling for updates to apps")
cmd.Flags().Int("retry-interval", 0, "Retry interval in seconds for linear backoff when retrying functions - must be 1 or above")

cmd.Flags().Int("tick", 150, "The interval (in milliseconds) at which the executor checks for new work, during local development")
Expand Down Expand Up @@ -74,6 +75,7 @@ func doDev(cmd *cobra.Command, args []string) {
// Run auto-discovery unless we've explicitly disabled it.
noDiscovery, _ := cmd.Flags().GetBool("no-discovery")
noPoll, _ := cmd.Flags().GetBool("no-poll")
pollInterval, _ := cmd.Flags().GetInt("poll-interval")
retryInterval, _ := cmd.Flags().GetInt("retry-interval")
tick, _ := cmd.Flags().GetInt("tick")

Expand All @@ -93,6 +95,7 @@ func doDev(cmd *cobra.Command, args []string) {
URLs: urls,
Autodiscover: !noDiscovery,
Poll: !noPoll,
PollInterval: pollInterval,
RetryInterval: retryInterval,
Tick: time.Duration(tick) * time.Millisecond,
}
Expand Down
1 change: 1 addition & 0 deletions pkg/devserver/devserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ type StartOpts struct {
URLs []string `json:"urls"`
Autodiscover bool `json:"autodiscover"`
Poll bool `json:"poll"`
PollInterval int `json:"poll_interval"`
Tick time.Duration `json:"tick"`
RetryInterval int `json:"retry_interval"`
}
Expand Down
11 changes: 5 additions & 6 deletions pkg/devserver/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,6 @@ import (
"github.com/mattn/go-isatty"
)

const (
SDKPollInterval = 5 * time.Second
)

func newService(opts StartOpts, runner runner.Runner, data cqrs.Manager, pb pubsub.Publisher) *devserver {
return &devserver{
data: data,
Expand Down Expand Up @@ -184,6 +180,7 @@ func (d *devserver) Stop(ctx context.Context) error {
// any point.
func (d *devserver) runDiscovery(ctx context.Context) {
logger.From(ctx).Info().Msg("autodiscovering locally hosted SDKs")
pollInterval := time.Duration(d.opts.PollInterval) * time.Second
for {
if ctx.Err() != nil {
return
Expand All @@ -193,13 +190,15 @@ func (d *devserver) runDiscovery(ctx context.Context) {
_ = discovery.Autodiscover(ctx)
}

<-time.After(5 * time.Second)
<-time.After(pollInterval)
}
}

// pollSDKs hits each SDK's register endpoint, asking them to communicate with
// the dev server to re-register their functions.
func (d *devserver) pollSDKs(ctx context.Context) {
pollInterval := time.Duration(d.opts.PollInterval) * time.Second

// Initially, add every app started with the `-u` flag
for _, url := range d.opts.URLs {
// URLs must contain a protocol. If not, add http since very few apps
Expand Down Expand Up @@ -272,7 +271,7 @@ func (d *devserver) pollSDKs(ctx context.Context) {
}
}
}
<-time.After(SDKPollInterval)
<-time.After(pollInterval)
}
}

Expand Down

0 comments on commit ade79fe

Please sign in to comment.