Skip to content

Commit

Permalink
Invalidate too large batch sizes (#1289)
Browse files Browse the repository at this point in the history
  • Loading branch information
goodoldneon committed Apr 18, 2024
1 parent 12c6cf0 commit fb29ea0
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
6 changes: 6 additions & 0 deletions pkg/inngest/batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@ func (c EventBatchConfig) IsValid() error {
Message: fmt.Sprintf("batch size cannot be smaller than 2: %d", c.MaxSize),
}
}
if c.MaxSize > consts.DefaultBatchSize {
return syscode.Error{
Code: syscode.CodeBatchSizeInvalid,
Message: fmt.Sprintf("batch size cannot be larger than %d", consts.DefaultBatchSize),
}
}

if _, err := time.ParseDuration(c.Timeout); err != nil {
return fmt.Errorf("invalid timeout string: %v", err)
Expand Down
19 changes: 15 additions & 4 deletions pkg/inngest/function.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
multierror "github.com/hashicorp/go-multierror"
"github.com/inngest/inngest/pkg/consts"
"github.com/inngest/inngest/pkg/expressions"
"github.com/inngest/inngest/pkg/syscode"
"github.com/xhit/go-str2duration/v2"
)

Expand Down Expand Up @@ -257,6 +258,20 @@ func (f Function) Validate(ctx context.Context) error {
if berr := f.EventBatch.IsValid(); berr != nil {
err = multierror.Append(err, berr)
}

if len(f.Cancel) > 0 {
err = multierror.Append(err, syscode.Error{
Code: syscode.CodeComboUnsupported,
Message: "Batching and cancellation are mutually exclusive",
})
}

if f.Debounce != nil {
err = multierror.Append(err, syscode.Error{
Code: syscode.CodeComboUnsupported,
Message: "Batching and debouncing are mutually exclusive",
})
}
}

for _, step := range f.Steps {
Expand Down Expand Up @@ -343,10 +358,6 @@ func (f Function) Validate(ctx context.Context) error {
}
}

// NOTE: Debounce is not valid when batch is enabled.
if f.EventBatch != nil {
err = multierror.Append(err, fmt.Errorf("A function cannot specify batch and debounce"))
}
period, perr := str2duration.ParseDuration(f.Debounce.Period)
if perr != nil {
err = multierror.Append(err, fmt.Errorf("The debounce period of '%s' is invalid: %w", f.Debounce.Period, perr))
Expand Down
1 change: 1 addition & 0 deletions pkg/syscode/codes.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package syscode

const (
CodeBatchSizeInvalid = "batch_size_invalid"
CodeComboUnsupported = "combo_unsupported"
CodeConcurrencyLimitInvalid = "concurrency_limit_invalid"
CodeConfigInvalid = "config_invalid"
CodeUnknown = "unknown"
Expand Down

0 comments on commit fb29ea0

Please sign in to comment.