Directed acyclic task flow execution method and device, equipment and storage medium
By automatically generating declarative code and parsing the association structure, the execution status of the directed acyclic task flow is obtained, which solves the problem of low processing efficiency of complex task scheduling systems in the existing technology and realizes efficient task flow processing.
Patent Information
- Application Number
- CN202410633462.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-05-21
- Publication Date
- 2024-09-03
AI Technical Summary
The existing technology lacks a solution to automatically generate a declarative programming language and obtain dependent node information based on an association structure in the form of key-value pairs, resulting in a complex directed acyclic task scheduling system with low processing efficiency and an inability to meet the needs of a huge number of tasks.
By obtaining the directed acyclic task flow, the declarative code corresponding to the task flow graph is automatically generated, and parsed to form an association structure. Nodes with empty dependency information continuously obtain execution status from the preset time interval. If all dependent nodes are completed, execution will begin. , until the task flow is executed or fails.
It improves the processing efficiency of task flow, improves the efficiency of searching the dependent node status of each node, simplifies the processing process of task flow, and is suitable for complex directed acyclic task scheduling.
Smart Images

Figure CN118585176A
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of automatic execution of task flows, and in particular to a method, device, equipment and storage medium for executing directed acyclic task flows. Background Art
[0002] With the rapid development of big data and artificial intelligence applications, the demand for task execution in distributed systems is increasing. Directed acyclic task flows have high expressive power in describing the dependency relationships between tasks, and are therefore widely used in distributed systems.
[0003] In related technologies, complex directed acyclic tasks require clear relationships between tasks, and require the close integration of general description languages and computer programming techniques to handle complex task scheduling systems. However, the underlying computer language is too complex, and only people with certain domain knowledge can write and design it. Traditional single-point methods often use data structure algorithms such as topological sorting. The output of topological sorting is all the orders that can be executed, and it cannot take into account the processing efficiency of the nodes in real time, and cannot meet the huge number of tasks.
[0004] Based on the above analysis of the development status of this technical field, the existing technology lacks a solution for automatically generating a declarative programming language and obtaining dependent node information in combination with an association structure in the form of key-value pairs. Summary of the invention
[0005] The purpose of the present invention is to provide a method, device, equipment and storage medium for executing a directed acyclic task flow, aiming to solve the above-mentioned problems in the prior art.
[0006] According to a first aspect of an embodiment of the present invention, a method for executing a directed acyclic task flow is provided, comprising:
[0007] Obtain a directed acyclic task flow with execution order dependency, visualize the directed acyclic task flow as a task flow graph, and automatically generate declarative code corresponding to the task flow graph;
[0008] Parse the declarative code to form an association structure, where the key of the association structure is a node representing a task, and the value of the association structure is a structure including dependency information and execution status;
[0009] Execute nodes whose dependency information is empty;
[0010] The node set whose execution status is not started in the associated structure is continuously obtained at preset time intervals. In the node set, if the execution status of each node that a node depends on is completed, the node will be executed until the directed acyclic task flow is completed or a node fails to execute.
[0011] According to a second aspect of an embodiment of the present invention, there is provided an execution device for a directed acyclic task flow, comprising:
[0012] The declarative code generation module is used to obtain a directed acyclic task flow with execution order dependency, visualize the directed acyclic task flow as a task flow graph, and automatically generate the declarative code corresponding to the task flow graph;
[0013] An association structure generation module is used to parse the declarative code to form an association structure, wherein the key of the association structure is a node representing a task, and the value of the association structure is a structure including dependency information and execution status;
[0014] The initial execution module is used to execute nodes whose dependency information is empty;
[0015] The dependency execution module is used to continuously obtain the set of nodes in the associated structure whose execution status is not started at a preset time interval. In the node set, if the execution status of each node that a node depends on is completed, the node will be executed until the directed acyclic task flow is completed or a node fails to execute.
[0016] According to a third aspect of an embodiment of the present invention, there is provided an electronic device, comprising: a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the computer program is executed by the processor, the steps of the method for executing a directed acyclic task flow as provided in the first aspect of the present disclosure are implemented.
[0017] According to a fourth aspect of an embodiment of the present invention, a computer-readable storage medium is provided, on which a program for implementing information transmission is stored, and when the program is executed by a processor, the steps of the method for executing the directed acyclic task flow provided in the first aspect of the present disclosure are implemented.
[0018] The technical solution provided by the embodiment of the present invention includes the following beneficial effects: simple and readable declarative code is automatically generated according to the task flow diagram, and then the nodes and relationships in the declarative code are parsed to form an association structure, which is convenient for finding the execution status of the dependent nodes of the node. There is no need to pay attention to the task flow as a whole, but only the dependent nodes of each node need to be paid attention to in order to process the directed acyclic task flow, thereby improving processing efficiency.
[0019] It is to be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the present disclosure. BRIEF DESCRIPTION OF THE DRAWINGS
[0020] In order to more clearly illustrate one or more embodiments of this specification or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments recorded in this specification. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative labor.
[0021] Figure 1 is a flowchart of a method for executing a directed acyclic task flow according to an embodiment of the present invention;
[0022] Figure 2 is a schematic diagram of a task flow chart of an embodiment of the present invention;
[0023] Figure 3 is a schematic diagram of the execution flow of an embodiment of the present invention;
[0024] Figure 4 is a schematic diagram of an execution device of a directed acyclic task flow according to an embodiment of the present invention;
[0025] Figure 5 is a schematic diagram of an electronic device according to an embodiment of the present invention. DETAILED DESCRIPTION
[0026] In order to enable those skilled in the art to better understand the technical solutions in one or more embodiments of this specification, the following will be combined with the drawings in one or more embodiments of this specification to clearly and completely describe the technical solutions in one or more embodiments of this specification. Obviously, the described embodiments are only part of the embodiments of this specification, not all of the embodiments. Based on one or more embodiments of this specification, all other embodiments obtained by ordinary technicians in this field without creative work should fall within the scope of protection of this document.
[0027] Method Embodiment
[0028] According to an embodiment of the present invention, a method for executing a directed acyclic task flow is provided. Figure 1 is a flowchart of a method for executing a directed acyclic task flow according to an embodiment of the present invention. Figure 1 As shown, the execution method of the directed acyclic task flow according to an embodiment of the present invention specifically includes:
[0029] In step S110, a directed acyclic task flow with execution order dependency is obtained, the directed acyclic task flow is visualized as a task flow graph, and a declarative code corresponding to the task flow graph is automatically generated, specifically including:
[0030] Define the nodes of the task, for example, the task of node A is to execute the request, the task of node B is to send a warning, etc.
[0031] On the visual interface, drag circles and arrows to form a task flow graph DAG, where circles represent task nodes, arrows represent execution order, and the node pointed by the arrow needs to be executed after the node on the other side. The arrow can reflect dependency information. Figure 2 Schematic diagram of a task flow diagram of an embodiment of the present invention, such as Figure 2 As shown, A needs to be executed first before B and C can be executed in parallel. D can be executed only after B and C are executed. E can be executed only after D is executed.
[0032] Automatically generate DSL declarative code corresponding to the task flow diagram, such as Figure 2 The directed acyclic task flow diagram shown in the figure, the DSL declarative code definition defined in the embodiment of the present invention is as follows:
[0033]
[0034]
[0035] Among them, name represents the task flow name, description represents the description information, workflow represents the workflow, node_x represents the instance of the node, type represents the name of the node, depend represents the immediate predecessor node of the dependency, and param represents other execution-related parameters.
[0036] In step S120, the declarative code is parsed to form an association structure, wherein the key of the association structure is a node representing a task, and the value of the association structure is a structure including dependency information and execution status, specifically including:
[0037] Get the declarative code, parse the nodes and dependency information representing the tasks in the declarative code, and generate the corresponding Map association structure, that is, store the nodes and dependency information in the Map container. The key-value pair of the association structure can be expressed as [node instance, node task structure]. The node instance is node_1, node_2, etc. Initialize all execution states in the Map association structure to New. The structure is defined as follows:
[0038] Node task: a structure object, {
[0039] String type;
[0040] Set <string>dependences;
[0041] String status;
[0042] }
[0043] Among them, type represents the node type, that is, the name of the node such as A, B, C, dependencies represents dependency information, that is, the node instance of the immediate predecessor node, and status represents the execution status, which is divided into New, Running, and Finished in this embodiment.
[0044] In step S130, executing the node whose dependency information is empty specifically includes:
[0045] Traverse the key-value pair information of the association structure, and obtain the nodes corresponding to all keys with empty dependency information as the first-tier set. In this example, there is only node A in the first-tier set.
[0046] Execute the tasks corresponding to all nodes in the first echelon set, and change the execution status to executing. When the task is completed, change the execution status of the corresponding node to completed.
[0047] In step S140, a node set whose execution status is not started in the association structure is continuously obtained at a preset time interval. In the node set, if the execution status of each node that a node depends on is completed, the node is started to be executed until the directed acyclic task flow is completed or a node fails to execute, which specifically includes:
[0048] Traverse the node set whose execution status is not started, and obtain the dependency information in the node set, wherein the dependency information is one or more directly associated previous nodes that need to be executed before the node corresponding to the key, and specifically stores the node instance name of the previous node;
[0049] Search the association structure for the predecessor information of all predecessor nodes as keys, obtain the execution status of the predecessor information, if all execution statuses are completed, the node meets the execution condition and starts to execute, and the execution status of the node is changed to executing, and when the task is completed, the execution status of the node is modified to completed. That is to say, in this embodiment, if node D needs to be executed, it is necessary to search the key-value pair with B and C as keys in the key structure, and determine that the execution status of B and C are both completed before executing node D; although A also needs to be executed before D, A is not directly associated with D, so there is no need to judge A.
[0050] Continuously obtain the set of unstarted nodes and execute the nodes that meet the conditions until the execution status of all nodes in the associated structure is completed. In other words, it terminates when the set of nodes whose execution status is unstarted cannot be obtained, or when a node fails to execute. When a node executes for too long, it can also be considered as failed.
[0051] Preferably, in order to save the efficiency of traversal, a list of states that have not started execution can be maintained, and the set of nodes that have not started execution at the current moment can be directly obtained from the list during each traversal; at the same time, post-order dependent nodes can also be defined in the map association structure. In this case, when a node has not been executed, when judging whether the nodes in the node set meet the execution conditions in turn, the execution conditions of subsequent nodes do not need to be judged. That is to say, when C has not been executed, there is no need to judge the predecessor node of D, which can reduce the number of judgments to a certain extent.
[0052] The above technical solutions of the embodiments of the present invention are illustrated with reference to the following drawings.
[0053] Figure 3 is a schematic diagram of the execution flow of an embodiment of the present invention, such as Figure 3 As shown in the figure, the complete solution of directed acyclic task flow is demonstrated, including parsing declarative code, generating Map, executing nodes without dependencies, and updating and executing nodes with dependencies. It should be noted that judging the end or failure of task execution after the start of execution of tasks without dependencies can prevent the task from containing only nodes without dependencies. For a normal directed acyclic task flow task, the step of judging the end or failure of task execution can be moved to after updating the node status.
[0054] To sum up, in response to the existing problems, the execution method of the directed acyclic task flow invented this time automatically generates simple and readable declarative code according to the task flow graph, and the declarative code can be easily understood by researchers in various fields; then the nodes and relationships in the declarative code are parsed to form an associated structure, and the Map data structure has a high search efficiency, which is convenient for finding the execution status of the dependent nodes of the node; execution starts from the node whose execution dependency information is empty to ensure the correctness of the directed acyclic task processing; in general, there is no need to pay attention to the task flow as a whole, only the dependent nodes of each node need to be paid attention to to process the directed acyclic task flow, which improves the processing efficiency.
[0055] Device Embodiment
[0056] According to an embodiment of the present invention, a device for executing a directed acyclic task flow is provided. Figure 4 is a schematic diagram of an execution device of a directed acyclic task flow according to an embodiment of the present invention. Figure 4 As shown, the execution device of the directed acyclic task flow according to the embodiment of the present invention specifically includes:
[0057] The declarative code generation module 40 is used to obtain a directed acyclic task flow with execution order dependency, visualize the directed acyclic task flow as a task flow graph, and automatically generate declarative code corresponding to the task flow graph, specifically for:
[0058] On the visual interface, drag circles and arrows to form a task flow diagram, where circles represent task nodes and arrows represent execution order;
[0059] Automatically generate DSL declarative code corresponding to the task flow diagram.
[0060] The association structure generation module 42 is used to parse the declarative code to form an association structure, wherein the key of the association structure is a node representing a task, and the value of the association structure is a structure including dependency information and execution status, and is specifically used to:
[0061] Get the declarative code, parse the nodes and dependency information representing the tasks in the declarative code, generate the corresponding Map association structure, and initialize all execution states in the Map association structure to not started.
[0062] The initial execution module 46 is used to execute the node whose dependency information is empty, specifically to:
[0063] Traverse the key-value pair information of the association structure, and obtain the nodes corresponding to all keys whose dependency information is empty as the first-tier set;
[0064] Execute the tasks corresponding to all nodes in the first echelon set, and change the execution status to executing. When the task is completed, change the execution status of the corresponding node to completed.
[0065] The dependency execution module 48 is used to continuously obtain a set of nodes in the association structure whose execution status is not started at a preset time interval. In the node set, if the execution status of each node on which a node depends is completed, the node is started to be executed until the directed acyclic task flow is completed or a node fails to execute. Specifically, it is used to:
[0066] Traverse the node set whose execution state is not started, and obtain dependency information in the node set, wherein the dependency information is one or more directly associated preceding nodes that need to be executed before the node corresponding to the key;
[0067] Search for the pre-order information of all pre-order nodes as keys in the association structure, obtain the execution status of the pre-order information, if all execution statuses are completed, the node meets the execution condition and starts to execute, change the execution status of the node to executing, and modify the execution status of the node to completed when the task is executed;
[0068] Continuously obtain the unstarted node set and execute the nodes that meet the conditions until the execution status of all nodes in the associated structure is completed, or terminate when a node fails to execute.
[0069] To sum up, in response to the existing problems, the execution device of the directed acyclic task flow invented this time automatically generates simple and readable declarative code according to the task flow diagram, and the declarative code can be easily understood by researchers in various fields; then the nodes and relationships in the declarative code are parsed to form an associated structure, and the Map data structure has a high search efficiency, which is convenient for finding the execution status of the dependent nodes of the node; execution starts from the node whose execution dependency information is empty to ensure the correctness of the directed acyclic task processing; in general, there is no need to pay attention to the task flow as a whole, only the dependent nodes of each node need to be paid attention to to process the directed acyclic task flow, which improves the processing efficiency.
[0070] Electronic device embodiment
[0071] Figure 5 Schematic diagram of an electronic device according to an embodiment of the present invention. The electronic device 500 may include at least one processor 510 and a memory 520. The processor 510 may execute instructions stored in the memory 520. The processor 510 is connected to the memory 520 through a data bus. In addition to the memory 520, the processor 510 may also be connected to an input device 530, an output device 540, and a communication device 550 through a data bus.
[0072] The processor 510 may be any conventional processor, such as a commercially available CPU. The processor may also include a graphics processor (Graphic Process Unit, GPU), a field programmable gate array (Field Programmable Gate Array, FPGA), a system on chip (System on Chip, SOC), an application specific integrated circuit (Application Specific Integrated Circuit, ASIC) or a combination thereof.
[0073] The memory 520 may be implemented by any type of volatile or nonvolatile storage device or a combination thereof, such as static random access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic memory, flash memory, magnetic disk or optical disk.
[0074] In the embodiment of the present disclosure, executable instructions are stored in the memory 520, and the processor 510 can read the executable instructions from the memory 520 and execute the instructions to implement all or part of the steps of the execution method of the directed acyclic task flow in any of the above exemplary embodiments.
[0075] Computer Readable Storage Medium Embodiments
[0076] In addition to the above-mentioned methods and apparatus, an exemplary embodiment of the present disclosure may also be a computer program product or a computer-readable storage medium storing the computer program product, wherein the computer product includes computer program instructions that can be executed by a processor to implement all or part of the steps described in the execution method of the directed acyclic task flow in any of the above-mentioned exemplary embodiments.
[0077] The computer program product may be written in any combination of one or more programming languages to write program codes for performing the operations of the embodiments of the present application, including object-oriented programming languages such as Java, C++, etc., and also conventional procedural programming languages such as "C" language or similar programming languages and scripting languages (e.g., Python). The program code may be executed entirely on the user computing device, partially on the user computing device, as an independent software package, partially on the user computing device and partially on a remote computing device, or entirely on a remote computing device or server.
[0078] Computer readable storage media can adopt any combination of one or more readable media. The readable medium can be a readable signal medium or a readable storage medium. The readable storage medium can include, for example, but is not limited to, a system, device or device of electricity, magnetism, light, electromagnetic, infrared, or semiconductor, or any combination of the above. More specific examples of readable storage media include: a static random access memory (SRAM) with one or more wires electrically connected, an electrically erasable programmable read-only memory (EEPROM), an erasable programmable read-only memory (EPROM), a programmable read-only memory (PROM), a read-only memory (ROM), a magnetic memory, a flash memory, a magnetic disk or an optical disk, or any suitable combination of the above.
[0079] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or replace some or all of the technical features therein by equivalents. However, these modifications or replacements do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of the present invention.< / string>
Claims
1. A method for executing a directed acyclic task flow, characterized in that: include: Obtaining a directed acyclic task flow with execution order dependency, visualizing the directed acyclic task flow as a task flow graph, and automatically generating declarative code corresponding to the task flow graph; Parsing the declarative code to form an association structure, wherein a key of the association structure is a node representing a task, and a value of the association structure is a structure including dependency information and an execution status; Execute the node whose dependency information is empty; A set of nodes in the association structure whose execution status is not started is continuously obtained at preset time intervals. In the node set, if the execution statuses of the nodes that a certain node depends on are all completed, the execution of the node begins until the directed acyclic task flow is completed or the execution of a certain node fails.
2. The method according to claim 1, characterized in that The step of visualizing the directed acyclic task flow as a task flow graph and automatically generating a declarative code corresponding to the task flow graph specifically includes: A task flow chart is formed by dragging circles and arrows on a visual interface, wherein the circles represent task nodes and the arrows represent execution order; Automatically generate DSL declarative code corresponding to the task flow graph.
3. The method according to claim 1, characterized in that The parsing of the declarative code to form an associated structure specifically includes: The declarative code is obtained, nodes and dependency information representing tasks in the declarative code are parsed, a corresponding Map association structure is generated, and all execution states in the Map association structure are initialized to not started.
4. The method according to claim 1, characterized in that: The execution of the node whose dependency information is empty specifically includes: Traversing the key-value pair information of the association structure, obtaining nodes corresponding to all keys whose dependency information is empty as a first-tier set; Execute the tasks corresponding to all nodes in the first echelon set, and change the execution status to executing. When the task is completed, modify the execution status of the corresponding node to completed.
5. The method according to claim 1, characterized in that In the node set, if the execution statuses of the nodes that a node depends on are all completed, then the node is started to be executed until the directed acyclic task flow is completed or a node fails to execute, specifically including: Traversing a node set whose execution state is not started, and obtaining dependency information in the node set, wherein the dependency information is one or more directly associated preceding nodes that need to be executed before the node corresponding to the key; Searching for the pre-order information of all pre-order nodes as keys in the association structure, obtaining the execution status of the pre-order information, and if all execution statuses are completed, the node meets the execution condition and starts to execute, and the execution status of the node is changed to executing, and when the task is executed, the execution status of the node is modified to completed; Continuously obtain the unstarted node set and execute the nodes that meet the conditions until the execution status of all nodes in the associated structure is completed, or terminate when a node fails to execute.
6. A directed acyclic task flow execution device, characterized in that: include: A declarative code generation module, used to obtain a directed acyclic task flow with execution order dependency, visualize the directed acyclic task flow as a task flow graph, and automatically generate declarative code corresponding to the task flow graph; An association structure generation module, used for parsing the declarative code to form an association structure, wherein the key of the association structure is a node representing a task, and the value of the association structure is a structure including dependency information and execution status; An initial execution module, used for executing the node whose dependency information is empty; The dependency execution module is used to continuously obtain a set of nodes in the association structure whose execution status is not started at a preset time interval. In the node set, if the execution statuses of the nodes that a certain node depends on are all completed, the execution of the node will start until the directed acyclic task flow is completed or a certain node fails to execute.
7. The device according to claim 6, characterized in that The association structure generation module is specifically used for: The declarative code is obtained, nodes and dependency information representing tasks in the declarative code are parsed, a corresponding Map association structure is generated, and all execution states in the Map association structure are initialized to not started.
8. The device according to claim 6, characterized in that The dependency execution module is specifically used for: Traversing a node set whose execution state is not started, and obtaining dependency information in the node set, wherein the dependency information is one or more directly associated preceding nodes that need to be executed before the node corresponding to the key; Searching for the pre-order information of all pre-order nodes as keys in the association structure, obtaining the execution status of the pre-order information, and if all execution statuses are completed, the node meets the execution condition and starts to execute, and the execution status of the node is changed to executing, and when the task is executed, the execution status of the node is modified to completed; Continuously obtain the unstarted node set and execute the nodes that meet the conditions until the execution status of all nodes in the associated structure is completed, or terminate when a node fails to execute.
9. An electronic device, characterized in that: include: A memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the computer program is executed by the processor, the steps of the method for executing a directed acyclic task flow as described in any one of claims 1 to 5 are implemented.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores an implementation program for information transmission, and when the program is executed by a processor, the steps of the method for executing a directed acyclic task flow as described in any one of claims 1 to 5 are implemented.
