Multi-task scheduling method and device

By obtaining the Action function in the task to be executed automatically determines the task type and generating a traverser to execute tasks, the problem of lengthy and maintenance difficulties in the existing technology is solved, and the maintainability and simplicity of the code is improved.

CN119847711APending Publication Date: 2025-04-18竞技世界(北京)网络技术有限公司
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510020302.3
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-01-07
Publication Date
2025-04-18

AI Technical Summary

Technical Problem

The prior art requires writing a lot of extra code to distinguish task categories when scheduling, resulting in lengthy code and difficulty in maintaining.

Method used

By obtaining the Action function in the task to be executed, the task type is automatically determined, and the traverser execution task is generated based on the Action execution function, simplifying the complexity of task scheduling.

Benefits of technology

It avoids explicitly writing a large amount of judgment and process control code, and improves the maintainability and simplicity of code engineering.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119847711A_ABST
    Figure CN119847711A_ABST
Patent Text Reader

Abstract

The invention discloses a multi-task scheduling method and device, and the method comprises the steps: obtaining an Action function in a to-be-executed task when the to-be-executed task is received; determining a task type of the to-be-executed task according to an Action function in the to-be-executed task; calling an Action execution function according to the task type of the to-be-executed task; and generating a traversal device based on the Action execution function, and executing the to-be-executed task by using the traversal device. The type and execution logic of the task are determined by obtaining the Action function in the to-be-executed task, and explicit writing of a large number of judgment and process control codes is avoided. The types of the tasks are automatically determined through the Action function, and the execution process is processed in sequence through the generated traversal device, so that the task scheduling complexity is simplified, and the maintainability of code engineering is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of computer technology, and in particular to a multi-task scheduling method and device. Background Art

[0002] Scheduling can increase the processing capacity of tasks by properly allocating central processing unit (CPU) time and other resources.

[0003] Currently, when scheduling tasks, it is necessary to distinguish the categories of tasks and perform different scheduling according to the categories. However, distinguishing task categories usually requires writing a lot of additional code, which not only leads to lengthy code and makes it difficult to highlight the core logic, but also if the task category changes, the lengthy code needs to be updated accordingly, making it difficult to maintain the entire project.

[0004] Therefore, how to improve the maintainability of the project has become an urgent problem to be solved in this field. Summary of the invention

[0005] The present application provides a multi-task scheduling method and device, the purpose of which is to improve the maintainability of the project.

[0006] In order to achieve the above objectives, this application provides the following technical solutions:

[0007] A multi-task scheduling method, comprising:

[0008] When receiving a task to be executed, obtaining the Action function in the task to be executed;

[0009] Determine the task type of the task to be executed according to the Action function in the task to be executed;

[0010] Calling the Action execution function according to the task type of the task to be executed;

[0011] A traversal is generated based on the Action execution function, and the traversal is used to execute the task to be executed.

[0012] Optionally, determining the task type of the task to be executed according to the Action function in the task to be executed includes:

[0013] When the Action function in the task to be executed is TaskManager.Action(Task), determining that the task type of the task to be executed is a subtask;

[0014] When the Action function in the task to be executed is TaskManager.Action(GroupTask), determining that the task type of the task to be executed is a group task;

[0015] When the Action function in the task to be executed is TaskManager.Action(GeneralTask), it is determined that the task type of the task to be executed is a root task.

[0016] Optionally, the using the traverser to execute the task to be executed includes:

[0017] When the task to be executed is a root task or a group task, all tasks under the task to be executed are traversed and executed by using the traverser;

[0018] When the task to be executed is a subtask, the traverser is used to execute the task to be executed.

[0019] Optionally, the using the traverser to execute the task to be executed includes:

[0020] Obtaining the task flow of the task to be executed;

[0021] Execute the task to be executed according to the task flow of the task to be executed.

[0022] Optionally, also include:

[0023] When the task to be executed is completed, the trigger logic is executed to feedback prompt information of task completion.

[0024] A multi-task scheduling device, comprising:

[0025] An acquisition unit, configured to acquire an Action function in a task to be executed when receiving the task to be executed;

[0026] A determination unit, used to determine the task type of the task to be executed according to the Action function in the task to be executed;

[0027] A calling unit, used for calling an Action execution function according to the task type of the task to be executed;

[0028] An execution unit is used to generate a traversal based on the Action execution function, and use the traversal to execute the task to be executed.

[0029] Optionally, the determining unit is specifically configured to:

[0030] When the Action function in the task to be executed is TaskManager.Action(Task), determining that the task type of the task to be executed is a subtask;

[0031] When the Action function in the task to be executed is TaskManager.Action(GroupTask), determining that the task type of the task to be executed is a group task;

[0032] When the Action function in the task to be executed is TaskManager.Action(GeneralTask), it is determined that the task type of the task to be executed is a root task.

[0033] Optionally, the execution unit is specifically used for:

[0034] When the task to be executed is a root task or a group task, all tasks under the task to be executed are traversed and executed by using the traverser;

[0035] When the task to be executed is a subtask, the traverser is used to execute the task to be executed.

[0036] Optionally, the execution unit is specifically used for:

[0037] Obtaining the task flow of the task to be executed;

[0038] Execute the task to be executed according to the task flow of the task to be executed.

[0039] Optionally, the execution unit is specifically used for:

[0040] The feedback unit is used to execute the trigger logic after the to-be-executed task is completed, so as to feedback prompt information of task completion.

[0041] The technical solution provided by the present application, when receiving a task to be executed, obtains the Action function in the task to be executed; determines the task type of the task to be executed according to the Action function in the task to be executed; calls the Action execution function according to the task type of the task to be executed; generates a traverser based on the Action execution function, and uses the traverser to execute the task to be executed. By obtaining the Action function in the task to be executed to determine the type and execution logic of the task, it avoids explicitly writing a large amount of judgment and process control code. The type of task is automatically determined by the Action function, and the execution process is processed sequentially through the generated traverser, which simplifies the complexity of task scheduling and improves the maintainability of code engineering. BRIEF DESCRIPTION OF THE DRAWINGS

[0042] In order to more clearly illustrate the embodiments of the present application 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 of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.

[0043] Figure 1 A flowchart of a multi-task scheduling method provided in an embodiment of the present application;

[0044] Figure 2 A schematic diagram of a task relationship provided for an embodiment of the present application;

[0045] Figure 3 A flowchart of a method for executing a task to be executed provided in an embodiment of the present application;

[0046] Figure 4 A one-step and two-step flow chart provided for embodiments of the present application;

[0047] Figure 5 A multi-step flow chart provided for an embodiment of the present application;

[0048] Figure 6 A mind map for task management provided in an embodiment of the present application;

[0049] Figure 7 A schematic diagram of the architecture of a multi-task scheduling device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0050] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.

[0051] In this application, the terms "comprises", "comprising" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device comprising a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, an element defined by the sentence "comprising a ..." does not exclude the presence of other identical elements in the process, method, article or device comprising the element.

[0052] like Figure 1As shown, it is a flowchart of a multi-task scheduling method provided in an embodiment of the present application, which is applied to a task manager and includes the following steps:

[0053] S101: When a task to be executed is received, an Action function in the task to be executed is obtained.

[0054] When a task to be executed is received, the Action function in the task to be executed is obtained to execute corresponding logic according to the Action function in the task to be executed.

[0055] S102: Determine the task type of the task to be executed according to the Action function in the task to be executed.

[0056] The types of tasks to be executed include but are not limited to: subtasks, group tasks, and root tasks.

[0057] It can be understood that a plurality of subtasks form a group, constituting a group task, and a plurality of group tasks form a root task.

[0058] Optionally, in another embodiment of the present application, the specific implementation of step S102 includes:

[0059] When the Action function in the task to be executed is TaskManager.Action(Task), it is determined that the task type of the task to be executed is a subtask.

[0060] When the Action function in the task to be executed is TaskManager.Action(GroupTask), it is determined that the task type of the task to be executed is a group task.

[0061] When the Action function in the task to be executed is TaskManager.Action(GeneralTask), it is determined that the task type of the task to be executed is a root task.

[0062] It should be noted that the task manager (TaskManager) will perform task-related operations to start, shut down, and restart tasks. The execution unit can be a group task or a single subtask. Group tasks can also be nested, and the root task is the vertex of all tasks. The above relationship can be seen in the URL graph. Figure 2 .

[0063] For example, according to the above relationship, the execution scenario is:

[0064] GeneralTask

[0065] -GroupTask A

[0066] -GroupTask D

[0067] -Task D1

[0068] -Task D2

[0069] -Task H

[0070] -GroupTask B

[0071] -Task E

[0072] -Task F

[0073] -GroupTask C

[0074] -Task G.

[0075] In the above execution scenario, GeneralTask ​​represents the execution of all tasks, GroupTask A represents the execution of all tasks under group task D (Task D1, Task D2, Task H), and Task H represents the execution of subtask H only.

[0076] It should be noted that the task class (Task class) and its subclasses in the task manager should set the behaviors responsible for executing tasks (such as the task execution methods) to protected or private, so that external code cannot directly call these methods, thereby ensuring that the control of task execution can only be performed in a specific way. Then, by declaring the task manager class as a friend class of the Task class, the TaskManager can manage and control the execution of tasks without exposing these task execution methods.

[0077] S103: Calling an Action execution function according to the task type of the task to be executed.

[0078] Optionally, you can use function overloading to implement functions that execute different logics based on the task type. Different types of tasks can have different versions of Action functions, and C++ function overloading will determine which version of the Action function to execute based on the task type to be executed.

[0079] For example, if the task type of the task to be executed is a group task, the Action execution function called is GroupTask::Action.

[0080] It should be noted that the execution of a task is determined based on its type. A group task will have its own Action call function, and the specific tasks under the group task will have their own execution logic. When an Action is called, the group task will handle its own execution and call the Action execution function of the contained specific tasks, and each specific task will perform its own specific behavior.

[0081] S104: Generate a traversal based on the Action execution function, and use the traversal to execute the task to be executed.

[0082] For example, if the Action execution function is GroupTask::Action, then the traverser generated based on the Action execution function is an instance of the ActionTraverse class.

[0083] It should be noted that different Action execution functions indicate different task types for the tasks to be executed, and different traversers may be generated by different task types.

[0084] Specifically, the process from step S101 to step S104 can be implemented by code, and the specific expression of the code is:

[0085] bool TaskManager::Action(Task*pTask,ActionEnum action){

[0086] if(!pTask){

[0087] TASKLOGGER_WARN(ENC_STR_T("TaskManager gets nullptr task"));

[0088] return false;

[0089] }

[0090] bool bOK=false;

[0091] try{

[0092] bOK=pTask->Action(action);

[0093] }

[0094] }

[0095] bool GroupTask::Action(ActionEnum action){

[0096] return ActionTraverser(this->CreateIterator(),action).Perform();;

[0097] }.

[0098] Optionally, in another embodiment of the present application, the specific implementation of using the traverser to execute the task to be executed in step S104 includes process A1 to process A2:

[0099] A1: When the task to be executed is a root task or a group task, use the traverser to traverse all tasks under the task to be executed and execute them.

[0100] It can be understood that when the task to be executed is a root task, one or more group tasks constituting the root task are traversed, and then all subtasks constituting the one or more group tasks are traversed and executed; when the task to be executed is a group task, all subtasks constituting the group task are traversed and executed using a traverser.

[0101] It should be noted that the root task itself is also a task, and so is the group task, that is, the root task and the group task are also the basic units to be scheduled. This design forms a combination.

[0102] A2: When the task to be executed is a subtask, the traverser is used to execute the task to be executed.

[0103] It is understandable that when the task to be executed is a subtask, the subtask is a single task, and at this time, it is only necessary to use the traverser to execute the subtask.

[0104] Specifically, the process from process A1 to process A2 can be implemented through code, and the specific expression of the code is as follows:

[0105] / / This method is used to execute tasks. It has only one parameter, which is the task to be executed.

[0106] TaskManager::Action(Task*task);

[0107] auto taskManager=TaskManager::Instance();

[0108] Task task1,task2,task3;

[0109] GroupTask groupTask1;

[0110] groupTask1.AddTask(task1,task2,task3);

[0111] Task task4,task5;

[0112] GroupTask groupTask2;

[0113] groupTask1.AddTask(task4,task5);

[0114] GeneralTaskgeneralTask;

[0115] generalTask.AddTask(groupTask1,groupTask2);

[0116] taskManager.Action(task1);

[0117] taskManager.Action(groupTask1);

[0118] taskManager.Action(generalTask).

[0119] In the above code, TaskManager::Action is used to execute tasks. The function parameter only needs to put in one task. According to the design principle, the Action execution function does not need to know what kind of task the parameter passed in is, which saves the irrelevant code logic of task type checking and makes the entire design structure very clear. After that, some tasks, group tasks, and root tasks are defined in the code, and then scheduled with the Action execution function. If a group task is executed, the Action execution function will execute all tasks under the group task.

[0120] Optionally, in another embodiment of the present application, the specific implementation of process A2 is as follows: Figure 3 As shown, the following steps are included:

[0121] S301: Obtain the task flow of the task to be executed.

[0122] Among them, the task flow of the task to be executed includes one step, two steps and multiple steps.

[0123] The task flow is a one-step and two-step flowchart, such as Figure 4 As shown. Figure 4In the , tasks have two basic states, creation and completion. After a task is created, it is in the creation state. If you stop the task in this state, the task state will not change; if you execute the task, it will be converted to the completion state. Execution in the completion state will not change the task state because the task has been completed; if you stop the task in the completion state, the task will return to the creation state. The difference between one-step and two-step here is that in a two-step task flow, changes are made in a certain step (for example, modifying or entering data), and the rollback function provides a way to restore or undo these changes, thereby "stopping" or "rolling back" to the previous state; while the stop action of a one-step task flow is just a task state change, and does not include the rollback function.

[0124] The task flow is a multi-step flow chart, such as Figure 5 As shown. Figure 5 It contains a state machine, which is implemented by a strategy class. Tasks can implement different scheduling logics by selecting different strategy classes. For example, state 1 and state 2 are just different states, but the definition of the state is implemented by the strategy class itself.

[0125] For example, if a student is going home from school, then state 1 of the state machine is walking to the school gate, state 2 is walking to intersection A, and the final state N is walking home from intersection X. Since students can have different paths and ways to go home, such as taking a shortcut or taking the bus home, there will be multiple state machines, and the task can choose according to its own situation.

[0126] S302: Execute the task to be executed according to the task flow of the task to be executed.

[0127] It is understandable that executing the tasks to be executed according to the predetermined task flow means completing each task step in sequence according to the pre-designed order. This approach can avoid developers from explicitly writing a large amount of task status judgment and next step execution code, thereby making the functional code more concise and compact, highlighting the engineering design structure, and improving the maintainability of the project.

[0128] Optionally, after step S104, it is also necessary to feedback whether the task is completed. Separating the task completion from the feedback logic can reduce unnecessary interference and conflicts during task execution, thereby improving stability. Therefore, another embodiment of the present application provides an information feedback method, including:

[0129] When the pending task is completed, the trigger logic is executed to feedback the prompt information of task completion.

[0130] Optionally, a pop-up window or a message may be sent to provide feedback indicating that the task has been completed.

[0131] It should be noted that each task to be executed carries a trigger. When the execution result of the task to be executed meets the expectation, the trigger logic is executed. The expectation of the execution result here is defined by the task itself. For example, if the task checks the process environment and finds malware (defined conditions), the task executes the trigger logic. There are many types of trigger logic, such as closing the process, reporting an exception, etc., and the selection method is also selected by the task itself.

[0132] For a better explanation of the above, see Figure 6 , shows a mind map of task management, including elements, internal iterators and task scheduling. Elements include tasks and task managers, tasks and actions. Root tasks include group tasks and subtasks (i.e., task 1 and task 2); actions include creation, execution, stop and restart; task managers include creation of tasks, stop of tasks and restart of tasks, etc. Internal iterators include iteration abstract classes and traversers; task scheduling includes task states and schedulers.

[0133] In summary, by obtaining the Action function in the task to be executed to determine the type and execution logic of the task, it is possible to avoid explicitly writing a large amount of judgment and process control code. The type of task is automatically determined by the Action function, and the execution process is processed sequentially through the generated traverser, which simplifies the complexity of task scheduling and improves the maintainability of code engineering.

[0134] like Figure 7 , which is a schematic diagram of the architecture of a multi-task scheduling device provided in an embodiment of the present application, the device includes: an acquisition unit 100, a determination unit 200, a calling unit 300 and an execution unit 400.

[0135] The acquisition unit 100 is used to acquire the Action function in the task to be executed when receiving the task to be executed.

[0136] The determination unit 200 is used to determine the task type of the task to be executed according to the Action function in the task to be executed.

[0137] The determination unit 200 is specifically used for: when the Action function in the task to be executed is TaskManager.Action(Task), determining that the task type of the task to be executed is a subtask; when the Action function in the task to be executed is TaskManager.Action(GroupTask), determining that the task type of the task to be executed is a group task; when the Action function in the task to be executed is TaskManager.Action(GeneralTask), determining that the task type of the task to be executed is a root task.

[0138] The calling unit 300 is used to call the Action execution function according to the task type of the task to be executed.

[0139] The execution unit 400 is used to generate a traversal based on the Action execution function, and use the traversal to execute the task to be executed.

[0140] The execution unit 400 is specifically used for: when the task to be executed is a root task or a group task, using a traverser to traverse all tasks under the task to be executed and execute them; when the task to be executed is a subtask, using a traverser to execute the task to be executed.

[0141] The execution unit 400 is specifically used for: obtaining a task flow of the task to be executed; and executing the task to be executed according to the task flow of the task to be executed.

[0142] In summary, by obtaining the Action function in the task to be executed to determine the type and execution logic of the task, it is possible to avoid explicitly writing a large amount of judgment and process control code. The type of task is automatically determined by the Action function, and the execution process is processed sequentially through the generated traverser, which simplifies the complexity of task scheduling and improves the maintainability of code engineering.

[0143] Preferably, combined Figure 7 The content shown, the device also includes: a feedback unit, which is used to execute trigger logic after the task to be executed is completed to feedback prompt information of task completion.

[0144] In this specification, each embodiment is described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the embodiments can refer to each other, and each embodiment focuses on the differences from other embodiments. In particular, for the system or system embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can refer to the partial description of the method embodiment. The system and system embodiments described above are merely schematic, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of this embodiment. Ordinary technicians in this field can understand and implement it without paying creative work.

[0145] Professionals may further appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of the two. In order to clearly illustrate the interchangeability of hardware and software, the composition and steps of each example have been generally described in the above description according to function. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professionals and technicians may use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of the present invention.

[0146] The above description of the disclosed embodiments enables those skilled in the art to implement or use the present application. Various modifications to these embodiments will be apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the present application. Therefore, the present application will not be limited to the embodiments shown herein, but will conform to the widest scope consistent with the principles and novel features disclosed herein.

Claims

1. A multi-task scheduling method, characterized in that: include: When receiving a task to be executed, obtaining the Action function in the task to be executed; Determine the task type of the task to be executed according to the Action function in the task to be executed; Calling the Action execution function according to the task type of the task to be executed; A traversal is generated based on the Action execution function, and the traversal is used to execute the task to be executed.

2. The method according to claim 1, characterized in that Determine the task type of the task to be executed according to the Action function in the task to be executed, including: When the Action function in the task to be executed is TaskManager.Action(Task), determining that the task type of the task to be executed is a subtask; When the Action function in the task to be executed is TaskManager.Action(GroupTask), determining that the task type of the task to be executed is a group task; When the Action function in the task to be executed is TaskManager.Action(GeneralTask), it is determined that the task type of the task to be executed is a root task.

3. The method according to claim 1, characterized in that The using the traverser to execute the task to be executed includes: When the task to be executed is a root task or a group task, all tasks under the task to be executed are traversed and executed by using the traverser; When the task to be executed is a subtask, the traverser is used to execute the task to be executed.

4. The method according to claim 1, characterized in that: The using the traverser to execute the task to be executed includes: Obtaining the task flow of the task to be executed; Execute the task to be executed according to the task flow of the task to be executed.

5. The method according to claim 1, characterized in that Also includes: When the task to be executed is completed, the trigger logic is executed to feedback prompt information of task completion.

6. A multi-task scheduling device, characterized in that: include: An acquisition unit, configured to acquire an Action function in a task to be executed when receiving the task to be executed; A determination unit, used to determine the task type of the task to be executed according to the Action function in the task to be executed; A calling unit, used for calling an Action execution function according to the task type of the task to be executed; An execution unit is used to generate a traversal based on the Action execution function, and use the traversal to execute the task to be executed.

7. The device according to claim 6, characterized in that The determining unit is specifically used for: When the Action function in the task to be executed is TaskManager.Action(Task), determining that the task type of the task to be executed is a subtask; When the Action function in the task to be executed is TaskManager.Action(GroupTask), determining that the task type of the task to be executed is a group task; When the Action function in the task to be executed is TaskManager.Action(GeneralTask), it is determined that the task type of the task to be executed is a root task.

8. The device according to claim 6, characterized in that The execution unit is specifically used for: When the task to be executed is a root task or a group task, all tasks under the task to be executed are traversed and executed by using the traverser; When the task to be executed is a subtask, the traverser is used to execute the task to be executed.

9. The device according to claim 6, characterized in that The execution unit is specifically used for: Obtaining the task flow of the task to be executed; Execute the task to be executed according to the task flow of the task to be executed.

10. The device according to claim 6, characterized in that The execution unit is specifically used for: The feedback unit is used to execute the trigger logic after the task to be executed is completed to feedback prompt information of task completion.