Conditions in Task Schedule

  • Last update:November 10, 2020
  • I. Overview

    1) The scheduled task condition judgment refers to performing a check action before executing the scheduled tasks, and stop or defer the execution when the check fails. If Task Restart is checked in Scheduling Cycle, condition judgment action will be carried out again after an interval of time.

    2) There are 3 options in Conditions, namely, Always Execute, Formula Judgment and Custom Class Judgment.

    3) Always Execute means to run tasks without condition judgment process. Formula Judgment and Custom Class Judgment are described in detail below.

    You will learn
    • Formula Judgment

      • Set a Scheduling Cycle

      • View Results

    • Custom Class Judgement - Without Parameters

      • Build a Custom Class

      • Set a Scheduling Cycle

      • View Results

    • Custom Class Judgment - With Parameters

      • Build a Custom Class

      • Set a Scheduling Cycle

      • View Results

    • Important Note

    II. Formula Judgment

    Formula Judgment is used to check formula contents before executing the scheduled tasks. Tasks will be executed if the formula returns "true", and stopped or deferred when returns "false".

    Deferred execution means to run tasks again and re-check conditions after an interval of time with Task Restart checked in Scheduling Cycle. By analogy, the task is not executed if it restarts and fails the check for a given number of times; once all conditions are met, the scheduled task is executed.


    1. Set a Scheduling Cycle

    Take GettingStartedEN.cpt for example. Please refer to Task Schedule Setting Steps for more information on how to set up tasks.

    Click Next and go to Scheduling Cycle.

    • Select Formula Judgment for Conditions.

    • Enter D5>20000 in the formula input box as the execution condition.

    • Check If the task is interrupted, restart at the following frequency and set the "Interval between two restarts" to 1 minute and "Maximum number of attempts to restart" to 2 times.

    1.png

    The meaning of formulas and configuration items for Task Restart are as follows:

    Configuration Items
    Remarks

    Formula D5>20000

    For a template selected in Dispatcher Object, the task is only executed when the cell value of D5 is greater than 20000; otherwise, deferred or stopped.

    Interval between two restarts

    The task is restarted if the cell value of D5 is less than 20000, and the interval between restarts is 1 minute. Formula judgment will be conducted again after restarting.

    Maximum number of attempts to restart

    Task will be restarted 2 times as configured before it is stopped.


    2. View Results

    After running the task, the Formula Judgment in Task Management has been done as shown below:

    2.png

    Click on Run Monitoring to check on details of task runs:

    3.png

    Task1 has been restarted twice for the template failing to meet the conditions to execute tasks, so it was skipped and exceeded the maximum attempts before the very end. The task is not listed in Task in Progress right now.

    III. Custom Class Judgement - Without Parameters

    The Custom Class Judgement is to do checks with a custom class, and run tasks when it returns "true".

    Interface com.fr.schedule.base.provider.ExecuteCondition needs to be implemented to run custom classes for tasks, and there is a public boolean execute() method which can be called to check the conditions and return results.


    1. Build a Custom Class

    For example, check if it's Friday when running a scheduled task, and to run it on Friday only. The code is as follows:

    package com.fr.schedule;
    import java.util.Calendar;
    import com.fr.schedule.base.provider.ExecuteCondition;
    public class ExecuteClass implements ExecuteCondition {
    public boolean execute() {
    Calendar cal = Calendar.getInstance();
    int dow = cal.get(Calendar.DAY_OF_WEEK);//The dow of Friday is 6
    return (dow) == 6;
    }
    }

    Save the compiled class file to %FR_HOME%\webapps\webroot\WEB-INF\classes\com\fr\schedule.


    2. Set a Scheduling Cycle

    First, choose Custom Class Judgment in Scheduling Cycle, and select in the drop-down field the above-saved class file, as shown below:

    4.png

    Click Save once all the configurations are completed.


    3. View Results

    Go to Run Monitoring and see a "Successful" status if it's Friday:

    5.png

    If it's not Friday, "Snapshot Generated, Skip" is shown as below:

    6.png


    IV. Custom Class Judgment - With Parameters

    Jar versions released on and after 8th Jun, 2020 support adding parameters and assigning values in Conditions.


    1. Build a Custom Class

    For example, set a task to run when [Param1 < 5] and [Param2 contains "ABC"]:

    Param name allows a combination of letters, numbers and Chinese characters, but the first char of the name mustn't be a number.

    package com.fr.schedule;
    import com.fr.general.GeneralUtils;
    import com.fr.log.FineLoggerFactory;
    import com.fr.schedule.base.provider.impl.AbstractParameterExecuteCondition;
    import com.fr.stable.StringUtils;
    import java.util.List;
    import java.util.Map;
    public class NewCondition extends AbstractParameterExecuteCondition {
        @Override
        public boolean execute(List<Map<String, Object>> paramList) {
            FineLoggerFactory.getLogger().error("New condition, skip");
            if (paramList.size() < 1) {
                return true;
            }
            int param1 = 0;
            String param2 = StringUtils.EMPTY;
            for (Map<String, Object> map : paramList) {
                if (StringUtils.equals(GeneralUtils.objectToString(map.get("name")), "Param 1")) {
                    param1 = Integer.parseInt(GeneralUtils.objectToString(map.get("value")));
                } else if (StringUtils.equals(GeneralUtils.objectToString(map.get("name")), "Param 2")) {
                    param2 = GeneralUtils.objectToString(map.get("value"));
                }
            }
            if (param1 > 5 && param2.contains("ABC")) {
                return true;
            } else {
                return false;
            }
        }
    }

    Save the compiled class file to %FR_HOME%\webapps\webroot\WEB-INF\classes\com\fr\schedule.


    2. Set a Scheduling Cycle

    Choose Custom Class Judgment in Scheduling Cycle and select in the drop-down field the above-saved class file. Add Param1 and Param2 as parameters with values set to "6" and "ABC":

    7.png



    3. View Results

    Go to Run Monitoring and see a "Successful" status:

    8.png

    If the value of Param1 and Param2 does not meet the conditions (for example, change the value of Param1 to "4"), "Snapshot Generation, Skip" will be shown in the table as below:

    9.png

    V. Important Note

    Problem:

    When Cell A1 of a template contains the formula $fine_username, it won't work to use "LEN" on cell A1 as the Formula Judgment in Scheduling Cycle. For example, take LEN(report0~A1) for .frm template and LEN(A1) for .cpt template.

    Cause:

    The LEN formula uses the values from A1, but it gets an array of values when A1 is an extended cell.

    Solution:

    Modify the formula to LEN(INDEXOFARRAY(report0~A1,1)) for .frm template and LEN(INDEXOFARRAY(A1,1)) for .cpt template.

     

    Attachment List


    Theme: Decision-making Platform
    • Helpful
    • Not helpful
    • Only read

    滑鼠選中內容,快速回饋問題

    滑鼠選中存在疑惑的內容,即可快速回饋問題,我們將會跟進處理。

    不再提示

    10s後關閉

    Get
    Help
    Online Support
    Professional technical support is provided to quickly help you solve problems.
    Online support is available from 9:00-12:00 and 13:30-17:30 on weekdays.
    Page Feedback
    You can provide suggestions and feedback for the current web page.
    Pre-Sales Consultation
    Business Consultation
    Business: international@fanruan.com
    Support: support@fanruan.com
    Page Feedback
    *Problem Type
    Cannot be empty
    Problem Description
    0/1000
    Cannot be empty

    Submitted successfully

    Network busy