scale method

Future<void> scale(
  1. int newWorkerCount
)

Scale the worker pool (add or remove workers)

Implementation

Future<void> scale(int newWorkerCount) async {
  if (newWorkerCount < 1) {
    throw ArgumentError('Worker count must be at least 1');
  }

  if (newWorkerCount == _workerCount) {
    return;
  }

  if (newWorkerCount > _workerCount) {
    // Add workers
    final workersToAdd = newWorkerCount - _workerCount;
    for (int i = 0; i < workersToAdd; i++) {
      final worker = QueueWorker(_driver, _config);
      _workers.add(worker);
      if (_isRunning) {
        worker.start();
      }
    }
    print('✅ Scaled up to $newWorkerCount workers');
  } else {
    // Remove workers
    final workersToRemove = _workerCount - newWorkerCount;
    for (int i = 0; i < workersToRemove; i++) {
      final worker = _workers.removeLast();
      await worker.stop();
    }
    print('✅ Scaled down to $newWorkerCount workers');
  }
}