Task scheduling adaptive execution framework system
By introducing the state machine model and Quartz scheduling algorithm into the task scheduling framework, priority is given to processing faulty task flow queues, which solves the problem that the traditional framework cannot flexibly adapt to task changes and manage faulty tasks, and realizes adaptive management of task flows and faulty tasks. Priority scheduling improves the flexibility and scalability of the system.
Patent Information
- Application Number
- CN202410860837.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-28
- Publication Date
- 2024-09-17
AI Technical Summary
The traditional task scheduling framework cannot flexibly adapt to the dynamic changes of tasks, and has limitations in the management of faulty tasks and dynamic task flows, especially the insufficient support for task execution order and dependencies.
A task scheduling adaptive execution framework system is designed, which uses a state machine model, task step definition module, task process definition module, task queue management module and Quartz scheduling algorithm. The task process is modeled through the state machine and prioritized using the Quartz scheduling algorithm. Faulty task flow queue implements adaptive management of task flows and priority scheduling of faulty tasks.
It enhances the flexibility and anti-interference ability of the system, supports dynamic task flow management, ensures timely processing and repair of faulty tasks, and improves the adaptability and scalability of task scheduling. Users can define tasks through simple interfaces and configuration items. Steps and processes.
Smart Images

Figure CN118656192A
Abstract
Description
Technical Field
[0001] The present invention relates to the field of task scheduling processing and execution in IT and software development, and in particular to a task scheduling adaptive execution framework system. Background Art
[0002] In modern computing systems, task scheduling is an important function. The task scheduling framework can automatically schedule and execute tasks according to the composition of the task flow and the predetermined plan or trigger conditions. However, there are some problems with the traditional task scheduling framework, such as the inability to flexibly adapt to the dynamic changes of tasks, and the incomplete support for the execution order and dependency of tasks.
[0003] The state machine design pattern can effectively manage and execute the state and process of tasks, and Quartz is a commonly used open source task scheduling framework with flexibility and scalability. However, the traditional Quartz framework has some limitations in the priority scheduling of faulty tasks and the management of dynamic task flows in the task scheduling process.
[0004] The present invention proposes a task scheduling adaptive execution framework system. Summary of the invention
[0005] In view of the above shortcomings of the prior art, the purpose of the invention is to provide a task scheduling and execution framework system based on a state machine and Quartz, which can efficiently manage and execute task scheduling, realize priority scheduling of faulty tasks and flexible management of dynamic task flows. The framework is convenient and lightweight, flexible to expand, efficient and pluggable, and is suitable for a variety of task scheduling and execution scenarios.
[0006] A first aspect of the present invention provides a task scheduling adaptive execution framework system, comprising:
[0007] State machine model module: used to model the task scheduling and processing execution process as a state machine, where each state represents a different execution stage of the task, and the transition between states represents the execution process and dependency of the task;
[0008] Task step definition module: define different steps of a task by using step;
[0009] Task process definition module: defines the task process by using flow, that is, the execution order and dependencies of task steps;
[0010] Task queue management module: saves two types of task flows by using normal task flow queue and fault task flow queue;
[0011] Quartz scheduling algorithm module: uses Quartz's scheduling algorithm to periodically query the existence of tasks in the two queues and give priority to reading the faulty task flow queue;
[0012] Task flow execution management module: used to manage task flow queues.
[0013] Furthermore, when the state machine module is started, it will read the persistent task flow related data in the database and merge it into the cache queue. When creating or executing a task flow, it will also synchronously process the task flow context information in the database and the cache queue.
[0014] Furthermore, each task flow is composed of multiple task steps, the execution of each task step is idempotent and stateless, and the context information corresponding to the task flow and its specific task step context information are persisted in the database and mapped and associated with the task flow ID and the task step ID.
[0015] Furthermore, subtasks are cascaded in the task steps, and the same steps in multiple task flows share a common interface code and are executed multiple times, and the encapsulation of specific task steps is completed through the context information in each associated database.
[0016] Furthermore, the steps in the task step definition module include the triggering conditions, execution time, and execution code of the task.
[0017] Furthermore, the common task flow queue in the task queue management module is used to store tasks with normal processes, and the fault task flow queue is used to store tasks with faults.
[0018] Furthermore, in the Quartz scheduling algorithm module, if the faulty task flow queue is not empty, the head task flow is taken out to trigger the execution of the task flow function code; if the faulty task flow queue is empty, the head element information of the ordinary task flow queue is read to trigger the execution of the ordinary task flow function code; if both queues are empty, the current scheduling is skipped and waits for the next scheduling.
[0019] Furthermore, if the task step fails to execute, the task flow status will be updated and the failure information will be marked. At the same time, by configuring Quartz's task flow inspection and scheduling strategy, you can adaptively retry scenarios such as timeouts and failures during the task flow execution process.
[0020] Furthermore, after the current step of the task flow in the task flow management module is executed, it will be detected whether the currently executed task step is the last step; if so, the execution of the current task flow is terminated and it is removed from the queue.
[0021] Furthermore, in the task flow management module, if it is not the last step, the sequence number of the current execution step of the task is increased by 1, and the task flow is put into the head of the corresponding queue again, so that it is scheduled into the execution model again to realize the continued execution of the task.
[0022] The beneficial effects of the present invention are as follows:
[0023] First of all, enhanced security and anti-interference capabilities:
[0024] 1. Adaptive management of task flows: The framework supports flexible management of dynamic task flows. It can dynamically modify task processes and steps based on task execution status and custom state transition rules, and has adaptability to task scheduling.
[0025] 2. Flexible and scalable: Through the design pattern of the state machine, the task flow execution steps are loosely coupled and granular, and the process is clear and controllable. With the flexibility of Quartz, the framework as a whole can flexibly manage and execute task scheduling and adapt to the complex dependencies of tasks.
[0026] 3. Priority scheduling of faulty tasks: By giving priority to reading the faulty task flow queue, the framework can give priority to scheduling faulty tasks to ensure that faulty tasks are processed and repaired in a timely manner.
[0027] 4. Easy to integrate and use: Users only need to introduce jar package dependencies and implement the interfaces or configuration items provided by the framework to define task steps, agree on task flow composition and execution order, conversion rules between different task states, and adaptive processing measures. BRIEF DESCRIPTION OF THE DRAWINGS
[0028] The accompanying drawings are only used to illustrate specific embodiments and are not considered to limit the present invention. In the entire drawings, the same reference symbols represent the same components. Obviously, the drawings described below are only some embodiments recorded in the embodiments of the present invention. For those of ordinary skill in the art, other drawings can also be obtained based on these drawings.
[0029] Figure 1 A construction execution model of a task flow and task steps of a task scheduling adaptive execution framework according to an embodiment of the present invention;
[0030] Figure 2 A state flow diagram of task step scheduling execution of a task scheduling adaptive execution framework according to an embodiment of the present invention;
[0031] Figure 3 A state flow diagram of task flow scheduling execution of a task scheduling adaptive execution framework according to an embodiment of the present invention;
[0032] Figure 4The present invention provides a task flow queue and Quartz scheduling process flow chart of a task scheduling adaptive execution framework according to an embodiment of the present invention. DETAILED DESCRIPTION
[0033] In order to enable those skilled in the art to better understand the technical solutions in the embodiments of the present invention, the technical solutions of the present invention will be clearly and completely described below in conjunction with the accompanying drawings. Obviously, the described embodiments are part of the embodiments of the present invention, rather than all of the embodiments. It should be understood that these descriptions are only exemplary and are not intended to limit the scope of the present invention. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in the field without making creative work should fall within the scope of protection of the present invention.
[0034] Furthermore, in the following description, descriptions of well-known structures and technologies are omitted to avoid unnecessarily obscuring the concepts disclosed in the present invention.
[0035] In the description of the present invention, it should be noted that, unless otherwise clearly specified and limited, the orientation or position relationship indicated by the terms "center", "upper", "lower", "left", "right", "vertical", "horizontal", "inside", "outside", etc. is based on the orientation or position relationship shown in the drawings, which is only for the convenience of describing the present invention and simplifying the description, and does not indicate or imply that the device or element referred to must have a specific orientation, be constructed and operated in a specific orientation, and therefore cannot be understood as a limitation of the present invention. In addition, the terms "first", "second", and "third" are only used for descriptive purposes and cannot be understood as indicating or implying relative importance. The terms "installed", "connected", and "connected" should be understood in a broad sense, for example, it can be a fixed connection, a detachable connection, or an integral connection; it can be a mechanical connection or an electrical connection; it can be a direct connection, or it can be indirectly connected through an intermediate medium, or it can be a connection between the two elements. For those of ordinary skill in the art, the specific meanings of the above terms in the present invention can be understood according to specific circumstances.
[0036] Exemplary embodiments will be described in detail herein, examples of which are shown in the accompanying drawings. When the following description refers to the drawings, unless otherwise indicated, the same numbers in different drawings represent the same or similar elements. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with the present invention. Instead, they are merely examples of methods and systems consistent with some aspects of the present invention as detailed in the appended claims.
[0037] The present invention proposes a task scheduling adaptive execution framework, which provides base class services for task scheduling strategies, task steps, task flows and their step composition and execution order, and has the most basic task execution and adaptive scheduling functions for common tasks and faulty tasks through encapsulation and abstraction. In actual service applications, users can expand and define their own common or faulty task step step classes, the step composition and execution order of task flow flow classes, and the various state transfer state classes of task flows and single task steps, and manually or regularly call the framework interface of the present invention to create corresponding common task flows and add them to the task_flow queue. It can also detect the occurrence of faults and automatically trigger the creation of faulty task flows and add them to the fault_flow queue by applying its own regular inspection and other measures. The framework will read the two task queues regularly according to the configured Quartz scheduling strategy and give priority to processing as long as the faulty task flow queue is not empty. At the same time, Quartz can be configured to detect the execution status of the task flow to realize logical processing such as retry or skipping of the task, thereby realizing adaptive scheduling execution of the task.
[0038] System Example
[0039] The present invention provides a task scheduling adaptive execution framework for task flow and task step construction execution model, such as Figure 1-Figure 4 As shown, the main contents of the framework of the present invention are as follows:
[0040] The first is state machine modeling. The state machine design pattern is used to save and manage two types of task flow information: normal and faulty. When the service introduced into the framework is started, the persistent task flow related data in the database will be read and merged into the cache queue. When creating or executing a task flow, the task flow context information in the database and cache queue will also be processed synchronously. Figure 1 , Figure 2 and Figure 3 .
[0041] The second is the task flow queue and Quartz scheduling. By configuring Quartz's task flow execution scheduling strategy, the existence of tasks in the two queues is regularly queried and the fault task flow queue is read first. As long as the fault task flow queue is not empty, the head element information of the fault task flow queue is read first to trigger the execution of the fault task flow function code; if the fault task flow queue is empty, the head element information of the ordinary task flow queue is read to trigger the execution of the ordinary task flow function code; if both queues are empty, the scheduling is skipped and waits for the next scheduling. Among them, each trigger of the task flow corresponds to the execution of an internal task step. If the task step is executed successfully and this task is the last step of the task flow, the execution of this task flow is directly terminated and removed from the ordinary task queue; if the task step is executed successfully but this task is not the last step of the task flow, the step sequence value of the task to be executed corresponding to the task flow will be increased by 1 and re-added to the head of the ordinary task flow queue so that the same task can be scheduled and executed next time. If the task step fails to execute, the task flow status will be updated and the failure information will be marked. At the same time, by configuring Quartz's task flow inspection and scheduling strategy, you can perform adaptive retries for scenarios such as timeouts and failures during task flow execution. Figure 4 .
[0042] Then comes the specific logical implementation of the task steps. Each task flow is composed of multiple task steps. The execution of each task step is idempotent and stateless. The context information corresponding to the task flow and its specific task step context information are persistently stored in the database, and mapped and associated with the task flow ID and the task step ID. At the same time, subtasks can also be cascaded in the task steps, and because the task execution is stateless, the same steps in multiple task flows can share a single interface code and execute multiple times. The encapsulation of specific task steps is completed by associating the context information in the database, which can greatly improve code reusability.
[0043] Finally, it is integrated use. The task scheduling and processing execution framework based on the state machine and Quartz is developed and encapsulated into a jar package dependency for reference and integration by other service projects. Its users can build task steps and task flows and schedule execution strategies by calling the interfaces provided by the framework or using configuration items, thereby completing task scheduling and execution in actual business application scenarios.
[0044] Example
[0045] For another specific embodiment of the invention, please refer to Figure 1-Figure 4 , discloses a method flow of a task scheduling adaptive execution framework as follows:
[0046] 1. State machine model: The task scheduling and execution process is modeled as a state machine, where each state represents a different execution stage of the task, and the transitions between states represent the execution flow and dependencies of the task.
[0047] 2. Task step definition: Use step to define different steps of a task. Each step can include the triggering condition, execution time, execution code, etc. of the task.
[0048] 3. Task process definition: Use flow to define the task process, that is, the execution order and dependencies of task steps.
[0049] 4. Task queue management: Use the normal task flow queue and the fault task flow queue to save two types of task flows. The normal task flow queue is used to save tasks with normal processes, and the fault task flow queue is used to save tasks with faults.
[0050] 5. Quartz scheduling algorithm: Quartz's scheduling algorithm is used to periodically query the existence of tasks in the two queues, and the faulty task flow queue is read first. If the faulty task flow queue is not empty, the first task flow is taken out to trigger the execution of the task flow function code.
[0051] 6. Task flow execution management: After the current step of the task flow is executed, it will detect whether the currently executed task step is the last step. If so, the execution of the current task flow will be terminated and removed from the queue. If not, the sequence number of the current execution step of the task will be increased by 1, and the task flow will be put into the head of the corresponding queue again, so that it will be scheduled into the execution model again to realize the continued execution of the task.
[0052] In summary, the technical points of the present invention are as follows:
[0053] 1. Use the state machine design pattern to model the task flow and task composition steps, and use databases and other persistent storage context information to modularize the task functions. It can be customized and assembled, which is flexible, convenient and highly reusable.
[0054] 2. Use the internal cache queue to store task flow information, and use Quartz to schedule the cache queue elements to trigger the execution of the task flow, including the first trigger execution after the task flow is created, status inspection of historical task flow execution, and retry of timeout or faulty tasks, supporting customized task scheduling and processing strategies.
[0055] 3. By storing different types of task flows in different cache queues and adopting different priority reading algorithms for queue elements, priority processing of faulty tasks is ensured. Different fault handling strategies are used to make task scheduling and execution more adaptive, thus ensuring the robustness of service task processing.
[0056] 4. The framework has built-in task flows and task steps as well as flow processing models and algorithms between different states. Users only need to introduce dependencies and then call interfaces and define the task flow process and implement the specific processing logic of task steps through configuration. It is easy to integrate and simple to use.
[0057] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the embodiments of the present invention, rather than to limit them. Although the present invention has been described in detail with reference to the above embodiments, those skilled in the art should understand that they can still modify the technical solutions recorded in the above embodiments, or replace some of the technical features therein by equivalents; and these modifications or replacements do not make the essence of the corresponding technical solutions deviate from the spirit and scope of the technical solutions of the embodiments of the present invention. Any changes or replacements that can be easily thought of by those skilled in the art within the technical scope disclosed in the present invention should be covered within the protection scope of the present invention.
Claims
1. A task scheduling adaptive execution framework system, characterized in that: include: State machine model module: used to model the task scheduling and processing execution process as a state machine, where each state represents a different execution stage of the task, and the transition between states represents the execution process and dependency of the task; Task step definition module: define different steps of a task by using step; Task process definition module: defines the task process by using flow, that is, the execution order and dependencies of task steps; Task queue management module: saves two types of task flows by using normal task flow queue and fault task flow queue; Quartz scheduling algorithm module: uses Quartz's scheduling algorithm to periodically query the existence of tasks in the two queues and give priority to reading the faulty task flow queue; Task flow execution management module: used to manage task flow queues.
2. A task scheduling adaptive execution framework system according to claim 1, characterized in that: When the state machine module is started, it will read the persistent task flow related data in the database and merge it into the cache queue. When creating or executing a task flow, it will also synchronously process the task flow context information in the database and the cache queue.
3. A task scheduling adaptive execution framework system according to claim 2, characterized in that: Each task flow is composed of multiple task steps. The execution of each task step is idempotent and stateless. The context information corresponding to the task flow and its specific task step context information are persisted in the database and mapped and associated with the task flow ID and task step ID.
4. A task scheduling adaptive execution framework system according to claim 3, characterized in that: Cascading creation of subtasks is performed in task steps. The same steps in multiple task flows share a common interface code and are executed multiple times. The encapsulation of specific task steps is completed through the context information in each associated database.
5. A task scheduling adaptive execution framework system according to claim 4, characterized in that: The steps in the task step definition module include the triggering conditions, execution time, and execution code of the task.
6. A task scheduling adaptive execution framework system according to claim 5, characterized in that: The common task flow queue in the task queue management module is used to store tasks of normal flow, and the fault task flow queue is used to store tasks with faults.
7. A task scheduling adaptive execution framework system according to claim 6, characterized in that: In the Quartz scheduling algorithm module, if the faulty task flow queue is not empty, the head task flow is taken out to trigger the execution of the task flow function code; if the faulty task flow queue is empty, the head element information of the ordinary task flow queue is read to trigger the execution of the ordinary task flow function code; if both queues are empty, the current scheduling is skipped and waits for the next scheduling.
8. A task scheduling adaptive execution framework system according to claim 7, characterized in that: If the task step fails to execute, the task flow status will be updated and the failure information will be marked. At the same time, by configuring Quartz's task flow inspection and scheduling strategy, you can adaptively retry scenarios such as timeouts and failures during the task flow execution process.
9. A task scheduling adaptive execution framework system according to claim 8, characterized in that: After the current step of the task flow in the task flow management module is executed, it will detect whether the currently executed task step is the last step; if so, the execution of the current task flow is terminated and it is removed from the queue.
10. A task scheduling adaptive execution framework system according to claim 9, characterized in that: If it is not the last step in the task flow management module, the current execution step number of the task is increased by 1, and the task flow is put into the head of the corresponding queue again, so that it is scheduled into the execution model again to realize the continued execution of the task.
