All Products
Search
Document Center

SchedulerX:Use workflows to orchestrate jobs

Last Updated:Jan 23, 2024

This topic describes how to orchestrate jobs by using visualized workflows in the SchedulerX console. Cron expressions and API operations are supported.

Usage notes

  • You cannot separately schedule jobs in a workflow. The jobs are scheduled together with the workflow and based on the scheduling cycle of the workflow.

  • A workflow that is used to schedule jobs must contain at least two jobs and have job dependencies. If you have only one job, you can schedule the job on the Task Management page.

  • Workflows support cross-application orchestration. You can orchestrate jobs of different applications by using a single workflow.

Limits

Only Java jobs support data transfer. If you use distributed Java jobs, you must use MapReduce models to transfer data.

Usage guide

For detailed information, see Manage workflows.

Data transfer between upstream and downstream nodes

SchedulerX provides workflow-based job orchestration capabilities and supports data transfer between upstream and downstream nodes of workflows.

Return execution results

/**
 *
 * @param status
 * @param result, the size should less than 1000 bytes
 * @throws Exception
 */
public ProcessResult(boolean status, String result) throws Exception;

You can add this method to the end of the Processor interface to obtain the execution result.

Note

The length of the result is not the length of String and cannot exceed 1,000 bytes. If the result contains Chinese characters, the length may exceed 1,000 bytes. In this case, the job may fail.

Obtain upstream data

List<JobInstanceData> upstreamDatas = JobContext.getUpstreamData();

In Processor, you can call this operation to obtain upstream data from JobContext. The upstream data is a list that may have multiple parent nodes. The JobInstanceData field contains the JobName and Data (String type) properties.

Demo

  1. Compile three job processors.

    public class TestSimpleJobA extends JavaProcessor {
        @Override
        public ProcessResult process(JobContext context) throws Exception {
            System.out.println("TestSimpleJobA " + DateTime.now().toString("yyyy-MM-dd HH:mm:ss"));
            return new ProcessResult(true, String.valueOf(1));
        }
    }
    public class TestSimpleJobB extends JavaProcessor {
        @Override
        public ProcessResult process(JobContext context) throws Exception {
            System.out.println("TestSimpleJobB " + DateTime.now().toString("yyyy-MM-dd HH:mm:ss"));
            return new ProcessResult(true, String.valueOf(2));
        }
    }
    public class TestSimpleJobC extends JavaProcessor {
        @Override
        public ProcessResult process(JobContext context) throws Exception {
            List<JobInstanceData> upstreamDatas = context.getUpstreamData();
            int sum = 0;
            for (JobInstanceData jobInstanceData : upstreamDatas) {
                System.out.println("jobName=" + jobInstanceData.getJobName() 
                		+ ", data=" + jobInstanceData.getData());
                sum += Integer.valueOf(jobInstanceData.getData());
            }
            System.out.println("TestSimpleJobC sum=" + sum);
            return new ProcessResult(true, String.valueOf(sum));
        }
    }
  2. Configure a workflow in the SchedulerX console. The following figure shows an example.

    image.png

  3. After you trigger the workflow once, click Execution List in the left-side navigation pane, click Process instance list, and then find the created workflow on the page. Then, click Instance ID/Process instance diagram to go to the Workflow instance details page. Right-click instance JobA and click Details to go to the Task instance details panel. On the Basic Information tab of the panel, view the value of the Results or error messages parameter. The following figure shows that the value of the Results or error messages parameter of instance JobA is 1.

    image.png Repeat the preceding step to query the values of the Results or error messages parameter of instance JobB and instance JobC. In this example, the Results or error messages values of the two instances are 2 and 3 respectively.

  4. View the print information of instance JobC in the SchedulerX console.

    jobName=jobB, data=2
    jobName=jobA, data=1
    TestSimpleJobC sum=3