dolphinscheduler icon indicating copy to clipboard operation
dolphinscheduler copied to clipboard

Looking at the current source code and features, there is no need for priority between workflows(看了目前的源码和功能,没有工作流程之间的优先级的需求)

Open itheima-cby opened this issue 7 years ago • 4 comments

At present, the function only has priority at the task level. May I ask the author, is there a priority between workflows? Don't know if the author is convenient to add such a priority control to an existing project? Thank you


目前功能仅有任务级别的优先级,请问一下作者,有工作流程之间的优先级吗?不知道作者是否方便在现有项目中添加一个这样子的优先级控制?谢谢

itheima-cby avatar Apr 30 '19 10:04 itheima-cby

we already have implemented this,please view the class of TaskQueueZkImpl.java, relevent code

 /**
     * An element pops out of the queue <p>
     * note:
     *   ${processInstancePriority}_${processInstanceId}_${taskInstancePriority}_${taskId}
     *   The tasks with the highest priority are selected by comparing the priorities of the above four levels from high to low.
     *
     *   流程实例优先级_流程实例id_任务优先级_任务id       high <- low
     * @param  key  task queue name
     * @param  remove  whether remove the element
     * @return the task id  to be executed
     */
    @Override
    public String poll(String key, boolean remove) {
        try{
            CuratorFramework zk = getZkClient();
            String tasksQueuePath = getTasksPath(key) + Constants.SINGLE_SLASH;
            List<String> list = zk.getChildren().forPath(getTasksPath(key));

            if(list != null && list.size() > 0){

                int size = list.size();

                String formatTargetTask = null;
                String targetTaskKey = null;
                for (int i = 0; i < size; i++) {
                    String taskDetail = list.get(i);
                    String[] taskDetailArrs = taskDetail.split(Constants.UNDERLINE);

                    if(taskDetailArrs.length == 4){
                        //format ${processInstancePriority}_${processInstanceId}_${taskInstancePriority}_${taskId}
                        String formatTask = String.format("%s_%010d_%s_%010d", taskDetailArrs[0], Long.parseLong(taskDetailArrs[1]), taskDetailArrs[2], Long.parseLong(taskDetailArrs[3]));
                        if(i > 0){
                            int result = formatTask.compareTo(formatTargetTask);
                            if(result < 0){
                                formatTargetTask = formatTask;
                                targetTaskKey = taskDetail;
                            }
                        }else{
                            formatTargetTask = formatTask;
                            targetTaskKey = taskDetail;
                        }
                    }else{
                        logger.error("task queue poll error, task detail :{} , please check!", taskDetail);
                    }
                }

                if(formatTargetTask != null){
                    String taskIdPath = tasksQueuePath + targetTaskKey;

                    logger.info("consume task {}", taskIdPath);

                    String[] vals = targetTaskKey.split(Constants.UNDERLINE);

                    if(remove){
                        removeNode(key, targetTaskKey);
                    }
                    logger.info("consume task: {},there still have {} tasks need to be executed", vals[vals.length - 1], size - 1);
                    return targetTaskKey;
                }else{
                    logger.error("should not go here, task queue poll error, please check!");
                }
            }

        } catch (Exception e) {
            logger.error("add task to tasks queue exception",e);
        }
        return null;
    }

davidzollo avatar Apr 30 '19 14:04 davidzollo

Thank you very much, I will read the source code carefully.


非常感谢,我会仔细阅读源码的

---原始邮件--- 发件人: "escheduler"[email protected] 发送时间: 2019年4月30日(星期二) 晚上10:44 收件人: "analysys/EasyScheduler"[email protected]; 抄送: "Author"[email protected];"itheima-cby"[email protected]; 主题: Re: [analysys/EasyScheduler] 看了目前的源码和功能,没有工作流程之间的优先级的需求 (#244)

we already have implemented this,please view the class of TaskQueueZkImpl.java, relevent code /** * An element pops out of the queue

* note: * ${processInstancePriority}${processInstanceId}${taskInstancePriority}${taskId} * The tasks with the highest priority are selected by comparing the priorities of the above four levels from high to low. * * 流程实例优先级_流程实例id_任务优先级_任务id high <- low * @param key task queue name * @param remove whether remove the element * @return the task id to be executed */ @Override public String poll(String key, boolean remove) { try{ CuratorFramework zk = getZkClient(); String tasksQueuePath = getTasksPath(key) + Constants.SINGLE_SLASH; List list = zk.getChildren().forPath(getTasksPath(key)); if(list != null && list.size() > 0){ int size = list.size(); String formatTargetTask = null; String targetTaskKey = null; for (int i = 0; i < size; i++) { String taskDetail = list.get(i); String[] taskDetailArrs = taskDetail.split(Constants.UNDERLINE); if(taskDetailArrs.length == 4){ //format ${processInstancePriority}${processInstanceId}${taskInstancePriority}${taskId} String formatTask = String.format("%s_%010d_%s_%010d", taskDetailArrs[0], Long.parseLong(taskDetailArrs[1]), taskDetailArrs[2], Long.parseLong(taskDetailArrs[3])); if(i > 0){ int result = formatTask.compareTo(formatTargetTask); if(result < 0){ formatTargetTask = formatTask; targetTaskKey = taskDetail; } }else{ formatTargetTask = formatTask; targetTaskKey = taskDetail; } }else{ logger.error("task queue poll error, task detail :{} , please check!", taskDetail); } } if(formatTargetTask != null){ String taskIdPath = tasksQueuePath + targetTaskKey; logger.info("consume task {}", taskIdPath); String[] vals = targetTaskKey.split(Constants.UNDERLINE); if(remove){ removeNode(key, targetTaskKey); } logger.info("consume task: {},there still have {} tasks need to be executed", vals[vals.length - 1], size - 1); return targetTaskKey; }else{ logger.error("should not go here, task queue poll error, please check!"); } } } catch (Exception e) { logger.error("add task to tasks queue exception",e); } return null; }

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.

itheima-cby avatar Apr 30 '19 14:04 itheima-cby

image

davidzollo avatar Apr 30 '19 14:04 davidzollo

we close this issue for now, if have more questions, please reopen it again!

davidzollo avatar Apr 30 '19 14:04 davidzollo