/** * Resume a job. * * <p>This method reenables a job after it has been * [Job.State.PAUSED][google.cloud.scheduler.v1beta1.Job.State.PAUSED]. The state of a job is * stored in [Job.state][google.cloud.scheduler.v1beta1.Job.state]; after calling this method it * will be set to [Job.State.ENABLED][google.cloud.scheduler.v1beta1.Job.State.ENABLED]. A job * must be in [Job.State.PAUSED][google.cloud.scheduler.v1beta1.Job.State.PAUSED] to be resumed. * * <p>Sample code: * * <pre><code> * try (CloudSchedulerClient cloudSchedulerClient = CloudSchedulerClient.create()) { * JobName name = JobName.of("[PROJECT]", "[LOCATION]", "[JOB]"); * Job response = cloudSchedulerClient.resumeJob(name.toString()); * } * </code></pre> * * @param name Required. * <p>The job name. For example: `projects/PROJECT_ID/locations/LOCATION_ID/jobs/JOB_ID`. * @throws com.google.api.gax.rpc.ApiException if the remote call fails */ public final Job resumeJob(String name) { ResumeJobRequest request = ResumeJobRequest.newBuilder().setName(name).build(); return resumeJob(request); }
/** * Resume a job. * * <p>This method reenables a job after it has been * [Job.State.PAUSED][google.cloud.scheduler.v1beta1.Job.State.PAUSED]. The state of a job is * stored in [Job.state][google.cloud.scheduler.v1beta1.Job.state]; after calling this method it * will be set to [Job.State.ENABLED][google.cloud.scheduler.v1beta1.Job.State.ENABLED]. A job * must be in [Job.State.PAUSED][google.cloud.scheduler.v1beta1.Job.State.PAUSED] to be resumed. * * <p>Sample code: * * <pre><code> * try (CloudSchedulerClient cloudSchedulerClient = CloudSchedulerClient.create()) { * JobName name = JobName.of("[PROJECT]", "[LOCATION]", "[JOB]"); * Job response = cloudSchedulerClient.resumeJob(name); * } * </code></pre> * * @param name Required. * <p>The job name. For example: `projects/PROJECT_ID/locations/LOCATION_ID/jobs/JOB_ID`. * @throws com.google.api.gax.rpc.ApiException if the remote call fails */ public final Job resumeJob(JobName name) { ResumeJobRequest request = ResumeJobRequest.newBuilder().setName(name == null ? null : name.toString()).build(); return resumeJob(request); }
@Test @SuppressWarnings("all") public void resumeJobExceptionTest() throws Exception { StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT); mockCloudScheduler.addException(exception); try { JobName name = JobName.of("[PROJECT]", "[LOCATION]", "[JOB]"); client.resumeJob(name); Assert.fail("No exception raised"); } catch (InvalidArgumentException e) { // Expected exception } }
@Test @SuppressWarnings("all") public void resumeJobTest() { JobName name2 = JobName.of("[PROJECT]", "[LOCATION]", "[JOB]"); String description = "description-1724546052"; String schedule = "schedule-697920873"; String timeZone = "timeZone36848094"; Job expectedResponse = Job.newBuilder() .setName(name2.toString()) .setDescription(description) .setSchedule(schedule) .setTimeZone(timeZone) .build(); mockCloudScheduler.addResponse(expectedResponse); JobName name = JobName.of("[PROJECT]", "[LOCATION]", "[JOB]"); Job actualResponse = client.resumeJob(name); Assert.assertEquals(expectedResponse, actualResponse); List<GeneratedMessageV3> actualRequests = mockCloudScheduler.getRequests(); Assert.assertEquals(1, actualRequests.size()); ResumeJobRequest actualRequest = (ResumeJobRequest) actualRequests.get(0); Assert.assertEquals(name, JobName.parse(actualRequest.getName())); Assert.assertTrue( channelProvider.isHeaderSent( ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern())); }