edit-icon download-icon

Use distributed job in test region

Last Updated: Jun 01, 2018

Create a distributed job

  1. Log on to the EDAS console and select Scheduler > Jobs in the left-side navigation pane.

  2. On the Jobs page, select a region and a job group.

    You can also select Scheduler > Job Groups and then click Create Group in the uppper-right corner to create a group.


    • If the job is for testing and must be linked through the development environment, select Test region.
    • If you select one of the other regions, the job can be connected only through the ECS instance in the selected region.
  3. Click Create Job at the upper-right corner of the page.

    Note: Before creating a job in a region, ensure that the selected region has at least one job group.

    In this example, a job that is triggered every 30 seconds and with the job processor implemention class com.schedulerx.test.ExecuteShellJobProcessor is created in the schedulerxTestGroup group in the Test region. For more information about the parameters, see Create a job.

Coding in the project

  1. Add the following dependency to the project file pom.xml.

    1. <dependencies>
    2. <dependency>
    3. <groupId>com.alibaba.edas</groupId>
    4. <artifactId>schedulerX-client</artifactId>
    5. <version>1.6.6</version>
    6. </dependency>
    7. </dependencies>
  2. Initialize SchedulerX-Client.

    • Option 1:

      1. public class SchedulerxTestMain {
      2. private static final Log logger = LogFactory.getLog(SchedulerxTestMain.class);
      3. public static void main(String[] args) {
      4. SchedulerXClient schedulerXClient = new SchedulerXClient();
      5. schedulerXClient.setGroupId("101-1-1-77");
      6. schedulerXClient.setRegionName("cn-test");
      7. try {
      8. schedulerXClient.init();
      9. } catch (Throwable e) {
      10. e.printStackTrace();
      11. }
      12. }
      13. }
    • Option 2 (using Spring):

      1. <?xml version="1.0" encoding="UTF-8"?>
      2. <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" "http://www.springframework.org/dtd/spring-beans-2.0.dtd">
      3. <beans>
      4. <bean id="schedulerXClient" class="com.alibaba.edas.schedulerX.SchedulerXClient" init-method="init">
      5. <property name="groupId">
      6. <value>101-1-1-77</value>
      7. </property>
      8. <property name="regionName">
      9. <value>cn-test</value>
      10. </property>
      11. </bean>
      12. </beans>

    You should replace the values of the two parameters (groupId and regionName)with those you actually used.

  3. Write the job processor interface.

    Note: The job processor must first implement the ScxSimpleJobProcessor interface and the processor name must match the job processor interface name specified upon Create Job.

    1. package com.schedulerx.test;
    2. import java.util.Date
    3. public class ExecuteShellJobProcessor implements ScxSimpleJobProcessor {
    4. public ProcessResult process(ScxSimpleJobContext context) {
    5. System.out.printIn("Hello World") +new Date());
    6. return new ProcessResult(true);//true 表示执行成功,false 表示失败
    7. }
    8. }

    Job Processor Interface

Run test

  1. Set the running parameters before running the test program.


    Set the file path and file name of SchedulerX (actually EDAS) Access Key ID and Access Key Secret as needed. Authentication is not performed in the development test region.

  2. Run the program after setting the parameters. A job trigger is received every five seconds to output the printed information in the processor logic.


Thank you! We've received your feedback.