A task execution method and device based on a finite state machine
By using a task execution method based on finite state machines, the current state and execution result of a task are obtained, the state is updated, and the task is executed. This solves the problem of high business coupling in task management and enables unified management and independent execution of tasks of multiple domain types.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- ZHEJIANG LANZHUO IND INTERNET INFORMATION TECH CO LTD
- Filing Date
- 2022-12-09
- Publication Date
- 2026-05-01
AI Technical Summary
Existing technologies have high business coupling in task management, resulting in poor versatility and an inability to be applied to the unified management of multiple tasks with no dependencies, especially in multi-domain types of tasks.
A task execution method based on finite state machines is adopted. By obtaining the current state and execution result of the task, updating the state, and executing the task according to the association relationship of the finite state machine, the business coupling is reduced, which is suitable for unified management of tasks of multiple domain types.
It enables independent execution of tasks of different domain types, reduces business coupling, is suitable for unified management of tasks of multiple domain types, and improves the versatility of task management.
Smart Images

Figure CN115858052B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of task management technology, and in particular to a method and apparatus for task execution based on a finite state machine. Background Technology
[0002] With the development of computer technology, task management has gradually become an indispensable part of various fields and systems. Effective task management methods can ensure that tasks are executed in an orderly manner.
[0003] In existing technologies, task management is usually based on workflow. A task flowchart is built by setting dependencies between tasks, and the next task is executed after the current task is completed, according to the task flowchart.
[0004] However, existing technologies typically manage tasks with dependencies, resulting in high business coupling and poor versatility. This makes them unsuitable for the unified management of multiple tasks without dependencies, and thus cannot meet the unified management needs of tasks across multiple domains. Summary of the Invention
[0005] To address the aforementioned issues, this application provides a task execution method and apparatus based on a finite state machine.
[0006] The embodiments of this application disclose the following technical solutions:
[0007] This application provides a task execution method based on a finite state machine, including:
[0008] Determine the target task based on the multiple domain types of the multiple tasks in progress;
[0009] Perform the target task;
[0010] During the execution of the target task, the current state of the target task, the execution result of the current state, and the finite state machine corresponding to the domain type of the target task are obtained; the finite state machine represents the association relationship between multiple states;
[0011] Based on the current state of the target task, the execution result, and the finite state machine, update the current state to obtain the updated state;
[0012] If the updated state is a non-final state, the updated state is determined as the current state of the target task, and the target task continues to be executed; if the updated state is a final state, the target task is completed.
[0013] Furthermore, determining the target task based on multiple domain types of multiple tasks in execution includes:
[0014] Obtain the domain type of the task to be executed and the task concurrency corresponding to the domain type of the task to be executed;
[0015] Based on the multiple domain types of multiple tasks in execution, query the number of tasks belonging to the domain type of the task to be executed among the multiple tasks to obtain the number of tasks;
[0016] If the number of tasks is less than the task concurrency, the task to be executed is determined to be the target task.
[0017] Furthermore, it also includes:
[0018] If the number of tasks is detected to be greater than or equal to the task concurrency, the tasks to be executed are added to the waiting queue corresponding to the domain type of the tasks to be executed.
[0019] Further, the step of adding the tasks to be executed to the waiting queue corresponding to the domain type of the tasks to be executed if the number of tasks is detected to be greater than or equal to the task concurrency includes:
[0020] If the number of tasks is detected to be greater than or equal to the task concurrency, and there is a waiting queue corresponding to the domain type of the task to be executed, the task to be executed is added to the waiting queue corresponding to the domain type of the task to be executed.
[0021] If there is no waiting queue corresponding to the domain type of the task to be executed, create a waiting queue corresponding to the domain type of the task to be executed.
[0022] Add the task to be executed to the waiting queue corresponding to the domain type of the task to be executed.
[0023] Furthermore, if the updated state is a final state, after completing the target task, the process further includes:
[0024] If the waiting queue corresponding to the domain type of the target task is not empty, determine the next target task in the waiting queue;
[0025] If the waiting queue corresponding to the domain type of the target task is empty, then the task execution will end.
[0026] Further, if the waiting queue corresponding to the domain type of the target task is not empty, determining the next target task in the waiting queue includes:
[0027] The next target task is determined based on the arrival order and / or priority of multiple tasks in the waiting queue.
[0028] Furthermore, it also includes:
[0029] During the execution of the target task, the current status of the target task and the execution result are displayed.
[0030] This application also provides a task execution device based on a finite state machine, including:
[0031] The module comprises a first determination module, an execution module, an acquisition module, a obtaining module, and a second determination module;
[0032] The first determining module is used to determine the target task based on multiple domain types of multiple tasks in execution;
[0033] The execution module is used to execute the target task;
[0034] The acquisition module is used to acquire, during the execution of the target task, the current state of the target task, the execution result of the current state, and the finite state machine corresponding to the domain type of the target task; the finite state machine represents the association relationship between multiple states.
[0035] The obtaining module is used to update the current state based on the current state of the target task, the execution result, and the finite state machine, and obtain the updated state.
[0036] The second determining module is used to determine the updated state as the current state of the target task and continue to execute the target task if the updated state is a non-final state; and to complete the execution of the target task if the updated state is a final state.
[0037] Further, the first determining module includes:
[0038] Acquisition unit, obtaining unit, and determination unit;
[0039] The acquisition unit is used to acquire the domain type of the task to be executed and the task concurrency corresponding to the domain type of the task to be executed;
[0040] The obtaining unit is used to query the number of tasks belonging to the domain type of the task to be executed among the multiple tasks in execution, based on the multiple domain types of the multiple tasks in execution, and obtain the number of tasks.
[0041] The determining unit is configured to determine the task to be executed as the target task if it detects that the number of tasks is less than the task concurrency.
[0042] Furthermore, it also includes:
[0043] Add a module;
[0044] The adding module is used to add the task to be executed to the waiting queue corresponding to the domain type of the task if the number of tasks is detected to be greater than or equal to the task concurrency.
[0045] Furthermore, the added module includes:
[0046] The first addition unit, the creation unit, and the second addition unit;
[0047] The first adding unit is used to add the task to be executed to the waiting queue corresponding to the domain type of the task if the number of tasks is detected to be greater than or equal to the task concurrency, when there is a waiting queue corresponding to the domain type of the task to be executed.
[0048] The creation unit is used to create a waiting queue corresponding to the domain type of the task to be executed when there is no waiting queue corresponding to the domain type of the task to be executed.
[0049] The second adding unit is used to add the task to be executed to the waiting queue corresponding to the domain type of the task to be executed.
[0050] Furthermore, it also includes:
[0051] The third module determines the module and the closing module;
[0052] The third determining module is used to determine the next target task in the waiting queue if the waiting queue corresponding to the domain type of the target task is not empty;
[0053] The termination module is used to terminate task execution if the waiting queue corresponding to the domain type of the target task is empty.
[0054] Furthermore, the third determining module is used for:
[0055] If the waiting queue corresponding to the domain type of the target task is not empty, the next target task is determined according to the arrival order and / or priority of multiple tasks in the waiting queue.
[0056] Furthermore, it also includes:
[0057] Display module;
[0058] The display module is used to display the current status of the target task and the execution result during the execution of the target task.
[0059] This application embodiment also provides a computer device, the computer device including a processor and a memory:
[0060] The memory is used to store program code and transmit the program code to the processor;
[0061] The processor is used to execute the steps of a task execution method based on a finite state machine as described above, according to the instructions in the program code.
[0062] This application also provides a computer-readable storage medium storing a computer program, which, when executed by a processor, implements the steps of a task execution method based on a finite state machine as described above.
[0063] Compared with the prior art, this application has the following beneficial effects:
[0064] This application embodiment updates the current state based on the current state of the target task, the execution result, and the finite state machine to obtain an updated state. If the updated state is a non-final state, it is determined as the current state of the target task, and the target task continues to be executed. If the updated state is a final state, the target task is completed. In this application embodiment, different domain types of tasks correspond to different finite state machines. Regardless of the domain type of the target task, only the current state, execution result, and the finite state machine corresponding to the domain type of the target task need to be used to execute the corresponding target task, reducing business coupling and making it suitable for unified management of tasks of multiple domain types. Attached Figure Description
[0065] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0066] Figure 1 A flowchart illustrating a task execution method provided in this application embodiment;
[0067] Figure 2 A schematic diagram of a multi-domain task management model provided in this application embodiment;
[0068] Figure 3 A simplified diagram of task state transitions provided in an embodiment of this application;
[0069] Figure 4 A state transition diagram for an installation component task provided in an embodiment of this application;
[0070] Figure 5This is a schematic diagram of a task execution device provided in an embodiment of this application. Detailed Implementation
[0071] As described above, how to achieve unified management of tasks across multiple domains has become a technical problem that urgently needs to be solved by those skilled in the art.
[0072] Research has revealed that current technologies typically implement task management based on workflows. This involves constructing task flowcharts by setting dependencies between tasks, and then executing the next task after the current one is completed, according to the flowchart. However, tasks managed in these existing technologies often have dependencies, resulting in high business coupling and poor versatility. This makes them unsuitable for the unified management of multiple tasks without dependencies, and thus cannot meet the unified management needs of tasks across multiple domains.
[0073] In this application embodiment, different domain types of tasks correspond to different finite state machines. Regardless of which domain type the target task belongs to, the corresponding target task only needs to be executed according to the current state of the target task, the execution result, and the finite state machine corresponding to the domain type of the target task. This reduces the business coupling and is suitable for the unified management of tasks of multiple domain types.
[0074] To enable those skilled in the art to better understand the present application, the technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present application, and not all embodiments. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without creative effort are within the scope of protection of the present application.
[0075] This application provides a task execution method based on a finite state machine, including steps 101 to 105, see [link to relevant documentation]. Figure 1 The figure is a flowchart of a task execution method provided in an embodiment of this application.
[0076] Step 101: Determine the target task based on the multiple domain types of the multiple tasks in progress.
[0077] Specifically, such as Figure 2As shown in the figure, this is a schematic diagram of a multi-domain task management model provided in an embodiment of this application. The task manager consists of three parts: a general task model, a task scheduling module, and a task pool. A general task model should include attributes such as the domain type of the task, the initial state of the task, and the concurrency of the task. It should be noted that the attributes included in the general task model can be derived according to actual needs. The domain type is indispensable because it is associated with the state in the state manager. The task scheduling module is used to ensure that tasks can be executed according to a certain scheduling strategy. The task pool is a globally unified thread pool. The state manager consists of a general state model, a state dictionary, and a set of state transition functions. A general state model usually includes attributes such as the basic state name, the domain type to which the state belongs, and the percentage corresponding to the state. The state dictionary is a set of states defined for each domain type or task, i.e., a set of state sets. The state transition function represents the input of a certain state of a finite state machine and a triggering event, and outputs a new state. The method provided in this embodiment of the application is applicable to multi-domain tasks. When multiple tasks of multiple domain types are executed simultaneously, there is no dependency between multiple tasks of different domain types, and therefore the execution strategies of tasks of different domain types are independent of each other. The target tasks to be performed are determined based on the multiple domain types of the multiple tasks in progress.
[0078] Step 102: Execute the target task.
[0079] Step 103: During the execution of the target task, obtain the current state of the target task, the execution result of the current state, and the finite state machine corresponding to the domain type of the target task; the finite state machine represents the association relationship between multiple states.
[0080] Specifically, a task of a domain type corresponds to a finite-state machine. A finite-state machine (FSM) is a mathematical computational model that represents a finite number of states and the behaviors such as transitions and actions between these states. An FSM can be represented as a quintuple, as shown in equation (1):
[0081] A=(Q, ∑, δ, q0,F) (1)
[0082] In the formula, Q represents a finite set of states, ∑ represents a finite set of input symbols or alphabets, δ is the state transition function, q0 represents the initial state, and F represents the final state or the set of accepting states.
[0083] For a target task of a given domain type, a corresponding set of states can be defined. This set contains all possible states that the target task can reach during execution, i.e., the finite set of states Q mentioned above. ∑ represents the set of triggering events during task execution, recording the transitions and actions between states. See also... Figure 3 This figure is a simplified diagram of task state transitions provided in an embodiment of this application. In the figure, Q = {S, W, U, I, V, F}, ∑ = {a1, a2, a3, a4, a5, a6}, q0 = S, F ∈ {V, F}, δ = {W×a1 = W, W×a2 = U, U×a3 = I, U×a4 = F, I×a5 = V, I×a6 = F}, where S, W, U, I, V, and F are all possible states that the target task can reach during execution; a1, a2, a3, a4, a5, and a6 are the execution results during task execution. The current state of the target task, the execution result of the current state, and the finite state machine corresponding to the domain type of the target task are obtained so that the updated state can be obtained subsequently.
[0084] Step 104: Update the current state based on the current state of the target task, the execution result, and the finite state machine to obtain the updated state.
[0085] Specifically, taking the target task as an example of an installation component task, see [link to relevant documentation]. Figure 4 This diagram illustrates the state transitions of a component installation task according to an embodiment of this application. The states of the component installation task include: Start, Waiting, Decompressing, Installing, Component Installed, and Component Installation Failed. The execution results for the Waiting state include "No execution thread obtained" and "Execution thread obtained." The execution results for the Decompressing state include "Decompress successful" and "Decompress failed." The execution results for the Installing state include "Installation successful" and "Installation failed." When the component installation task begins execution, it transitions from the Start state to Waiting. After obtaining an execution thread, the state is updated to "Decompressing." If no execution thread is obtained, it continues to wait. After successful decompression, the state is updated to "Installation." If decompression fails, the state is updated to "Component Installation Failed." If installation is successful, the state is updated to "Component Installed." If installation fails, the state is updated to "Component Installation Failed." When the current state of the target task is Waiting and the execution result is "Execution thread obtained," the current state is updated to the updated state, which is "Decompressing."
[0086] Step 105: If the updated state is a non-final state, determine the updated state as the current state of the target task and continue to execute the target task; if the updated state is a final state, complete the execution of the target task.
[0087] Specifically, taking the component installation task mentioned above as an example, the four states of "Starting," "Waiting," "Decompressing," and "Installing" are all non-final states; "Component Installed" and "Component Installation Failed" are final states. If the updated state is "Waiting," "Decompressing," or "Installing," the updated state is determined as the current state of the target task, and the target task continues to be executed. If the updated state is "Component Installed" or "Component Installation Failed," the target task is completed. For example, if the updated state is "Waiting," it is determined as the current state of the target task, and the target task continues to be executed. If an execution thread is obtained, the state is updated to "Decompressing." If no execution thread is obtained, the "Waiting" state continues. If the updated state is "Component Installed," the target task is completed.
[0088] Furthermore, step 101 can be implemented through steps 201 to 203.
[0089] Step 201: Obtain the domain type of the task to be executed and the task concurrency corresponding to the domain type of the task to be executed.
[0090] Specifically, different domain types may correspond to different task concurrency levels. The task concurrency level corresponding to a domain type refers to the number of tasks of that domain type that can be executed simultaneously.
[0091] Step 202: Based on the multiple domain types of the multiple tasks in execution, query the number of tasks belonging to the domain type of the task to be executed among the multiple tasks to obtain the number of tasks.
[0092] Step 203: If the number of tasks is less than the task concurrency, determine the task to be executed as the target task.
[0093] Specifically, if the number of tasks is less than the task concurrency, it means that the task to be executed can be executed immediately, and the task to be executed is determined to be the target task.
[0094] Furthermore, it also includes step 204.
[0095] Step 204: If the number of tasks is detected to be greater than or equal to the task concurrency, add the tasks to be executed to the waiting queue corresponding to the domain type of the tasks to be executed.
[0096] Specifically, if the number of tasks detected is greater than or equal to the task concurrency, it indicates that there is currently no free runtime space to execute the tasks to be executed. The tasks to be executed need to be added to the waiting queue corresponding to the domain type of the tasks to be executed, awaiting execution. The method provided in this application creates a corresponding waiting queue based on the domain type, enabling tasks of different domain types to operate independently and achieving effective management and control of tasks.
[0097] Furthermore, step 204 can be implemented through steps 301 to 303.
[0098] Step 301: If the number of tasks is detected to be greater than or equal to the task concurrency, when there is a waiting queue corresponding to the domain type of the task to be executed, add the task to be executed to the waiting queue corresponding to the domain type of the task to be executed.
[0099] Step 302: If there is no waiting queue corresponding to the domain type of the task to be executed, create a waiting queue corresponding to the domain type of the task to be executed.
[0100] Specifically, if there is no waiting queue corresponding to the domain type of the task to be executed, then a waiting queue corresponding to the domain type of the task to be executed is created so that the task to be executed can be added to the waiting queue corresponding to the domain type of the task to be executed.
[0101] Step 303: Add the task to be executed to the waiting queue corresponding to the domain type of the task to be executed.
[0102] Furthermore, the method provided in this application embodiment also includes steps 401 to 402.
[0103] Step 401: If the waiting queue corresponding to the domain type of the target task is not empty, determine the next target task in the waiting queue.
[0104] Specifically, if the waiting queue corresponding to the domain type of the target task is not empty, it means that there is a task waiting to be executed, and the next target task is determined in the waiting queue.
[0105] Furthermore, the next target task can be determined based on the arrival order and / or priority of multiple tasks in the waiting queue. For example, if there are multiple tasks with different priorities in the waiting queue, the task with the highest priority is determined as the next target task.
[0106] Step 402: If the waiting queue corresponding to the domain type of the target task is empty, then the task execution ends.
[0107] Specifically, if the waiting queue corresponding to the domain type of the target task is empty, it means that there are no pending tasks to be executed, and the task execution can be terminated.
[0108] Furthermore, the method provided in this application embodiment also includes the following steps:
[0109] During the execution of the target task, the current status of the target task and the execution result are displayed.
[0110] Specifically, by displaying the current status of the target task and the execution result of the current status, it is possible to detect the execution status and progress of the target task, grasp the execution trajectory of the target task, and promptly detect and handle any abnormalities that occur during the execution of the target task.
[0111] In summary, in the embodiments of this application, different domain types of tasks correspond to different finite state machines. Regardless of which domain type the target task belongs to, the target task can be executed according to the current state of the target task, the execution result, and the finite state machine corresponding to the domain type of the target task. This reduces the business coupling and is suitable for the unified management of tasks of multiple domain types.
[0112] This application also provides a task execution device based on a finite state machine, see [link to relevant documentation]. Figure 5 The figure is a schematic diagram of a task execution device provided in an embodiment of this application. Its specific implementation and the achieved technical effects are consistent with those described in the embodiments of the above method, and some details will not be repeated here.
[0113] A task execution device based on a finite state machine includes:
[0114] The module comprises a first determining module 1101, an execution module 1102, an acquisition module 1103, an obtaining module 1104, and a second determining module 1105;
[0115] The first determining module 1101 is used to determine the target task based on multiple domain types of multiple tasks in execution;
[0116] The execution module 1102 is used to execute the target task;
[0117] The acquisition module 1103 is used to acquire, during the execution of the target task, the current state of the target task, the execution result of the current state, and the finite state machine corresponding to the domain type of the target task; the finite state machine represents the association relationship between multiple states.
[0118] The obtaining module 1104 is used to update the current state based on the current state of the target task, the execution result, and the finite state machine, and obtain the updated state.
[0119] The second determining module 1105 is used to determine the updated state as the current state of the target task and continue to execute the target task if the updated state is a non-final state; and to complete the execution of the target task if the updated state is a final state.
[0120] Further, the first determining module 1101 includes:
[0121] Acquisition unit, obtaining unit, and determination unit;
[0122] The acquisition unit is used to acquire the domain type of the task to be executed and the task concurrency corresponding to the domain type of the task to be executed;
[0123] The obtaining unit is used to query the number of tasks belonging to the domain type of the task to be executed among the multiple tasks in execution, based on the multiple domain types of the multiple tasks in execution, and obtain the number of tasks.
[0124] The determining unit is configured to determine the task to be executed as the target task if it detects that the number of tasks is less than the task concurrency.
[0125] Furthermore, it also includes:
[0126] Add a module;
[0127] The adding module is used to add the task to be executed to the waiting queue corresponding to the domain type of the task if the number of tasks is detected to be greater than or equal to the task concurrency.
[0128] Furthermore, the added module includes:
[0129] The first addition unit, the creation unit, and the second addition unit;
[0130] The first adding unit is used to add the task to be executed to the waiting queue corresponding to the domain type of the task if the number of tasks is detected to be greater than or equal to the task concurrency, when there is a waiting queue corresponding to the domain type of the task to be executed.
[0131] The creation unit is used to create a waiting queue corresponding to the domain type of the task to be executed when there is no existing waiting queue corresponding to the domain type of the task to be executed.
[0132] The second adding unit is used to add the task to be executed to the waiting queue corresponding to the domain type of the task to be executed.
[0133] Furthermore, it also includes:
[0134] The third module determines the module and the closing module;
[0135] The third determining module is used to determine the next target task in the waiting queue if the waiting queue corresponding to the domain type of the target task is not empty;
[0136] The termination module is used to terminate task execution if the waiting queue corresponding to the domain type of the target task is empty.
[0137] Furthermore, the third determining module is used for:
[0138] If the waiting queue corresponding to the domain type of the target task is not empty, the next target task is determined according to the arrival order and / or priority of multiple tasks in the waiting queue.
[0139] Furthermore, it also includes:
[0140] Display module;
[0141] The display module is used to display the current status of the target task and the execution result during the execution of the target task.
[0142] In summary, in the device provided in this application embodiment, different domain types of tasks correspond to different finite state machines. Regardless of which domain type the target task belongs to, the target task only needs to be executed according to the current state of the target task, the execution result, and the finite state machine corresponding to the domain type of the target task. This reduces the business coupling and is suitable for the unified management of tasks of multiple domain types.
[0143] This application embodiment also provides a computer device, the computer device including a processor and a memory:
[0144] The memory is used to store program code and transmit the program code to the processor;
[0145] The processor is used to execute the steps of a task execution method based on a finite state machine as described above, according to the instructions in the program code.
[0146] This application also provides a computer-readable storage medium storing a computer program, which, when executed by a processor, implements the steps of a task execution method based on a finite state machine as described above.
[0147] It should be noted that the various embodiments in this specification are described in a progressive manner, and the same or similar parts between the various embodiments can be referred to mutually. Each embodiment focuses on describing the differences from other embodiments. In particular, for the embodiments of apparatus, devices, and storage media, since they are basically similar to the method embodiments, the description is relatively simple, and the relevant parts can be referred to the description of the method embodiments. The apparatus, devices, and storage media embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate, and the components indicated as units may or may not be physical units, that is, they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected to achieve the purpose of the solution in this embodiment according to actual needs. Those skilled in the art can understand and implement this without creative effort.
[0148] The above description is merely one specific embodiment of this application, but the scope of protection of this application is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the technical scope disclosed in this application should be included within the scope of protection of this application. Therefore, the scope of protection of this application should be determined by the scope of the claims.
Claims
1. A task execution method based on a finite state machine, characterized in that, include: Obtain the domain type of the task to be executed and the task concurrency corresponding to the domain type of the task to be executed; Based on the multiple domain types of multiple tasks in execution, query the number of tasks belonging to the domain type of the task to be executed among the multiple tasks to obtain the number of tasks; If the number of tasks is less than the task concurrency, the task to be executed is determined to be the target task; Perform the target task; During the execution of the target task, the current state of the target task, the execution result of the current state, and the finite state machine corresponding to the domain type of the target task are obtained. The finite state machine represents the relationships between multiple states; Based on the current state of the target task, the execution result, and the finite state machine, update the current state to obtain the updated state; If the updated state is a non-final state, the updated state is determined as the current state of the target task, and the target task continues to be executed; If the updated state is the final state, the target task is completed. When the target task includes a component installation task, updating the current state based on the current state of the target task, the execution result, and the finite state machine to obtain the updated state includes: When the current state of the target task is "start", the current state is updated according to the current state of the target task, the execution result and the finite state machine, and the updated state is "waiting". When the current state of the target task is waiting, the execution result during the waiting period includes obtaining an execution thread. Based on the current state of the target task, the execution result, and the finite state machine, the current state is updated to obtain the updated state as decompression. When the current state of the target task is "decompressing", if the execution result of "decompressing" includes "decompressing successful", the current state is updated according to the current state of the target task, the execution result, and the finite state machine to obtain the updated state "installing"; if the execution result of "decompressing" includes "decompressing failed", the current state is updated according to the current state of the target task, the execution result, and the finite state machine to obtain the updated state "component installation failed". When the current state of the target task is "Installing", if the execution result of the installation includes "Installation Success", the current state is updated according to the current state of the target task, the execution result, and the finite state machine to obtain the updated state "Component Installed"; if the execution result of the installation includes "Installation Failed", the current state is updated according to the current state of the target task, the execution result, and the finite state machine to obtain the updated state "Component Installation Failed".
2. The method according to claim 1, characterized in that, Also includes: If the number of tasks is detected to be greater than or equal to the task concurrency, the tasks to be executed are added to the waiting queue corresponding to the domain type of the tasks to be executed.
3. The method according to claim 2, characterized in that, If the number of tasks is detected to be greater than or equal to the task concurrency, the step of adding the tasks to be executed to the waiting queue corresponding to the domain type of the tasks to be executed includes: If the number of tasks is detected to be greater than or equal to the task concurrency, and there is a waiting queue corresponding to the domain type of the task to be executed, the task to be executed is added to the waiting queue corresponding to the domain type of the task to be executed. If there is no waiting queue corresponding to the domain type of the task to be executed, create a waiting queue corresponding to the domain type of the task to be executed. Add the task to be executed to the waiting queue corresponding to the domain type of the task to be executed.
4. The method according to claim 1, characterized in that, If the updated state is the final state, after completing the target task, the process further includes: If the waiting queue corresponding to the domain type of the target task is not empty, determine the next target task in the waiting queue; If the waiting queue corresponding to the domain type of the target task is empty, then the task execution will end.
5. The method according to claim 4, characterized in that, If the waiting queue corresponding to the domain type of the target task is not empty, determining the next target task in the waiting queue includes: The next target task is determined based on the arrival order and / or priority of multiple tasks in the waiting queue.
6. The method according to any one of claims 1-5, characterized in that, Also includes: During the execution of the target task, the current status of the target task and the execution result are displayed.
7. A task execution device based on a finite state machine, characterized in that, include: The module comprises a first determination module, an execution module, an acquisition module, a obtaining module, and a second determination module; The first determining module is used to obtain the domain type of the task to be executed and the task concurrency corresponding to the domain type of the task to be executed; based on the multiple domain types of multiple tasks in execution, query the number of tasks belonging to the domain type of the task to be executed among the multiple tasks to obtain the number of tasks; If the number of tasks is less than the task concurrency, the task to be executed is determined to be the target task; The execution module is used to execute the target task; The acquisition module is used to acquire, during the execution of the target task, the current state of the target task, the execution result of the current state, and the finite state machine corresponding to the domain type of the target task. The finite state machine represents the relationships between multiple states; The obtaining module is used to update the current state based on the current state of the target task, the execution result, and the finite state machine, and obtain the updated state. The second determining module is configured to, if the updated state is a non-final state, determine the updated state as the current state of the target task and continue executing the target task; if the updated state is a final state, complete the execution of the target task. The obtaining module is specifically used for: When the target task includes a component installation task, updating the current state based on the current state of the target task, the execution result, and the finite state machine to obtain the updated state includes: When the current state of the target task is "start", the current state is updated according to the current state of the target task, the execution result and the finite state machine, and the updated state is "waiting". When the current state of the target task is waiting, the execution result during the waiting period includes obtaining an execution thread. Based on the current state of the target task, the execution result, and the finite state machine, the current state is updated to obtain the updated state as decompression. When the current state of the target task is "decompressing", if the execution result of "decompressing" includes "decompressing successful", the current state is updated according to the current state of the target task, the execution result, and the finite state machine to obtain the updated state "installing"; if the execution result of "decompressing" includes "decompressing failed", the current state is updated according to the current state of the target task, the execution result, and the finite state machine to obtain the updated state "component installation failed". When the current state of the target task is "Installing", if the execution result of the installation includes "Installation Success", the current state is updated according to the current state of the target task, the execution result, and the finite state machine to obtain the updated state "Component Installed"; if the execution result of the installation includes "Installation Failed", the current state is updated according to the current state of the target task, the execution result, and the finite state machine to obtain the updated state "Component Installation Failed".
8. A computer device, characterized in that, The computer device includes a processor and memory: The memory is used to store program code and transmit the program code to the processor; The processor is configured to execute the steps of a task execution method based on a finite state machine as described in any one of claims 1-6, according to the instructions in the program code.
9. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program, which, when executed by a processor, implements the steps of a task execution method based on a finite state machine as described in any one of claims 1-6.
Citation Information
Patent Citations
Task processing method and apparatus, and electronic device
CN108804215A
Data processing method and device and computer readable storage medium
CN111274019A