One-time jobs
A one-time job in SchedulerX runs once at a specified point in time and is automatically cleaned up after execution. Typical use cases include order timeout handling and scheduled calendar reminders. Create a one-time job by calling the SchedulerX OpenAPI.
Prerequisites
A RAM user is created and the
ALIBABA_CLOUD_ACCESS_KEY_IDandALIBABA_CLOUD_ACCESS_KEY_SECRETenvironment variables are configured. For more information, see Configure credentials.A SchedulerX namespace and an application group are created.
The SchedulerX OpenAPI SDK is added to your project.
Create a one-time job
Add the OpenAPI SDK dependency to the
pom.xmlfile of your application.Use the SDK to call the CreateJob API operation. Set the
timeTypeparameter to5to enable one-time job 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 region ID. Specify the value based on the region where you purchased the SchedulerX instance. String regionId = "public"; /** * 1. The AccessKey pair of an Alibaba Cloud account has access permissions on all API operations. We recommend that you use a Resource Access Management (RAM) user for API access or daily O&M. * 2. We recommend that you do not save your AccessKey ID and AccessKey secret in the project code. Otherwise, your AccessKey pair may be leaked and the security of all resources in your account may be compromised. * 3. This example loads the AccessKey pair from environment variables for identity verification. You must configure the ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variables in advance. * You can also use other secure and encrypted methods to store your credentials. */ String accessKeyId = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"); String accessKeySecret = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"); // The product name. String productName = "schedulerx2"; // The domain name of the SchedulerX API. Specify the value based on the region where you purchased the instance. String domain = "schedulerx.aliyuncs.com"; // Create the OpenAPI client. DefaultProfile.addEndpoint(regionId, productName, domain); DefaultProfile defaultProfile = DefaultProfile.getProfile(regionId, accessKeyId, accessKeySecret); DefaultAcsClient client = new DefaultAcsClient(defaultProfile); CreateJobRequest request = new CreateJobRequest(); // The job type. Valid values: java, http, shell. request.setJobType("java"); // The distributed model. Valid values: standalone, broadcast, sharding, MapReduce. request.setExecuteMode("standalone"); // The job description. request.setDescription("test"); // The job name. request.setName("One-time job test"); // The full class name of the job processor. Required for Java jobs. request.setClassName("com.alibaba.schedulerx.test.processor.HelloWorldJob3"); // Set timeType to 5 for one-time job scheduling. request.setTimeType(5); // The scheduled execution time in yyyy-MM-dd HH:mm:ss format. Replace this value with your target time. request.setTimeExpression("2025-06-01 10:00:00"); // The namespace ID. Replace this value with your namespace ID. request.setNamespace("your-namespace-id"); // The application group ID. Replace this value with your group ID. request.setGroupId("your-group-id"); // Monitoring and alerting settings. request.setTimeoutEnable(true); // Enable timeout monitoring. request.setTimeoutKillEnable(true); // Terminate the job on timeout. request.setFailEnable(true); // Enable failure alerting. request.setTimeout(12300L); // The timeout period in milliseconds. // Automatic retry settings. request.setMaxAttempt(3); // The maximum number of retry attempts upon failure. request.setAttemptInterval(30); // The retry interval in seconds. CreateJobResponse response = client.getAcsResponse(request); if (response.getSuccess()) { System.out.println("jobId=" + response.getData().getJobId()); } else { System.out.println(response.getMessage()); } } }The following table describes the key parameters in the code example:
Parameter Description jobTypeThe job type. Valid values: java,http,shell.executeModeThe distributed model. Valid values: standalone,broadcast,sharding,MapReduce.nameThe job name. descriptionThe job description. classNameThe full class name of the job processor. Required for Java jobs. timeTypeThe scheduling type. Set to 5for one-time jobs.timeExpressionThe scheduled execution time. Format: yyyy-MM-dd HH:mm:ss. Replace the value with your target execution time.namespaceThe namespace ID of the SchedulerX instance. groupIdThe ID of the application group. timeoutEnableSpecifies whether to enable timeout monitoring. timeoutKillEnableSpecifies whether to terminate the job when it times out. failEnableSpecifies whether to enable failure alerting. timeoutThe timeout period in milliseconds. maxAttemptThe maximum number of retry attempts upon failure. attemptIntervalThe retry interval in seconds. After you create the job, verify it in the console.
a. Log on to the Distributed Task Scheduling Platform.
b. In the left-side navigation pane, click Application Management.
Verify that the job appears in the Task Management list with the following properties:
Status: Enabled
Job name: One-time job test
Job type: Java Standalone
Time type: one_time
Time expression:
The Actions column provides entries such as Preview, Edit, and Run Once. You can modify job parameters before the scheduled time arrives.2025-06-01 10:00:00
Features
One-time jobs in SchedulerX provide the following capabilities:
Flexible scheduling — Unlike delayed messages, one-time jobs support any future timestamp. They are not limited by a fixed delay or a maximum number of days.
Multiple job types — One-time jobs support all job types, including Java, HTTP, and Shell. They also support all distributed models, including standalone, broadcast, sharding, and MapReduce.
Console-based management — You can view, query, and modify one-time jobs in the SchedulerX console. Features such as automatic retry upon failure are supported.