public function flush() {
    $count = count($this->queue);
    $success = true;

    while ($count > 0 && $success) {
      $batch = array_splice($this->queue, 0, min($this->batch_size, $count));
      $success = $this->flushBatch($batch);

      $count = count($this->queue);
    }

    return $success;
  }