public void updateWorkerPoolManualInstances()

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


  public void updateWorkerPoolManualInstances(String workerpoolName, int instances)
      throws IOException {
    GoogleCloudRunV2WorkerPoolScaling scaling = new GoogleCloudRunV2WorkerPoolScaling();
    scaling.setManualInstanceCount(instances);
    scaling.setScalingMode(MANUAL_SCALING_MODE);

    GoogleCloudRunV2WorkerPool workerpool = getWorkerPool(workerpoolName);
    workerpool.setScaling(scaling);
    workerpool.setLaunchStage(ALPHA_LAUNCH_STAGE);

    GoogleLongrunningOperation operation =
        this.cloudRun
            .projects()
            .locations()
            .workerPools()
            .patch(
                String.format(
                    "projects/%s/locations/%s/workerPools/%s",
                    this.projectId, this.region, workerpoolName),
                workerpool)
            .setUpdateMask(SCALING_AND_LAUNCH_STAGE_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);
    }
  }