edit-icon download-icon

Example of script jobs

Last Updated: Mar 15, 2018

This section uses an example to describe how to execute SchedulerX script jobs.

Note: To execute the script jobs, you must use SchedulerX-Client 2.1.3 or a later version.

Create a script job

1. Create a Shell script job

  1. In the EDAS console, choose Scheduler > Jobs from the left-side navigation pane.

  2. On the Jobs page, click Create Job in the upper right corner.

  3. Select Script Job from Job Type and enter the Shell script in the Job Script field.

  1. echo "Hello,"
  2. echo "EDAS"

After the job is executed, the message “Hello, EDAS” is displayed in the execution log.

2. Create a Shell job with parameters

  1. Compile a Shell script and save it as /Users/xxx/shellJobTest/hello.sh.

    1. echo $1
    2. echo $2
  2. Compile a Shell job and input the Shell script in in the Job Script field.

    1. /Users/xxx/shellJobTest/hello.sh Hello,EDAS

    After the job is executed, the message “Hello, EDAS” is displayed in the execution log.

3. Create a Python script job

  1. Compile a Python script and save it as /Users/xxx/shellJobTest/hello.py.

    1. print('Hello edas, python!')
    2. val1 = 1
    3. val2 = 0
    4. val3 = val1/val2
    5. print('val3 is ' + val3)
  2. Compile a Shell job and input the Shell script in the Job Script field.

    1. phthon /Users/xxx/shellJobTest/hello.py

    Note: In step 1, we entered an incorrect logic for illustration purpose. If val3 equals 1/0, an exception is generated and recorded in the exception log.

4. View job execution result

On the Jobs page, choose More > Trigger Record for the corresponding job to view job execution details, execution logs, and execution result.

Run a script job

You can run a script job using either of the Client dependency method or Agent method.

Client dependency method

  1. Add SchedulerX-Client dependency to the application project.

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

    You can initialize SchedulerX-Client using either of the Independent Java application or Spring application.

    • Independent Java application

      1. package com.schedulerx.test;
      2. import com.alibaba.edas.schedulerX.SchedulerXClient;
      3. public class schedulerxTestMain {
      4. public static void main(String[] args) {
      5. SchedulerXClient schedulerXClient = new SchedulerXClient();
      6. schedulerXClient.setGroupId("101-1-1-52");
      7. schedulerXClient.setRegionName("cn-hangzhou");
      8. schedulerXClient.setNewVersion(true);
      9. /*
      10. //If a cluster in Shanghai region is used, you must set the domainName attribute and set RegionName to cn-shanghai.
      11. schedulerXClient.setRegionName("cn-shanghai");
      12. schedulerXClient.setDomainName("schedulerx-shanghai.console.aliyun.com");
      13. */
      14. try {
      15. schedulerXClient.init();
      16. } catch (Throwable e) {
      17. e.printStackTrace();
      18. }
      19. }
      20. }
    • Spring application

      1. <bean id="schedulerXClient" class="com.alibaba.edas.schedulerX.SchedulerXClient" init-method="init">
      2. <property name="groupId">
      3. <value>101-1-1-77</value>
      4. </property>
      5. <property name="regionName">
      6. <value>cn-hangzhou</value>
      7. </property>
      8. <!--If a cluster in Shanghai region is used, you must set the domainName attribute and set RegionName to cn-shanghai.
      9. <property name="regionName">
      10. <value>cn-shanghai</value>
      11. </property>
      12. <property name="domainName">
      13. <value>schedulerx-shanghai.console.aliyun.com</value>
      14. </property>-->
      15. <property name="newVersion">
      16. <value>true</value>
      17. </property>
      18. </bean>

Agent method

  1. Download SchedulerX-Agent.

    You can download SchedulerX-Agent by running the wget command on the application machine.

    URL for downloading SchedulerX-Agent: http://edas.oss-cn-hangzhou.aliyuncs.com/SchedulerX/schedulerx-client-2.1.3-SNAPSHOT.tar.gz

  2. Run SchedulerX-Agent.

    1. Decompress the downloaded compressed package, go to the SchedulerX-Agent/conf directory, and edit the agent.ini file.

      1. [baseSection]
      2. groupId=111-1-1-0001 //Job group ID
      3. domainName=schedulerx.console.aliyun.com //Domain name. Set the name to schedulerx-shanghai.console.aliyun.com if a cluster in Shanghai region is used.
      4. regionName=cn-test //Enter the corresponding regionName.
      5. newVersion=true //Default parameter value, which does not need to be modified
    2. Go to the SchedulerX-Agent/bin directory and run start-1g.sh.

      You can run start-2g.sh, start-4g.sh, or start-8g.sh based on the job load and machine configurations.

    If a message indicating that the startup succeeds is displayed on SchedulerX-Agent, you can receive the scheduled jobs.

Thank you! We've received your feedback.