Method and system for realizing serial execution of task flow
By building a task flowchart and initializing the execution context, the problem of insufficient flexibility in task serial execution is solved, dynamic adjustment of task order and logic is realized, the code structure is simplified, and the flexibility and maintainability of task management are improved.
Patent Information
- Application Number
- CN202510442176.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-04-09
- Publication Date
- 2025-07-18
AI Technical Summary
In the prior art, the serial execution method of tasks lacks flexibility and makes it difficult to dynamically adjust the task sequence and logic. Especially when handling asynchronous tasks, the code structure is complex, resulting in poor readability and maintainability.
By building a task flow chart, adding task nodes and links, initializing the execution context, and updating the task flow chart according to needs, uniformly handling synchronous and asynchronous tasks, providing task scheduling and result management.
It improves the flexibility and maintainability of task execution, simplifies code complexity, supports conditional task flow, realizes data sharing and result management among tasks, and improves the reusability and traceability of code.
Smart Images

Figure CN120335965A_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of software development, and particularly relates to a method and system for realizing serial execution of a task flow. Background Art
[0002] In software development, it is a common requirement to execute a series of tasks arranged in a specific order. Traditionally, hard coding is mostly used to achieve serial execution of tasks, and this method has obvious defects.
[0003] On the one hand, the flexibility of using hard coding for serial execution of tasks is insufficient. Especially when it is necessary to dynamically adjust the task order or execution logic, a large amount of code often needs to be modified, which will consume a large amount of time and labor costs. For example, in a business process involving multiple data processing steps, if hard coding is used, once the business rules change, such as adding a data verification step or changing the data processing order, modifications need to be made in multiple places in the code, and new errors are easily introduced. On the other hand, when dealing with asynchronous tasks, the code structure becomes extremely complex when using hard coding, and the readability and maintainability are low. For example, in a business process when the tasks include asynchronous operations, such as network requests or database queries, the difficulty of writing and debugging the code will increase greatly, which may lead to nested code layers, the callback hell phenomenon, and ultimately result in poor code readability, difficult maintenance, and error handling problems.
[0004] Therefore, there is an urgent need to develop a more flexible, configurable, and easy-to-manage method for serial execution of tasks to meet the requirements of a new generation of software development for high efficiency, flexibility, and maintainability. Summary of the Invention
[0005] In a first aspect, an embodiment of the present application provides a method for realizing serial execution of a task flow, including the following steps: S1. Add task nodes and task links to construct a task flow chart; S2. Use the environment information and parameters required for task execution as the execution context and initialize it; S3. When it is necessary to change a task, update the task flow chart; S4. Schedule and execute tasks according to the task flow chart, and update the execution context according to the execution results.
[0006] Further, the specific steps of step S1 are as follows: S11. Determine the task attributes of the task nodes to be executed, where the task attributes include task names, task functions, and unique identifiers; S12. Add each task node and establish the corresponding relationship between the task node and the task attribute to complete the creation of the task node; S13. Determine two task nodes with an execution order, establish a task link between them, and define the task link attributes; the task link attributes include the source task, the target task, and the execution condition; S14. Define the source task and the target task according to the execution order, and set the execution condition according to whether the target task is executed, to complete the creation of the task link.
[0007] Further, the specific steps of step S2 are as follows: S21. Create a new context object; S22. Determine the initial parameters for task execution and fill them into the context object to complete the initialization of the execution context; the initial parameters include the environment information, input parameters, and output parameters required for task execution.
[0008] Further, the specific steps of step S2 are as follows: S21. Set the execution context required for task execution, including global parameters, task result sets, and current task information; S22. Create a new execution context object and initialize the input parameters and environment parameters that need to be set in the global parameters.
[0009] Further, the specific steps of step S3 are as follows: S31. Determine whether the task needs to be changed; If so, go to step S32; If not, go to step S4; S32. Change the task nodes and task links that need to be changed, and update the task flow chart.
[0010] Further, the specific steps of step S32 are as follows: S321. Determine whether the task node needs to be changed; If so, go to step S322; If not, go to step S323; S322. Add new task nodes and their task attributes as required, delete existing task nodes and their task attributes, and change the task attributes of existing task nodes; S323. Determine whether the task link needs to be changed; If so, go to step S324; If not, go to step S4; S324. Establish new task links as required, add task link attributes, delete existing task links, and change the task attributes of existing task links; S325. Update the task flow chart according to the changes in the task nodes and task links.
[0011] Further, the specific steps of step S4 are as follows: S41. Convert the task flow chart into an executable task sequence; S42. Determine the set of task nodes to which the next task to be executed belongs based on the execution status of the current task from the task sequence to obtain candidate tasks; S43. Determine the task type of the current task; If it is a synchronous task, go to step S44; If it is not an asynchronous task, go to step S45; S44. Directly call the task function corresponding to the task node of the current task to obtain the execution result, and go to step S46; S45. Wait for the completion after executing the task function corresponding to the task node of the current task, and obtain the execution result; S46. Obtain the execution conditions in the set of task nodes to which the current task and the next task to be executed belong, and make a judgment in combination with the execution result to find the next task to be executed and determine whether it is found; If yes, go to step S47; If no, go to step S48; S47. Save the execution result of the current task to the execution context, take the next task to be executed as the current task, and return to step S3; S48. Aggregate and output the execution results of each completed task, and clean up the execution context as needed.
[0012] Further, the specific steps of step S46 are as follows: S461. Obtain each candidate task in the set of task nodes to which the next task to be executed belongs; S462. Obtain the execution conditions of the task links between the task node to which the current task belongs and each candidate task; S463. Convert the conditional expressions in string form in each execution condition into executable conditional functions; S464. Select an executable conditional function according to the execution result of the current task and execute it to find the next task to be executed; If there is a next task to be executed, go to step S47; If there is no next task to be executed, go to step S48; The specific steps of step S47 are as follows: S471. Save the task name and start time of the current task to the current task information in the execution context; S472. Save the execution result of the current task to the task result set in the execution context; S474. Set the next task to be executed as the current task and return to step S3.
[0013] Further, the specific steps of step S48 are as follows: S481. Obtain the execution results of each task, perform aggregation processing as required, and obtain the final output; S482. Determine whether a query request for a single task is received; If so, go to step S83; If not, go to step S484; S483. Obtain the execution result of the task to be queried from the execution context and return it to the user; S484. Output the aggregated final output; S485. Clean up the execution context that is no longer needed.
[0014] In a second aspect, an embodiment of the present application further provides a system for implementing serial execution of a task flow, including: A task node management module that adds, deletes, and manages task nodes in the task flow diagram; A task link management module that adds, deletes, and manages task links in the task flow diagram; A context management module that creates and maintains the execution context required for task execution; A task scheduling module that schedules task execution according to the task flow diagram; A task execution module that executes the task function of the corresponding task and processes it according to the task type; A condition evaluation module that evaluates the execution conditions of task links to determine the next task to be executed; A result management module that stores and manages task execution results.
[0015] Further, the task management module includes: A task node creation unit that creates a task node according to the provided task name and task function and sets a unique identifier; A task node update unit that modifies the task attributes or task functions of existing task nodes; A task node deletion unit that removes a specified task node from the task flow diagram; The task link management module includes: A task link creation unit that establishes a task link between two task nodes according to the execution order and defines task link attributes; A task link update unit that modifies the attributes of existing task links; A task link deletion unit that removes a specified task link from the task flow diagram; The context management module includes: A context initialization unit that creates a new execution context and sets the initial parameters for task execution; A context update unit that updates the data in the execution context during task execution; A context cleaning unit that cleans up the execution contexts that are no longer needed after all tasks have been executed; The task scheduling module includes: A task serialization unit that converts the task flow chart into an executable task sequence; A task dispatching unit that determines the set of task nodes to which the next task to be executed belongs based on the execution status of the current task, and obtains candidate tasks; The task execution module includes: A synchronous task execution unit that directly invokes the task function for synchronous tasks to obtain the execution result; An asynchronous task execution unit that waits for completion after executing the task function for asynchronous tasks and then obtains the execution result; An error handling unit that captures and handles exceptions that occur during the execution of the task function; The condition evaluation module includes: A condition parsing unit that converts the conditional expression in string form in the execution condition into an executable conditional function; A condition execution unit that selects an executable conditional function based on the execution result of the current task and executes it to find the next task to be executed; A condition modification unit that dynamically modifies or adds execution conditions during task execution; The result management module includes: A result storage unit that saves the execution result of each task to the execution context; A result query unit that provides an interface to query the execution result of a single task; A result aggregation unit that performs aggregation processing on the execution results of multiple tasks to obtain the final output.
[0016] From the above technical solutions, it can be seen that the present invention has the following advantages: In the method and system for implementing serial execution of a task flow provided by this application, the flexibility of task execution is improved, dynamic configuration of the task flow is supported, and the execution order and logic of tasks can be flexibly adjusted according to actual requirements; synchronous and asynchronous tasks are uniformly processed, simplifying the code complexity, and developers can use a consistent interface to handle different types of tasks; a clear task execution model is provided, which is easy to understand and maintain, enabling complex business processes to be clearly expressed and managed; conditional task flow is supported, and the execution path can be dynamically adjusted according to the execution result, achieving more flexible business logic control; the task definition and execution logic are separated, improving the code reusability and allowing developers to more easily reuse and combine existing tasks; through execution context management, data sharing and transfer between tasks are realized, simplifying the communication mechanism between tasks; complete task life cycle management is provided, from task creation, execution to result management, making the entire process more controllable and traceable. BRIEF DESCRIPTION OF THE DRAWINGS
[0017] To more clearly illustrate the technical solutions of the present invention, the drawings required for description will be briefly introduced below. Obviously, the drawings in the following description are only some embodiments of the present invention. For those of ordinary skill in the art, other drawings can be obtained based on these drawings without creative efforts.
[0018] Figure 1 It is a schematic flowchart of the method for implementing serial execution of a task flow of the present invention.
[0019] Figure 2 It is a schematic diagram of the system for implementing serial execution of a task flow of the present invention. DETAILED DESCRIPTION OF THE EMBODIMENTS
[0020] In the following, the specific steps of the method for implementing serial execution of a task flow will be described in detail, and various embodiments of the present disclosure will be described more comprehensively. The present disclosure may have various embodiments, and adjustments and changes may be made therein. However, it should be understood that there is no intention to limit the various embodiments of the present disclosure to the specific embodiments disclosed herein, but the present disclosure should be understood to cover all adjustments, equivalents, and / or alternative solutions that fall within the spirit and scope of the various embodiments of the present disclosure.
[0021] Exemplarily, in the practice of software development, it is often necessary to execute a series of tasks in a specific order. The traditional approach is to implement serial execution of tasks through hard coding, but this approach has significant limitations.
[0022] The first problem is that the hard-coded task serial execution mode lacks flexibility. Especially when the task order or logic needs to be adjusted dynamically, developers often have to go deep into the core part of the code to make a lot of modifications, which is not only time-consuming and labor-intensive, but also very likely to cause new errors. Take the data processing process as an example. If the rules in the business process change, such as adding a data verification link or adjusting the order of processing steps, the hard-coded method will force developers to make tedious modifications in multiple code locations, which undoubtedly increases the risk of errors.
[0023] Secondly, when handling asynchronous tasks, hard coding makes the code structure more complicated, and the readability and maintainability are greatly reduced. For example, in a business process that includes asynchronous operations (such as network requests, database queries, etc.), developers may face the dilemma of nested codes and callback hell, which not only makes code writing and debugging extremely difficult, but also seriously affects the readability of the code and the convenience of subsequent maintenance, and also increases the difficulty of error handling.
[0024] In view of this, we urgently need a more flexible, configurable and easy-to-manage task serial execution solution to meet the current software development's urgent needs for efficiency, flexibility and maintainability.
[0025] In response to the above problems, this embodiment provides a method for implementing serial execution of task flows. By constructing a task flow chart and initializing the execution context, a clear task flow and necessary execution environment are provided for subsequent task scheduling and execution, thereby improving the flexibility and efficiency of task management.
[0026] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0027] See also Figure 1 The figure is a flowchart of a method for implementing serial execution of task flows in a specific embodiment, the method comprising the following steps: S1. Add task nodes and task links to build a task flow chart; It should be noted that by constructing a task flow chart, the abstract task logic can be presented in an intuitive graphical way, enabling developers to add task nodes and task links through a graphical interface, making the entire task flow more intuitive; and it allows for flexible addition of task nodes and task links according to actual business requirements; when the business changes, the task flow chart can be adjusted, for example, adding new task nodes to handle new business logics, or modifying task links to change the execution order of tasks; and each task node, as an independent module, has a task name and a task function; S2. Use the environmental information and parameters required for task execution as the execution context and initialize it; It should be noted that by initializing the execution context, the consistency of the running environment during task execution can be ensured; the environmental information and parameters included in the execution context can provide necessary support for tasks, such as database connection information, configuration parameters, etc., enabling tasks to run stably under the same environmental conditions; tasks can store the results in the execution context during execution for subsequent tasks to use, so the execution context undertakes data sharing and transfer between tasks; for example, a data processing task can store the processing results in the execution context, and subsequent data analysis tasks can directly obtain these results from the execution context for analysis; S3. When it is necessary to change the task, update the task flow chart; It should be noted that in actual business, requirements often need to change, and such changes can be quickly responded to by updating the task flow chart; for example, when business rules are adjusted, task nodes or task links can be directly modified in the task flow chart without the need for large-scale reconstruction of the entire system; compared with the hard-coded task execution method, updating the task flow chart is more intuitive and simple, and developers only need to operate on the graphical interface to complete the task change; therefore, changing tasks by updating the task flow chart reduces the amount of code modification, lowers the difficulty and cost of maintenance, and at the same time, also reduces the risk of introducing new errors due to code modification; S4. Schedule and execute tasks according to the task flow chart, and update the execution context according to the execution results; It should be noted that the tasks are scheduled and executed according to the task flow chart to achieve the automated processing of tasks. The system can automatically call the corresponding task functions according to the sequence and conditions of the task flow chart, reducing manual intervention and improving the efficiency of task execution; update the execution context according to the execution results of the tasks, enabling the system to obtain the execution status and results of the tasks in real time; if a certain task fails to execute, the system can perform corresponding processing according to the execution results, such as retrying the task, recording error information, etc.; at the same time, the updated execution context can also provide the latest data support for subsequent tasks to ensure the continuity of the tasks; in addition, the execution results of the tasks are stored in the execution context in a timely manner to avoid data loss or inconsistency problems.
[0028] In this embodiment, by constructing a task flow chart, the task execution sequence and dependency relationship view are intuitively displayed, and by introducing the execution context, a unified environment information and parameter management are provided for task execution.
[0029] Furthermore, as a refinement and extension of the specific implementation manner of the above embodiment, in order to fully illustrate the specific implementation process in this embodiment, another method for serial execution of the task flow is provided, and this method includes the following steps: S1. Add task nodes and task links to construct a task flow chart; the specific steps of step S1 are as follows: S11. Determine the task attributes of the task nodes to be executed, and the task attributes include task name, task function, and unique identifier; S12. Add each task node and establish the corresponding relationship between the task node and the task attributes to complete the creation of the task node; S13. Determine two task nodes with an execution sequence, establish a task link between them, and define the task link attributes; the task link attributes include source task, target task, and execution condition; S14. Define the source task and the target task according to the execution sequence, and set the execution condition according to whether the target task is executed to complete the creation of the task link; It should be noted that the specific steps for adding task nodes when constructing the task flow chart are determined, the task attributes of the task nodes are determined, and the corresponding relationship between the task node and the task attributes is established; by creating task links, the execution sequence and conditions between tasks are made more intuitive; S2. Use the environment information and parameters required for task execution as the execution context and initialize it; the specific steps of step S2 are as follows: S21. Set the execution context required for task execution to include global parameters, task result set, and current task information; S22. Create a new execution context object and initialize the input parameters and environment parameters that need to be set in the global parameters; It should be noted that determining the content included in the execution context and defining the process of creating the context object and populating the parameters ensure that the environmental information and parameters required for task execution can be correctly set; S3. When changes need to be made to the task, update the task flow chart. The specific steps of step S3 are as follows: S31. Determine whether changes need to be made to the task; If yes, go to step S32; If no, go to step S4; S32. Change the task nodes and task links that need to be changed, and update the task flow chart; It should be noted that when changes need to be made to the task, only the task nodes or task links in the task flow chart need to be adjusted, which is more intuitive and simpler than the hard - coding method; S4. Schedule and execute the task according to the task flow chart, and update the execution context based on the execution result. The specific steps of step S4 are as follows: S41. Convert the task flow chart into an executable task sequence; S42. Determine the set of task nodes to which the next task to be executed belongs according to the execution status of the current task from the task sequence, and obtain the candidate tasks; S43. Determine the task type of the current task; If it is a synchronous task, go to step S44; If it is an asynchronous task, go to step S45; S44. Directly call the task function corresponding to the task node of the current task to obtain the execution result, and go to step S46; S45. Execute the task function corresponding to the task node of the current task and wait for completion, and obtain the execution result; S46. Obtain the execution conditions in the set of task nodes to which the current task and the next task to be executed belong, combine them with the execution result for judgment, find the next task to be executed, and determine whether it is found; If yes, go to step S47; If no, go to step S48; S47. Save the execution result of the current task to the execution context, take the next task to be executed as the current task, and return to step S3; S48. Aggregate and output the execution results of the tasks that have completed execution, and clean up the execution context as needed; It should be noted that by converting the task flow chart into an executable sequence, determining candidate tasks, distinguishing the execution methods of synchronous and asynchronous tasks, and finding the next task based on the execution result, the task is executed according to the task flow chart, making the scheduling and execution of this task more precise and enabling better handling of different types of tasks; through operations such as saving the result to the context, aggregating the output, and cleaning the context, effective management of the task execution result is achieved, avoiding problems such as data loss or inconsistency.
[0030] In an embodiment of the present invention, based on step S32, a possible embodiment will be given below to non - restrictively elaborate on its specific implementation.
[0031] The specific steps of step S32 are as follows: S321. Determine whether it is necessary to change the task node; If so, go to step S322; If not, go to step S323; S322. Add new task nodes and their task attributes according to requirements, delete existing task nodes and their task attributes, and change the task attributes of existing task nodes; S323. Determine whether it is necessary to change the task link; If so, go to step S324; If not, go to step S4; S324. Establish a new task link according to requirements, add task link attributes, delete existing task links, and change the task attributes of existing task links; S325. Update the task flow chart according to the changes of the task nodes and task links; It should be noted that the operations of adding, deleting, and changing task nodes and task links enable flexible updating of the task flow chart, allowing developers to make targeted modifications to task nodes and task links according to specific requirements.
[0032] In an embodiment of the present invention, based on step S46, step S47, and step S48, a possible embodiment will be given below to non - restrictively elaborate on its specific implementation.
[0033] The specific steps of step S46 are as follows: S461. Obtain each candidate task in the task node set to which the next task to be executed belongs; S462. Obtain the execution conditions of the task links between the task node to which the current task belongs and each candidate task; S463. Convert the conditional expressions in string form in each execution condition into executable conditional functions; S464. Select an executable conditional function according to the execution result of the current task, execute it, and find the next task to be executed; If there is a next task to be executed, go to step S47; If there is no next task to be executed, go to step S48; The specific steps of step S47 are as follows: S471. Save the task name and start time of the current task to the current task information in the execution context; S472. Save the execution result of the current task to the task result set in the execution context; S474. Take the next task to be executed as the current task and return to step S3; The specific steps of step S48 are as follows: S481. Obtain the execution results of each task, perform aggregation processing as required, and obtain the final output; S482. Determine whether a query request for a single task is received; If so, go to step S483; If not, go to step S484; S483. Obtain the execution result of the task to be queried from the execution context and return it to the user; S484. Output the aggregated final output; S485. Clean up the execution context that is no longer needed; It should be noted that by obtaining candidate tasks, converting conditional expressions into executable functions, selecting and executing conditional functions according to execution results, the conditional evaluation of finding the next task to be executed is realized, making the task flow more accurate and enabling dynamic adjustment of the task execution path according to the actual execution results; by saving the task name, start time and execution results, the execution results of the current task are saved to the execution context, facilitating subsequent query and analysis of the task execution situation.
[0034] The following uses an example to illustrate the application of task flow serial execution in basic task flow execution, asynchronous task processing, and conditional branch processing.
[0035] Example 1: Basic task flow execution Refer to Figure 1 , this embodiment provides a basic task flow execution method.
[0036] S1. Add task nodes and task links to construct a task flow diagram; In this step, a simple task flow is defined, including three task nodes: Task A, Task B, and Task C; the task flow is as follows: Task A: Initialize data Task B: Process data Task C: Output result The task link is defined as follows: A -> B: Execute unconditionally B -> C: Execute when the processing result of B is greater than 0 S2. Use the environmental information and parameters required for task execution as the execution context and initialize it; Create a new context object containing the following initial data: context = { globalData: { inputValue: 10 }, taskResults: {}, currentTask: null } S4. Schedule and execute tasks according to the task flow chart and update the execution context based on the execution results; The system identifies task A as the initial node; Function to execute task A: function taskA(context) { const { inputValue} = context.globalData; return inputValue * 2; } Store the task execution result; Store the result of task A in the context: context.taskResults['taskA'] = 20; Determine the next task; The system checks the task link and finds that the link from task A to task B is executed unconditionally, so task B is selected as the next task; Find the next task to execute and check if it is found, then execute task B: function taskB(context) { const resultA = context.taskResults['taskA']; return resultA + 5; } Store the result of task B: context.taskResults['taskB'] = 25; Execute the search for the next task to be executed again and determine whether it is found. The system checks the link condition from task B to task C; since 25 > 0, the condition is satisfied, and task C is selected as the next task; Execute task C: function taskC(context) { const resultB = context.taskResults['taskB']; return ` result: ${resultB}`; } Store the result of task C: context.taskResults['taskC'] = " result: 25"; The task process execution is completed, and the final result is returned; The system returns the result of task C as the output of the entire process.
[0037] Example 2: Asynchronous task processing This example demonstrates how to process a process containing asynchronous tasks.
[0038] S1. Add task nodes and task links to build a task flow chart; Define a task process containing asynchronous operations: Task A: Synchronous initialization Task B: Asynchronous data acquisition Task C: Result processing S2. Use the environment information and parameters required for task execution as the execution context and initialize it; Execute task A (synchronous task); Execute task B (asynchronous task); function taskB(context) { return new Promise((resolve, reject) =>{ setTimeout(() =>{ resolve(context.taskResults['taskA'] * 3); }, 1000); }); } The system recognizes that task B returns a Promise and will wait for the Promise to be resolved before continuing execution; Wait for the asynchronous operation to complete, store the result, and execute task C.
[0039] Example 3: Conditional branch processing This example illustrates how to process a task flow that includes conditional branches; S1. Add task nodes and task links to construct a task flow diagram; Define a task flow that includes conditional branches: Task A: Initialization Task B1: Processing method 1 Task B2: Processing method 2 Task C: Result summary The task link definitions are as follows: A -> B1: Execute when the result of A is even A -> B2: Execute when the result of A is odd B1 -> C: Execute unconditionally B2 -> C: Execute unconditionally Initialize the context and execute task A; Determine the next task; The system evaluates the result of task A and selects to execute B1 or B2 based on parity; Execute the selected task (B1 or B2), and then execute task C; Through the above examples, the specific implementation methods of this application in three different scenarios of basic process, asynchronous task processing, and conditional branch processing are described.
[0040] It should be understood that the magnitudes of the sequence numbers of the steps in the above embodiments do not mean the order of execution is prior or posterior, and the execution order of each process should be determined according to its function and internal logic, and should not constitute any limitation to the implementation process of the embodiments of the present invention.
[0041] As Figure 2 shown, the following is an embodiment of a system for implementing serial execution of a task flow provided by an embodiment of the present disclosure. This system belongs to the same inventive concept as the method for implementing serial execution of a task flow in the above embodiments. Details not described in detail in the embodiment of the system for implementing serial execution of a task flow can be referred to the embodiment of the system for implementing serial execution of a task flow.
[0042] The system includes: A task node management module that adds, deletes, and manages task nodes in the task flow diagram; A task link management module that adds, deletes, and manages task links in the task flow diagram; A context management module that creates and maintains the execution context required for task execution; A task scheduling module that schedules task execution according to the task flow diagram; A task execution module that executes the task function corresponding to the task and processes it according to the task type; A condition evaluation module that evaluates the execution conditions of task links to determine the next task to be executed; A result management module that stores and manages the task execution results.
[0043] This embodiment constructs modules for task node management, task link management, context management, task scheduling, task execution, condition evaluation, and result management to achieve serial execution of the task flow. Each module works together to achieve efficient management and execution of the task process.
[0044] In one embodiment of the present invention, for the task node management module, task link management module, context management module, task scheduling module, task execution module, condition evaluation module, and result management module, a possible embodiment will be given below to non - restrictively elaborate on their specific implementation schemes.
[0045] The task management module includes: A task node creation unit that creates task nodes according to the provided task name and task function, and sets a unique identifier; A task node update unit that modifies the task attributes or task functions of existing task nodes; A task node deletion unit that removes the specified task node from the task flow diagram; The task link management module includes: A task link creation unit that establishes task links between two task nodes according to the execution order and defines task link attributes; A task link update unit that modifies the attributes of existing task links; A task link deletion unit that removes the specified task link from the task flow diagram; The context management module includes: A context initialization unit that creates a new execution context and sets the initial parameters for task execution; A context update unit that updates the data in the execution context during task execution; A context cleanup unit that cleans up the no - longer - needed execution context after all tasks are executed; The task scheduling module includes: A task serialization unit that converts the task flow diagram into an executable task sequence; The task assignment unit determines the set of task nodes to which the next task to be executed belongs based on the execution status of the current task, and obtains candidate tasks; The task execution module includes: The synchronous task execution unit directly calls the task function for the synchronous task to obtain the execution result; The asynchronous task execution unit waits for completion after executing the task function for the asynchronous task and then obtains the execution result; The error handling unit catches and handles exceptions that occur during the execution of the task function; The condition evaluation module includes: The condition parsing unit converts the conditional expression in string form in the execution condition into an executable conditional function; The condition execution unit selects an executable conditional function based on the execution result of the current task and executes it to find the next task to be executed; The condition modification unit dynamically modifies or adds the execution condition during the task execution process; The result management module includes: The result storage unit saves the execution result of each task to the execution context; The result query unit provides an interface to query the execution result of a single task; The result aggregation unit performs aggregation processing on the execution results of multiple tasks to obtain the final output.
[0046] The above description of the disclosed embodiments enables those skilled in the art to implement or use the present invention. Various modifications to these embodiments will be apparent to those skilled in the art, and the general principles defined herein can be implemented in other embodiments without departing from the spirit or scope of the present invention. Therefore, the present invention will not be limited to the embodiments shown herein, but rather to the widest scope consistent with the principles and novel features disclosed herein.
Claims
1. A method for implementing serial execution of a task flow, characterized in that, It includes the following steps: S1. Add task nodes and task links to construct a task flow chart; S2. Use the environmental information and parameters required for task execution as the execution context and initialize it; S3. When changes need to be made to the task, update the task flow chart; S4. Schedule and execute tasks according to the task flow chart, and update the execution context based on the execution results.
2. The method for implementing serial execution of a task flow according to claim 1, characterized in that, The specific steps of step S1 are as follows: S11. Determine the task attributes of the task nodes to be executed, where the task attributes include task name, task function, and unique identifier; S12. Add each task node and establish the corresponding relationship between the task node and the task attributes to complete the creation of the task node; S13. Determine two task nodes with an execution order, establish a task link between them, and define the task link attributes; the task link attributes include source task, target task, and execution condition; S14. Define the source task and the target task according to the execution order, and set the execution condition according to whether the target task is executed to complete the creation of the task link.
3. The method for implementing serial execution of a task flow according to claim 2, wherein The specific steps of step S2 are as follows: S21. Set the execution context required for task execution, including global parameters, task result set, and current task information; S22. Create a new execution context object and initialize the input parameters and environmental parameters that need to be set in the global parameters.
4. The method for implementing serial execution of a task flow according to claim 3, wherein The specific steps of step S3 are as follows: S31. Determine whether changes need to be made to the task; If yes, go to step S32; If no, go to step S4; S32. Change the task nodes and task links that need to be changed and update the task flow chart.
5. The method for implementing serial execution of a task flow according to claim 4, wherein The specific steps of step S32 are as follows: S321. Determine whether the task nodes need to be changed; If yes, go to step S322; If no, go to step S323; S322. Add new task nodes and their task attributes according to the requirements, delete existing task nodes and their task attributes, and change the task attributes of existing task nodes; S323. Determine whether the task links need to be changed; If yes, go to step S324; If no, go to step S4; S324. Establish new task links according to the requirements, add task link attributes, delete existing task links, and change the task attributes of existing task links; S325. Update the task flow chart according to the changes of the task nodes and task links.
6. The method for implementing serial execution of a task flow according to claim 5, wherein The specific steps of step S4 are as follows: S41. Convert the task flow chart into an executable task sequence; S42. Determine the set of task nodes to which the next task to be executed belongs according to the execution status of the current task from the task sequence to obtain candidate tasks; S43. Determine the task type of the current task; If it is a synchronous task, go to step S44; If it is an asynchronous task, go to step S45; S44. Directly call the task function corresponding to the task node of the current task to obtain the execution result and go to step S46; S45. Wait for the completion after executing the task function corresponding to the task node of the current task and obtain the execution result; S46. Obtain the execution conditions in the set of task nodes to which the current task and the next task to be executed belong, make a judgment in combination with the execution result, search for the next task to be executed and determine whether it is found; If yes, go to step S47; If no, go to step S48; S47. Save the execution result of the current task to the execution context, take the next task to be executed as the current task, and return to step S3; S48. Aggregate and output the execution results of each task that has completed execution, and clean up the execution context as needed.
7. The method for implementing serial execution of a task flow according to claim 6, wherein The specific steps of step S46 are as follows: S461. Obtain each candidate task in the set of task nodes to which the next task to be executed belongs; S462. Obtain the execution conditions of the task links between the task node to which the current task belongs and each candidate task; S463. Convert the conditional expressions in the form of strings in each execution condition into executable conditional functions; S464. Select an executable conditional function according to the execution result of the current task and execute it to search for the next task to be executed; If there is a next task to be executed, go to step S47; If there is no next task to be executed, go to step S48; The specific steps of step S47 are as follows: S471. Save the task name and start time of the current task to the current task information in the execution context; S472. Save the execution result of the current task to the task result set in the execution context; S474. Take the next task to be executed as the current task and return to step S3.
8. The method for implementing serial execution of a task flow according to claim 6, wherein The specific steps of step S48 are as follows: S481. Obtain the execution results of each task and perform aggregation processing as required to obtain the final output; S482. Determine whether a query request for a single task is received; If yes, go to step S483; If no, go to step S484; S483. Obtain the execution result of the task to be queried from the execution context and return it to the user; S484. Output the aggregated final output; S485. Clean up the execution context that is no longer needed.
9. A system for implementing serial execution of a task flow, characterized in that, Including: Task node management module, which adds, deletes, and manages task nodes in the task flow chart; Task link management module, which adds, deletes, and manages task links in the task flow chart; Context management module, which creates and maintains the execution context required for task execution; Task scheduling module, which schedules task execution according to the task flow chart; Task execution module, which executes the task function corresponding to the task and processes it according to the task type; Condition evaluation module, which evaluates the execution conditions of task links to determine the next task to be executed; Result management module, which stores and manages task execution results.
10. The system for implementing serial execution of a task flow according to claim 9, wherein The task management module includes: Task node creation unit, which creates task nodes according to the provided task name and task function, and sets a unique identifier; Task node update unit, which modifies the task attributes or task functions of existing task nodes; Task node deletion unit, which removes the specified task node from the task flow chart; The task link management module includes: A task link creation unit that creates a task link between two task nodes according to the execution order and defines the task link attributes; A task link update unit that modifies the attributes of an existing task link; A task link deletion unit that removes a specified task link from the task flow chart; The context management module includes: A context initialization unit that creates a new execution context and sets the initial parameters for task execution; A context update unit that updates the data in the execution context during task execution; A context cleanup unit that cleans up the execution context that is no longer needed after all tasks have been executed; The task scheduling module includes: A task serialization unit that converts the task flow chart into an executable task sequence; A task dispatching unit that determines the set of task nodes to which the next task to be executed belongs based on the execution status of the current task, obtaining candidate tasks; The task execution module includes: A synchronous task execution unit that directly calls the task function for a synchronous task to obtain the execution result; An asynchronous task execution unit that waits for completion after executing the task function for an asynchronous task and then obtains the execution result; An error handling unit that catches and handles exceptions that occur during the execution of the task function; The condition evaluation module includes: A condition parsing unit that converts the conditional expression in string form in the execution condition into an executable conditional function; A condition execution unit that selects an executable conditional function based on the execution result of the current task and executes it to find the next task to be executed; A condition modification unit that dynamically modifies or adds execution conditions during task execution; The result management module includes: A result storage unit that saves the execution result of each task to the execution context; A result query unit that provides an interface to query the execution result of a single task; A result aggregation unit that aggregates the execution results of multiple tasks to obtain the final output.