Skip to content

High-performance browser automation bridge and multi-instance orchestrator with advanced stealth injection and real-time dashboard.

feat(scheduler): make MaxBatchSize and WatcherInterval configurable

Yash Jadhav2930ffe28233
diff --git a/internal/scheduler/batch.go b/internal/scheduler/batch.go
index 1fbdbd3e..07c2c68c 100644
--- a/internal/scheduler/batch.go
+++ b/internal/scheduler/batch.go
@@ -9,8 +9,6 @@ import (
"github.com/pinchtab/pinchtab/internal/web"
)
-const maxBatchSize = 50
-
var (
errMissingAgentID = errors.New("missing required field 'agentId'")
errEmptyBatch = errors.New("batch must contain at least one task")
@@ -56,10 +54,13 @@ func (s *Scheduler) handleBatch(w http.ResponseWriter, r *http.Request) {
web.Error(w, 400, errEmptyBatch)
return
}
- if len(req.Tasks) > maxBatchSize {
+ s.cfgMu.RLock()
+ maxBatch := s.cfg.MaxBatchSize
+ s.cfgMu.RUnlock()
+ if len(req.Tasks) > maxBatch {
web.ErrorCode(w, 400, "batch_too_large", "batch exceeds maximum size", false, map[string]any{
"submitted": len(req.Tasks),
- "max": maxBatchSize,
+ "max": maxBatch,
})
return
}
diff --git a/internal/scheduler/batch_test.go b/internal/scheduler/batch_test.go
index 8cbe7346..38aa359d 100644
--- a/internal/scheduler/batch_test.go
+++ b/internal/scheduler/batch_test.go
@@ -88,8 +88,8 @@ func TestHandleBatchTooLarge(t *testing.T) {
_, mux, executor := setupHandlerTest(t)
defer executor.Close()
- // Build batch with maxBatchSize+1 tasks.
- tasks := make([]map[string]string, maxBatchSize+1)
+ // Build batch with more than the default max (50) tasks.
+ tasks := make([]map[string]string, 51)
for i := range tasks {
tasks[i] = map[string]string{"action": "click", "tabId": "t1"}
}
diff --git a/internal/scheduler/scheduler.go b/internal/scheduler/scheduler.go
index 82fbea7a..26d6ad66 100644
--- a/internal/scheduler/scheduler.go
+++ b/internal/scheduler/scheduler.go
@@ -29,6 +29,8 @@ type Config struct {
MaxPerAgentFlight int `json:"maxPerAgentInflight"`
ResultTTL time.Duration `json:"resultTTL"`
WorkerCount int `json:"workerCount"`
+ MaxBatchSize int `json:"maxBatchSize"`
+ WatcherInterval time.Duration `json:"watcherInterval"`
}
// DefaultConfig returns safe defaults.
@@ -41,6 +43,8 @@ func DefaultConfig() Config {
MaxPerAgentFlight: 10,
ResultTTL: 5 * time.Minute,
WorkerCount: 4,
+ MaxBatchSize: 50,
+ WatcherInterval: 30 * time.Second,
}
}
@@ -90,6 +94,12 @@ func New(cfg Config, resolver InstanceResolver) *Scheduler {
if cfg.WorkerCount <= 0 {
cfg.WorkerCount = 4
}
+ if cfg.MaxBatchSize <= 0 {
+ cfg.MaxBatchSize = 50
+ }
+ if cfg.WatcherInterval <= 0 {
+ cfg.WatcherInterval = 30 * time.Second
+ }
return &Scheduler{
cfg: cfg,