diff --git a/pkg/inngest/batch.go b/pkg/inngest/batch.go index d206d4e61..5acce9624 100644 --- a/pkg/inngest/batch.go +++ b/pkg/inngest/batch.go @@ -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) diff --git a/pkg/inngest/function.go b/pkg/inngest/function.go index 5cbcd7fdb..fe295db98 100644 --- a/pkg/inngest/function.go +++ b/pkg/inngest/function.go @@ -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" ) @@ -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 { @@ -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)) diff --git a/pkg/syscode/codes.go b/pkg/syscode/codes.go index 2229d3386..adcc60e39 100644 --- a/pkg/syscode/codes.go +++ b/pkg/syscode/codes.go @@ -2,6 +2,7 @@ package syscode const ( CodeBatchSizeInvalid = "batch_size_invalid" + CodeComboUnsupported = "combo_unsupported" CodeConcurrencyLimitInvalid = "concurrency_limit_invalid" CodeConfigInvalid = "config_invalid" CodeUnknown = "unknown"