One Time 您所在的位置:网站首页 schedulerx One Time

One Time

2024-05-23 06:34| 来源: 网络整理| 查看: 265

You can use one-time scheduling to trigger a job at a specified time. After SchedulerX completes the job, SchedulerX automatically deletes the job. This saves you the need to manually trigger and delete the job from the agent. One-time jobs are suitable for scenarios in which you want to disable notifications for unpaid orders or disable calendar notifications. This topic describes how to use the SchedulerX API to create a one-time job.

Benefits

Precise scheduling: Unlike periodic scheduling that has interval limits, one-time scheduling allows you to trigger a job at a point in time as needed.

Multiple job types: One-time scheduling based on SchedulerX supports all types of jobs, such as Java jobs, HTTP jobs, and Shell jobs. One-time scheduling is suitable for all distributed programming models, such as the standalone model, broadcast model, sharding model, and MapReduce model.

Visualized O&M: SchedulerX provides a visualized user interface where you can view and query one-time jobs in the same manner in which you manage other types of jobs. After you create a one-time job, you can modify the parameters of the job before the job is triggered. You can also configure SchedulerX to retry a one-time job that SchedulerX fails to trigger.

Use the SchedulerX API to create a one-time job

Add the SDK dependencies of the SchedulerX API to the pom.xml file of your application.

The following sample code shows how to use the SDK to call the SchedulerX API. Set the timeType parameter to 5 to enable one-time scheduling.

import com.aliyuncs.DefaultAcsClient; import com.aliyuncs.profile.DefaultProfile; import com.aliyuncs.schedulerx2.model.v20190430.CreateJobRequest; import com.aliyuncs.schedulerx2.model.v20190430.CreateJobResponse; public class CreateJavaJob { public static void main(String[] args) throws Exception { // The endpoint of the SchedulerX API. You can refer to the Endpoints topic or enter an endpoint based on the region in which you purchased the service. String regionId = "public"; /** * 1. The AccessKey pair of your Alibaba Cloud account has permissions on all API operations. We recommend that you use the AccessKey pair of a RAM user to access the SchedulerX API and perform routine O&M. * 2. To prevent leaks of the AccessKey secret and ensure the security of all resources in your Alibaba Cloud account, we recommend that you do not save the Access Key ID and AccessKey secret to your project code. * 3. In this example, identity verification is performed based on the AccessKey ID and AccessKey secret information that is read from environment variables. You must configure the following environment variables in advance: ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET. * You can use other encryption methods to ensure the security of your identity information based on your business requirements. */ String accessKeyId = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"); String accessKeySecret = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"); // The name of the service. String productName ="schedulerx2"; // Refer to the Endpoints topic and enter a domain. String domain ="schedulerx.aliyuncs.com"; // Create an API client. DefaultProfile.addEndpoint(regionId, productName, domain); DefaultProfile defaultProfile = DefaultProfile.getProfile(regionId, accessKeyId, accessKeySecret); DefaultAcsClient client = new DefaultAcsClient(defaultProfile); CreateJobRequest request = new CreateJobRequest(); request.setJobType("java"); request.setExecuteMode("standalone"); request.setDescription("test"); request.setName("One-time job test"); request.setClassName("com.alibaba.schedulerx.test.processor.HelloWorldJob3"); //timeType=5 specifies that the job is a one-time job. request.setTimeType(5); //yyyy-MM-dd HH:mm:ss request.setTimeExpression("2021-12-15 12:11:00"); request.setNamespace("433d8b23-06e9-408c-aaaa-90d4d1b9a4af"); request.setGroupId("xueren_sub"); // Alert settings request.setTimeoutEnable(true); request.setTimeoutKillEnable(true); request.setFailEnable(true); request.setTimeout(12300L); // Advanced settings. The automatic retry settings are configured. request.setMaxAttempt(3); request.setAttemptInterval(30); CreateJobResponse response = client.getAcsResponse(request); if (response.getSuccess()) { System.out.println("jobId=" + response.getData().getJobId()); } else { System.out.println(response.getMessage()); } } }

After you use the Scheduler X API to create a one-time job, log on to the SchedulerX console to check the job.

Log on to the SchedulerX console.

In the left-side navigation pane, click Applications.



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有