public void updateWorkerPoolMinInstances()

in src/main/java/com/google/cloud/run/kafkascaler/clients/CloudRunClientWrapper.java [114:150]


  public void updateWorkerPoolMinInstances(String workerpoolName, int instances)
      throws IOException {
    GoogleCloudRunV2WorkerPool workerpool = getWorkerPool(workerpoolName);

    GoogleCloudRunV2WorkerPoolScaling oldScaling = workerpool.getScaling();
    GoogleCloudRunV2WorkerPoolScaling newScaling = new GoogleCloudRunV2WorkerPoolScaling();
    if (oldScaling != null && oldScaling.getMaxInstanceCount() != null) {
      newScaling.setMaxInstanceCount(oldScaling.getMaxInstanceCount());
    }

    newScaling.setMinInstanceCount(instances);
    newScaling.setScalingMode(AUTOMATIC_SCALING_MODE);

    workerpool.setScaling(newScaling);

    GoogleLongrunningOperation operation =
        this.cloudRun
            .projects()
            .locations()
            .workerPools()
            .patch(
                String.format(
                    "projects/%s/locations/%s/workerPools/%s",
                    this.projectId, this.region, workerpoolName),
                workerpool)
            .setUpdateMask(SCALING_UPDATE_MASK)
            .execute();

    if (operation.getError() != null) {
      throw new IOException(
          "Request failed to Cloud Run to update workerpool instances: " + operation.getError());
    } else {
      logger.atInfo().log(
          "Sent update workerpool request to set instances to %d for workerpool %s",
          instances, workerpoolName);
    }
  }