/** * Forces a job to run now. * * <p>When this method is called, Cloud Scheduler will dispatch the job, even if the job is * already running. * * <p>Sample code: * * <pre><code> * try (CloudSchedulerClient cloudSchedulerClient = CloudSchedulerClient.create()) { * JobName name = JobName.of("[PROJECT]", "[LOCATION]", "[JOB]"); * Job response = cloudSchedulerClient.runJob(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 runJob(String name) { RunJobRequest request = RunJobRequest.newBuilder().setName(name).build(); return runJob(request); }
/** * Forces a job to run now. * * <p>When this method is called, Cloud Scheduler will dispatch the job, even if the job is * already running. * * <p>Sample code: * * <pre><code> * try (CloudSchedulerClient cloudSchedulerClient = CloudSchedulerClient.create()) { * JobName name = JobName.of("[PROJECT]", "[LOCATION]", "[JOB]"); * Job response = cloudSchedulerClient.runJob(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 runJob(JobName name) { RunJobRequest request = RunJobRequest.newBuilder().setName(name == null ? null : name.toString()).build(); return runJob(request); }
@Test @SuppressWarnings("all") public void runJobExceptionTest() throws Exception { StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT); mockCloudScheduler.addException(exception); try { JobName name = JobName.of("[PROJECT]", "[LOCATION]", "[JOB]"); client.runJob(name); Assert.fail("No exception raised"); } catch (InvalidArgumentException e) { // Expected exception } } }
@Test @SuppressWarnings("all") public void runJobTest() { 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.runJob(name); Assert.assertEquals(expectedResponse, actualResponse); List<GeneratedMessageV3> actualRequests = mockCloudScheduler.getRequests(); Assert.assertEquals(1, actualRequests.size()); RunJobRequest actualRequest = (RunJobRequest) actualRequests.get(0); Assert.assertEquals(name, JobName.parse(actualRequest.getName())); Assert.assertTrue( channelProvider.isHeaderSent( ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern())); }