Task execution method and device and computer readable storage medium
By constructing a task dictionary and scheduler, the problem of cumbersome and time-consuming adjustment of client tasks is solved, independent registration and operation of tasks is realized, flexible adjustment of cycles and times is supported, and the efficiency of task execution is improved.
Patent Information
- Application Number
- CN202410141019.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-01-31
- Publication Date
- 2025-08-08
AI Technical Summary
In the monitoring and control system of the client-server architecture, the new client tasks are cumbersome, the structure is not unified, the debugging cannot be done on a stand-alone basis, and multiple deployment test adjustments are required, which is time-consuming and labor-intensive, and different settings cannot be made according to the product line.
Provide a task execution method and device, which registers tasks by constructing a task dictionary, starts a task scheduler, receives task instructions and parses the task id, judges and modifys control variables or generates a new task id, and independently adjusts the task's running cycle and number of times.
It realizes independent registration and operation of tasks, can run in a single or periodic manner, supports concurrent operation, and can adjust the task cycle and number of tasks, and independently modify it, reducing the time and labor of deploying tests.
Smart Images

Figure CN120448043A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to a task execution technology, and in particular to a task execution method, device and computer-readable storage medium. Background Art
[0002] In a client-server (CS) monitoring and control system (TMCS) system, the client executes tasks and reports back to the server. During development, adding new client tasks is cumbersome, the structure is inconsistent, and single-machine debugging is impossible. Deployment at various sites requires adjustments to tasks and their cycles due to differences in client scale, server performance, and network channel capacity. This requires multiple deployments and testing to confirm results, which is time-consuming and labor-intensive.
[0003] The client's tasks and execution are integrated. When adjustments are needed, such as changing the cycle or removing a task, the code must be modified, recompiled, and deployed. All clients perform the same tasks without any differences, and different settings cannot be made based on product lines. Summary of the Invention
[0004] In view of the above, it is necessary to provide a task execution method, device and computer-readable storage medium, which can register the same task multiple times and independently modify the operation cycle, operation times, etc. of each executing task.
[0005] An embodiment of the present invention provides a task execution method, including: constructing a task dictionary, registering a task according to the task dictionary, the task including a task name, a task ID, a task description, a task function, and a function pointer; when the task registration is completed, starting a task scheduling program, the task scheduling program is used to receive task instructions to execute the task, the task scheduling program includes control variables of the task; receiving a target task instruction, and parsing the task ID of the target task instruction; judging whether the task ID exists in the task being executed; when the task ID exists, modifying the control variables in the task scheduling program according to the target task instruction; when the task ID does not exist, starting a new task and automatically generating a corresponding task ID; and executing the task corresponding to the task ID and returning the execution result.
[0006] Optionally, the control variables include a task execution cycle, a task execution number, a task upper limit, and a task on or off.
[0007] An embodiment of the present invention also provides a task execution device, which includes a memory, a processor, and a task execution program stored in the memory and executable on the processor. When the task execution program is executed by the processor, the following steps are implemented: constructing a task dictionary, registering tasks according to the task dictionary, the tasks including task name, task id, task description, task function, and function pointer; when the task registration is completed, starting a task scheduling program, the task scheduling program is used to receive task instructions to execute tasks, the task scheduling program includes control variables of the task; receiving a target task instruction, and parsing the task id of the target task instruction; determining whether the task id exists in the task being executed; when the task id exists, modifying the control variables in the task scheduling program according to the target task instruction; when the task id does not exist, starting a new task and automatically generating a corresponding task id; and executing the task corresponding to the task id and returning the execution result.
[0008] Optionally, the control variables include a task execution cycle, a task execution number, a task upper limit, and a task on or off.
[0009] Optionally, modifying the control variables in the task scheduling program according to the target task instruction includes: when receiving the target task instruction, parsing the parameter values related to the control variables in the target task instruction; and modifying the control variables in the task scheduling program according to the parameter values.
[0010] An embodiment of the present invention further provides a computer-readable storage medium having a computer program stored thereon. When the computer program is executed by a processor, the steps of the task execution method described above are implemented.
[0011] Compared to existing technologies, the task execution method, apparatus, and computer-readable storage medium described in this embodiment run each task in an independent thread and can be run individually or periodically. The same task can also run concurrently. When a task runs periodically, it can stop after a certain number of runs, or it can run an unlimited number of runs. When a task runs periodically, the run period can be adjusted, and the task can be terminated early. BRIEF DESCRIPTION OF THE DRAWINGS
[0012] Figure 1 It is a program module diagram of a task execution device according to a preferred embodiment of the present invention.
[0013] Figure 2 It is a flowchart of a task execution method according to a preferred embodiment of the present invention.
[0014] Description of main component symbols
[0015] Task execution device 10
[0016] Memory 20
[0017] Processor 30
[0018] Registration Module 101
[0019] Scheduling module 102
[0020] Analysis module 103
[0021] Judgment module 104
[0022] Execution module 105
[0023] Steps S20 to S30
[0024] The following specific embodiments will further illustrate the present invention in conjunction with the above-mentioned drawings. DETAILED DESCRIPTION
[0025] See Figure 1 FIG2 is a program module diagram of a preferred embodiment of a task execution device 10 of the present invention. The task execution device 10 includes a registration module 101, a scheduling module 102, a parsing module 103, a judgment module 104, and an execution module 105. The task execution device 10 also includes a memory 20 and a processor 30. The registration module 101, scheduling module 102, parsing module 103, judgment module 104, and execution module 105 of the present invention are computer program segments that execute a specific instruction. The memory 20 is used to store data such as the program code of the task execution device 10. The processor 30 is used to execute the program code stored in the memory 20.
[0026] The memory 20 includes at least one type of storage medium, including flash memory, hard disk, multimedia card, card-type memory (e.g., SD or DX memory), random access memory (RAM), static random access memory (SRAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), programmable read-only memory (PROM), magnetic memory, magnetic disk, optical disk, etc. The processor 30 can be a central processing unit (CPU), a controller, a microcontroller, a microprocessor, or other data processing chip, etc.
[0027] The registration module 101 constructs a task dictionary and registers a task according to the task dictionary. The task includes a task name, a task ID, a task description (for example, 3 bottles of beer on table 1, 4 bottles of beer on table 2, and 4 bottles of beer on table 1), a task function, and a function pointer.
[0028] Specifically, the task dictionary contains nouns related to tasks, which are constructed by writing task codes. For example, task1_name = scrambled eggs, task2_name = serve beer, task3_name = stir-fry, and so on. The task includes the task name (name), task ID, task description (description), function pointer (pointer), execution mode (whether to execute automatically, autorun), etc.
[0029] For example, write a task dictionary and register a task as follows:
[0030] Task1={"task1_name":{"name":"task1_name",
[0031] "run":[task1_function_pointer],
[0032] "des":"task1_function_description",
[0033] "id":"friendly_name_for_running_task",
[0034] "autorun": True / False}
[0035] When the task registration is completed, the scheduling module 102 starts the task scheduling program. The task scheduling program is used to receive task instructions to execute the task. The task scheduling program includes control variables of the task.
[0036] The control variables of a task include the task execution cycle, the number of task executions, the task limit, and whether the task is enabled or disabled. For example, the code to start the task scheduler is as follows:
[0037] running_tasks_tags={"task1_tag":"task1_id"}
[0038] running_tasks={"task1_id":{"name":"task1_name",
[0039] "count": int_run_counter,
[0040] "rounds":MAX_run_Limit,
[0041] "period": period_in_seconds,
[0042] "kill": True / False}
[0043] For example, if the task name is "Boil Eggs," and the program boils 10 eggs (rounds is 10), with count being the number of eggs, and boiling one egg equal to count + 1, and setting one egg to boil every minute, then period is 1. When all 10 eggs are boiled, the program is shut down with kill set to True. In this embodiment, the task's execution period, number of runs, and operation mode can be modified by modifying the task's control variables.
[0044] The parsing module 103 receives a target task instruction and parses the task ID of the target task instruction.
[0045] The task instruction can be an instruction issued by a command line (console) or a RESTFul instruction issued by a phone or network. For example, the instruction issued by the command line (console) is a machine order, and the RESTFul instruction issued by a phone or network is an online or phone order. For example, if the parsing module 103 receives the target task instruction of boiling four eggs, the task ID of the target task instruction is parsed as boiling eggs.
[0046] The judgment module 104 determines whether the task ID exists in the task being executed. When the task ID exists, the control variable in the task scheduling program is modified according to the target task instruction. When the task ID does not exist, the judgment module 104 starts a new task and automatically generates a corresponding task ID.
[0047] In this embodiment, the parsing module 103 receives a target task instruction of "boil 4 eggs" and parses the target task instruction into a task ID of "boil eggs." The judgment module 104 then determines whether a task with the task ID "boil eggs" exists among the currently executed tasks. For example, if the currently executed task "boil 10 eggs" is found, the judgment module 104 determines that a task with the same task ID exists. If the currently executed task "boil eggs" is not found, the judgment module 104 determines that a task with the same task ID does not exist.
[0048] Specifically, when a target task instruction is received, the parsing module 103 parses the parameter values related to the control variables in the target task instruction and modifies the control variables in the task scheduling program according to the parameter values. For example, if the target task instruction received is to boil 4 eggs, and the task ID of the target task instruction is parsed as boil eggs, if it is found that there is a task of boiling 10 eggs in the task being executed, the judgment module 104 determines that there is a same task ID, and modifies the control variables in the task scheduling program by adding 4 to rounds to 14. If it is found that there is no task of boiling eggs in the task being executed, the judgment module 104 determines that there is no same task ID, and starts a new boiled egg task and automatically generates a corresponding task ID.
[0049] The execution module 105 executes the task and returns the execution result.
[0050] Specifically, after executing the task, the execution module 105 sends the execution result to the host or command line that sends the target task instruction.
[0051] In this embodiment, task implementation, registration, and execution are independent. A task can be registered multiple times. A registered task can be run multiple times concurrently. Each executing task can independently modify its execution period, run count, and other parameters.
[0052] See Figure 2 FIG. 1 is a flowchart of a task execution method according to a preferred embodiment of the present invention. The task execution method is applied to the task execution device 10 and can be executed by the processor 30. Figure 1 The present invention is realized by modules 101 to 105 shown in FIG.
[0053] Step S20: Construct a task dictionary and register a task according to the task dictionary. The task includes a task name, a task ID, a task description (e.g., 3 bottles of beer on table 1, 4 bottles of beer on table 2, and 4 bottles of beer on table 1), a task function, and a function pointer.
[0054] Specifically, the task dictionary contains nouns related to tasks, which are constructed by writing task codes. For example, task1_name = scrambled eggs, task2_name = serve beer, task3_name = stir-fry, and so on. The task includes the task name (name), task ID, task description (description), function pointer (pointer), execution mode (whether to execute automatically, autorun), etc.
[0055] For example, write a task dictionary and register a task using the following program:
[0056] Task1={"task1_name":{"name":"task1_name",
[0057] "run":[task1_function_pointer],
[0058] "des":"task1_function_description",
[0059] "id":"friendly_name_for_running_task",
[0060] "autorun": True / False}
[0061] In step S22 , after the task registration is completed, a task scheduling program is started. The task scheduling program is used to receive task instructions to execute the task. The task scheduling program includes control variables of the task.
[0062] The control variables of a task include the task execution cycle, the number of task executions, the task limit, and whether the task is enabled or disabled. For example, the code to start the task scheduler is as follows:
[0063] running_tasks_tags={"task1_tag":"task1_id"}
[0064] running_tasks={"task1_id":{"name":"task1_name",
[0065] "count": int_run_counter,
[0066] "rounds":MAX_run_Limit,
[0067] "period": period_in_seconds,
[0068] "kill": True / False}
[0069] For example, the task name is "Boil Eggs." Boil 10 eggs (rounds = 10), with count being the number of eggs. Each egg boiled is count + 1. If one egg is boiled every minute, then period is 1. When all 10 eggs are boiled, the program is shut down by setting kill to True in the code. In this embodiment, the task's execution period (period), number of rounds (rounds), and autorun mode (autorun) can be modified by modifying the task's control variables.
[0070] Step S24: receiving a target task instruction and parsing the task ID of the target task instruction.
[0071] The task instruction can be a command issued by the command line (console) or a RESTFul command issued by phone or the network. For example, the command issued by the command line (console) is a machine order, while the RESTFul command issued by phone or the network is an online or phone order. For example, if the target task instruction received is to boil four eggs, the task ID of the target task instruction is parsed as boil eggs.
[0072] Step S26, determining whether the task ID exists in the task being executed, and if so, executing step S28; if not, executing step S30.
[0073] In this embodiment, a target task instruction is received, which is "boil 4 eggs." The target task instruction is parsed as having a task ID of "boil eggs." A determination is then made as to whether there is a task with the same ID as "boil eggs" among the currently executing tasks. For example, if "boil 10 eggs" is found among the currently executing tasks, then the same task ID is considered to exist. If "boil eggs" is not found among the currently executing tasks, then the same task ID is considered to not exist.
[0074] Step S28: modifying the control variables in the task scheduling program according to the target task instruction.
[0075] Specifically, when a target task instruction is received, the parameter values associated with the control variables in the target task instruction are parsed, and the control variables in the task scheduling program are modified based on the parameter values. For example, if the target task instruction received is to boil 4 eggs, and the task ID of the target task instruction is parsed as boil eggs, if the task currently being executed contains boil 10 eggs, it is considered that the same task ID exists. Based on the four parameter values associated with the control variables extracted, the control variables in the task scheduling program code are modified, and rounds is increased by 4 to 14.
[0076] Step S30: Start a new task and automatically generate a corresponding task ID.
[0077] For example, the target task instruction received is to boil 4 eggs. The task ID of the target task instruction is parsed as boiled eggs. If it is found that there is no boiled eggs in the task being executed, it is considered that the same task ID does not exist, and a new boiled egg task is started and the corresponding task ID is automatically generated.
[0078] Step S32: execute the task corresponding to the task id and return the execution result.
[0079] After executing the task, the execution result is sent to the host or command line that sent the target task instruction.
[0080] In this embodiment, task implementation, registration, and execution are independent. A task can be registered multiple times. A registered task can be run multiple times concurrently. Each executing task can independently modify its execution period, run count, and other parameters.
[0081] This embodiment further provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the steps of the task execution method described above are implemented.
[0082] It is worth noting that the above embodiments are only used to illustrate the technical solutions of the present invention and are not intended to limit the present invention. Although the present invention has been described in detail with reference to preferred embodiments, those skilled in the art should understand that the technical solutions of the present invention may be modified or replaced by equivalents without departing from the spirit and scope of the technical solutions of the present invention.
Claims
1. A task execution method, characterized in that: The method comprises: Constructing a task dictionary, and registering a task according to the task dictionary, wherein the task includes a task name, a task ID, a task description, a task function, and a function pointer, wherein the task dictionary is a noun related to the task; When the task registration is completed, the task scheduling program is started, the task scheduling program is used to receive the task instruction to execute the task, and the task scheduling program includes the control variables of the task; Receive a target task instruction and parse the task ID of the target task instruction; Determine whether the task ID exists in the task being executed; When the task ID exists, modifying the control variables in the task scheduling program according to the target task instruction; When the task ID does not exist, start a new task and automatically generate a corresponding task ID; and Execute the task corresponding to the task id and return the execution result.
2. The task execution method according to claim 1, wherein: The control variables include task execution cycle, task execution times, task upper limit, and task opening or closing.
3. The task execution method according to claim 1, wherein: The step of modifying the control variables in the task scheduling program according to the target task instruction includes: When receiving a target task instruction, parsing the parameter values related to the control variables in the target task instruction; and The control variables in the task scheduler are modified according to the parameter values.
4. A task execution device, characterized in that: The task execution device includes a memory, a processor, and a task execution program stored in the memory and executable on the processor. When the task execution program is executed by the processor, the following steps are implemented: Constructing a task dictionary, and registering a task according to the task dictionary, wherein the task includes a task name, a task ID, a task description, a task function, and a function pointer, wherein the task dictionary is a noun related to the task; When the task registration is completed, the task scheduling program is started, the task scheduling program is used to receive the task instruction to execute the task, and the task scheduling program includes the control variables of the task; Receive a target task instruction and parse the task ID of the target task instruction; Determine whether the task ID exists in the task being executed; When the task ID exists, modifying the control variables in the task scheduling program according to the target task instruction; When the task ID does not exist, start a new task and automatically generate a corresponding task ID; Execute the task corresponding to the task id and return the execution result.
5. The task execution device according to claim 4, characterized in that: The control variables include task execution cycle, task execution times, task upper limit, and task opening or closing.
6. The task execution device according to claim 4, wherein: The step of modifying the control variables in the task scheduling program according to the target task instruction includes: When receiving a target task instruction, parsing the parameter values related to the control variables in the target task instruction; and The control variables in the task scheduler are modified according to the parameter values.
7. 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 the task execution method according to any one of claims 1 to 3.