Task execution method, task execution device, electronic equipment and storage medium

By creating a target message queue to store the execution status when the task executor abnormally shuts down, the problem of orphan processes being unable to obtain the task status is solved, achieving accurate and consistent acquisition of the task execution status and ensuring the continuity and accuracy of task execution.

CN120929267APending Publication Date: 2025-11-11PING AN TECH (SHENZHEN) CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202511103454.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-08-06
Publication Date
2025-11-11

AI Technical Summary

Technical Problem

When the executor shuts down or restarts abnormally, the process that the original executor used to execute the task script becomes an orphan process, making it impossible for the newly started executor to obtain the execution status of the task script, thus affecting the accuracy and consistency of task execution.

Method used

By creating a target thread and process, calling the target execution interface to execute the task script, and responding to the task executor shutdown operation after a preset time, the thread is released, the second task executor is started, and the execution status of the task script is stored in the target message queue through the target process, so that the second task executor can obtain the execution status from the message queue.

Benefits of technology

It improves the accuracy and consistency of task execution status acquisition, avoids errors caused by log recognition methods, and ensures the normal execution of downstream tasks.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120929267A_ABST
    Figure CN120929267A_ABST
Patent Text Reader

Abstract

The embodiment of the invention provides a task execution method, a task execution device, electronic equipment and a storage medium, belongs to the technical field of computers, and is suitable for the field of financial science and technology and the field of digital medical treatment. The method comprises the steps that a target thread is created through a first task executor, a target execution interface is called through the target thread, a target process is created according to the called target execution interface, and a task script of a target task is executed through the target process; wherein the task script has a script execution time length, responds to a closing operation of the first task executor in a preset time length, releases the target thread and starts the second task executor, the preset time length is smaller than the script execution time length, an execution state of the task script is obtained through the target process, and the execution state is stored in a target message queue according to the target task. The execution state is obtained from the target message queue through the second task executor, and the task execution state can be obtained.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of computer technology, and is applied to the fields of financial technology and digital healthcare. In particular, it relates to a task execution method, a task execution device, an electronic device, and a storage medium. Background Technology

[0002] An executor is a component used to execute task scripts. In fintech scenarios, executors can execute task scripts for anomaly detection. Based on these scripts, they can analyze massive amounts of data, such as user transaction patterns, geographical location, and device information, to quickly identify abnormal operational behaviors, such as unusually large transactions or logins from different locations. In digital healthcare scenarios, executors can execute task scripts for patient information management. Based on these scripts, they can integrate patients' electronic medical records, medical images, diagnostic results, and other data to create comprehensive patient health records.

[0003] In related technologies, the executor obtains the execution status of the task script and feeds it back to the scheduling controller so that the scheduling controller can dynamically schedule resources based on the execution status. However, when the executor shuts down or restarts abnormally, the process originally used by the executor to execute the task script becomes an orphan process, making it impossible for the newly started executor to obtain the execution status of the task script. Summary of the Invention

[0004] The main objective of this application is to provide a task execution method, a task execution device, an electronic device, and a storage medium, which aim to obtain the state of task execution.

[0005] To achieve the above objectives, a first aspect of this application provides a task execution method, the method comprising:

[0006] The target thread is created through the first task executor, and the target execution interface is called through the target thread.

[0007] A target process is created based on the invoked target execution interface, and the task script of the target task is executed through the target process; wherein, the task script has a script execution duration;

[0008] In response to the shutdown operation of the first task executor after a preset duration, the target thread is released and the second task executor is started; wherein, the preset duration is less than the script execution duration;

[0009] The execution status of the task script is obtained through the target process, and the execution status is stored in the target message queue according to the target task;

[0010] The execution status is obtained from the target message queue through the second task executor.

[0011] In some embodiments, storing the execution state to the target message queue according to the target task includes:

[0012] The execution state is encapsulated to obtain a status message;

[0013] The preset message queue is filtered according to the target task to obtain the target message queue;

[0014] The status message is stored in the target message queue.

[0015] In some embodiments, the step of filtering the preset message queue according to the target task to obtain the target message queue includes:

[0016] Obtain the task priority of the target task;

[0017] The preset message queue is first filtered according to the task priority to obtain a reference message queue;

[0018] Obtain the number of queues in the reference message queue;

[0019] The load factor of the reference message queue is obtained based on the number of queues;

[0020] The reference message queue is filtered a second time based on the load coefficient to obtain the target message queue.

[0021] In some embodiments, obtaining the load factor of the reference message queue based on the number of queues includes:

[0022] Obtain the queue length, queue processing speed, and queue resource utilization of the reference message queue;

[0023] Calculate the average waiting time based on the queue length and the queue processing speed;

[0024] The load factor is calculated based on the average waiting time and the queue resource utilization rate.

[0025] In some embodiments, calculating the load factor based on the average waiting time and the queue resource utilization includes:

[0026] Obtain the task complexity of the target task and determine the current time period;

[0027] The weight parameters are determined based on the task complexity and the current time period.

[0028] The load coefficient is obtained by weighting the average waiting time and the queue resource utilization rate according to the weight parameters.

[0029] In some embodiments, the step of performing a second filtering on the reference message queue based on the load coefficient to obtain the target message queue includes:

[0030] The reference message queues are filtered according to the load coefficient to obtain selected message queues; wherein, the selected message queues include message partitions;

[0031] Calculate the target load of the message partition, and calculate the load difference between the message partitions based on the target load;

[0032] The selected message queue is partitioned and expanded according to the load difference to obtain the target message queue.

[0033] In some embodiments, the target message queue includes a reference partition, and storing the status message in the target message queue includes:

[0034] The status message is hashed to obtain a hash value;

[0035] The reference partition is filtered based on the hash value to obtain the target partition;

[0036] The status message is stored in the target partition.

[0037] To achieve the above objectives, a second aspect of this application provides a task execution apparatus, the apparatus comprising:

[0038] The calling module is used to create a target thread through the first task executor and call the target execution interface through the target thread.

[0039] An execution module is used to create a target process based on the invoked target execution interface, and execute the task script of the target task through the target process; wherein, the task script has a script execution duration;

[0040] A response module is configured to respond to the shutdown operation of the first task executor within a preset duration, release the target thread, and start the second task executor; wherein the preset duration is less than the script execution duration;

[0041] The storage module is used to obtain the execution status of the task script through the target process and store the execution status to the target message queue according to the target task;

[0042] The acquisition module is used to acquire the execution status from the target message queue through the second task executor.

[0043] To achieve the above objectives, a third aspect of this application provides an electronic device, which includes a memory and a processor. The memory stores a computer program, and the processor executes the computer program to implement the method described in the first aspect.

[0044] To achieve the above objectives, a fourth aspect of the present application provides a computer-readable storage medium storing a computer program that, when executed by a processor, implements the method described in the first aspect.

[0045] The task execution method, device, electronic device, and computer-readable storage medium proposed in this application create a target thread through a first task executor and execute tasks by calling a target execution interface through the target thread. The target execution interface can execute multiple business tasks. To improve the execution efficiency of business tasks, a target process is created based on the called target execution interface, and the task script of the target task is executed through the target process. In response to the shutdown operation of the first task executor after a preset time, the target thread is released, making the target process an orphan process. A second task executor is then started, but it cannot obtain the task status of the target task executed by the orphan process. To enable the newly started task executor to obtain the task execution status of the target task, a target message queue is created. The execution status of the task script is obtained through the target process, and the execution status is stored in the target message queue according to the target task, allowing the second task executor to consume the execution status of the target task from the target message queue. Attached Figure Description

[0046] Figure 1 This is a flowchart of the task execution method provided in the embodiments of this application;

[0047] Figure 2 yes Figure 1 The flowchart of step S140 in the middle;

[0048] Figure 3 yes Figure 2 The flowchart of step S220 in the text;

[0049] Figure 4 yes Figure 3 The flowchart of step S340 in the text;

[0050] Figure 5 yes Figure 4 The flowchart of step S430 in the middle;

[0051] Figure 6 yes Figure 3 The flowchart of step S350 in the text;

[0052] Figure 7 yes Figure 2 The flowchart of step S230 in the text;

[0053] Figure 8 This is a schematic diagram of the structure of the task execution device provided in the embodiments of this application;

[0054] Figure 9 This is a schematic diagram of the hardware structure of the electronic device provided in the embodiments of this application. Detailed Implementation

[0055] To make the objectives, technical solutions, and advantages of this application clearer, the following detailed description is provided in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the scope of this application.

[0056] It should be noted that although functional modules are divided in the device schematic diagram and a logical order is shown in the flowchart, in some cases, the steps shown or described may be performed in a different order than the module division in the device or the order in the flowchart. The terms "first," "second," etc., in the specification, claims, and the aforementioned drawings are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence.

[0057] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this application belongs. The terminology used herein is for the purpose of describing embodiments of this application only and is not intended to limit this application.

[0058] An executor is a component used to execute task scripts. In fintech scenarios, executors can execute task scripts for anomaly detection. Based on these scripts, they can analyze massive amounts of data, such as user transaction patterns, geographical location, and device information, to quickly identify abnormal operational behaviors, such as unusually large transactions or logins from different locations. In digital healthcare scenarios, executors can execute task scripts for patient information management. Based on these scripts, they can integrate patients' electronic medical records, medical images, diagnostic results, and other data to create comprehensive patient health records.

[0059] In related technologies, the executor obtains the execution status of the task script and feeds it back to the scheduling controller so that the scheduling controller can dynamically schedule resources based on the execution status. However, when the executor shuts down or restarts abnormally, the process originally used by the executor to execute the task script becomes an orphan process, making it impossible for the newly started executor to obtain the execution status of the task script.

[0060] Based on this, embodiments of this application provide a task execution method, a task execution device, an electronic device, and a computer-readable storage medium, which aim to obtain the state of task execution.

[0061] The task execution method, task execution device, electronic device, and computer-readable storage medium provided in the embodiments of this application are specifically described through the following embodiments. First, the task execution method in the embodiments of this application is described.

[0062] The task execution method provided in this application relates to the field of computer technology. The task execution method provided in this application can be applied to a terminal, a server, or software running on either a terminal or a server. In some embodiments, the terminal can be a smartphone, tablet, laptop, desktop computer, etc.; the server can be configured as an independent physical server, a server cluster or distributed system composed of multiple physical servers, or a cloud server providing basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communication, middleware services, domain name services, security services, CDN, and big data and artificial intelligence platforms; the software can be an application implementing the task execution method, but is not limited to the above forms.

[0063] This application can be used in a wide variety of general-purpose or special-purpose computer system environments or configurations. Examples include: personal computers, server computers, handheld or portable devices, tablet devices, multiprocessor systems, microprocessor-based systems, set-top boxes, programmable consumer electronics, network PCs, minicomputers, mainframe computers, and distributed computing environments including any of the above systems or devices. This application can be described in the general context of computer-executable instructions executed by a computer, such as program modules. Generally, program modules include routines, programs, objects, components, data structures, etc., that perform specific tasks or implement specific abstract data types. This application can also be practiced in distributed computing environments where tasks are performed by remote processing devices connected via a communication network. In distributed computing environments, program modules can reside in local and remote computer storage media, including storage devices.

[0064] Figure 1 This is an optional flowchart of the task execution method provided in the embodiments of this application. Figure 1 The method may include, but is not limited to, steps S110 to S150.

[0065] Step S110: Create a target thread through the first task executor, and call the target execution interface through the target thread;

[0066] Step S120: Create a target process based on the invoked target execution interface, and execute the task script of the target task through the target process; wherein, the task script has a script execution duration;

[0067] Step S130: In response to the shutdown operation of the first task executor after a preset duration, release the target thread and start the second task executor; wherein, the preset duration is less than the script execution duration;

[0068] Step S140: Obtain the execution status of the task script through the target process, and store the execution status in the target message queue according to the target task;

[0069] Step S150: Obtain the execution status from the target message queue through the second task executor.

[0070] In the embodiments of this application, steps S110 to S150 involve creating a target message queue, whereby the target process, which becomes an orphan process, stores the execution status of the target task in the target message queue, allowing the newly created task executor to consume the execution status of the target task from the target message queue.

[0071] In step S110 of some embodiments, the first task executor is a component used to perform various business tasks such as data cleaning, model training, and problem querying. Big data tasks refer to a series of tasks covering big data collection, storage, processing, analysis, and application. Big data tasks have a long execution time. In order to improve task execution efficiency, the first task executor will create multiple target threads to execute different big data tasks. For example, one target thread executes the task of collecting user operation behavior data such as click events and page views from various channels, while another target thread executes the data cleaning task.

[0072] In response to the task execution instruction, the first task executor parses the instruction to obtain the target task and its parameters. These parameters are the input parameters required for the target task's execution, such as the storage location and name of the task script, and the task's dependencies. Dependencies refer to other tasks or conditions that need to be completed before the target task can be executed. The target thread reads the task parameters and calls the target execution interface based on them.

[0073] In step S120 of some embodiments, the target execution interface can concurrently execute multiple large data tasks through threads or processes. However, threads are lightweight execution units that share the memory space of the same process. If a thread crashes or encounters an exception, it may cause the entire process to crash, thereby affecting the normal execution of all threads within the process. This means that the failure of one task affects the execution of the entire task set. Multiple processes can provide excellent isolation; the crash of one process will not affect other processes, ensuring the independent execution of tasks. A target process is created through the target execution interface. The target process reads task parameters and executes the task script of the target task according to the task parameters. The task script is a program code file containing the task execution logic of the target task. The task script has a script execution duration, which is the expected duration from the start of the task script's execution to its end, such as 5 hours.

[0074] In step S130 of some embodiments, the preset duration is the time elapsed from the start of the target process executing the task script of the target task to the shutdown of the first task executor, and the preset duration is less than the script execution time. During the execution of the task script by the target process, the first task executor may shut down due to various factors such as version changes, restarts, or abnormal shutdowns. Within the preset duration, such as 2 hours, in response to the shutdown operation of the first task executor, all target threads created by the first task executor are released, making the target process an orphan process. To ensure the smooth execution of the business task, a new task executor is started, resulting in a second task executor. At this time, the second task executor cannot obtain the execution status of the task script executed by the orphan process, thereby blocking the execution of downstream dependent tasks. The execution status refers to the specific state of the task during execution, such as completed, running, pending execution, or execution failed. For example, after the script execution time, the target process successfully executes the task script of the target task, and the execution status of the task script is "completed".

[0075] In related technologies, the new task executor obtains the task execution status of orphan processes in the following way: It polls the logs generated by the task script execution, extracts keywords such as "execution successful" and "execution failed" from the logs, and writes back the task execution status based on these keywords. However, this method of obtaining task execution status relies on the standardization of the logs. The execution status identified by the logs may differ from the actual execution status, thus affecting the accuracy of downstream data. For example, if the output of task A is the input of task B, and the actual status of task A is "failed," but the log identifies the execution status as "completed," when task B processes the output data of task A, the output data of task A may not actually exist or may be incomplete, causing task B to fail or produce inaccurate output results. Environment variable parameters can also be used to cache the execution status, but environment variable parameters contain many control parameters. If the execution status is written to the control plane, it can easily affect the control plane functionality. This application embodiment creates a target message queue, uses the target process as the producer and the second task executor as the consumer, and stores the execution status of the target task in the target message queue through the target process, so that the second task executor can obtain the execution status from the target message queue. Compared with the log recognition method, this can improve the accuracy and consistency of status acquisition.

[0076] Please see Figure 2 In some embodiments, step S140 may include, but is not limited to, steps S210 to S230:

[0077] Step S210: Encapsulate the execution status to obtain a status message;

[0078] Step S220: Filter the preset message queues according to the target task to obtain the target message queue;

[0079] Step S230: Store the status message in the target message queue.

[0080] In step S210 of some embodiments, a message format is defined. The message format includes fields such as message type, task ID, task status, timestamp, and other information such as task processing progress and error information. The message type is used to identify the type of message, such as a status message or a prompt message. The task ID is used to uniquely identify the task. The task status is the current state of the task, such as pending execution, running, completed, or failed. To facilitate the transmission and storage of the task execution status, message content is created according to the message format and execution status. That is, the various fields in the message format are filled in, and the message content is converted into a format suitable for transmission, such as JSON format, thereby encapsulating the execution status into a message to obtain a status message.

[0081] In step S220 of some embodiments, the preset message queue is a pre-created queue for storing task execution status. To improve the storage efficiency of execution status and support the storage of execution status for multiple task types, a message queue with better storage performance is selected from the preset message queue according to the target task to obtain the target message queue.

[0082] In step S230 of some embodiments, in order to enable the second task executor to obtain the execution status of the target task, the status message is stored in the target message queue by the target process.

[0083] Steps S210 to S230 above improve the storage efficiency of task execution status by selecting target message queues with better storage performance and storing the task execution status in the target message queues.

[0084] Please see Figure 3 In some embodiments, step S220 may include, but is not limited to, steps S310 to S350:

[0085] Step S310: Obtain the task priority of the target task;

[0086] Step S320: Perform a first filter on the preset message queue according to the task priority to obtain the reference message queue;

[0087] Step S330: Obtain the number of queues in the reference message queue;

[0088] Step S340: Obtain the load factor of the reference message queue based on the number of queues;

[0089] Step S350: Perform a second filtering on the reference message queue based on the load factor to obtain the target message queue.

[0090] In step S310 of some embodiments, the task priority of the target task is obtained. The task priority is used to reflect the importance and urgency of the target task. The higher the task priority, the more important or urgent the target task is. Task priorities include high priority, medium priority, or low priority.

[0091] In step S320 of some embodiments, in a multi-tasking environment, system resources such as computing resources and storage resources are limited. To ensure that the status of high-priority tasks can be processed in a timely manner, such as the status updates of transaction orders in a financial transaction system (e.g., successful or failed transactions), priority is given to processing. A reference message queue is obtained by filtering a preset message queue according to task priority, so as to quickly respond to status changes of high-priority tasks through the reference message queue. Specifically, the preset message queue includes a high-priority queue, a medium-priority queue, or a high-priority queue. If the target task has a high priority, the high-priority queue is selected as the reference message queue; if the target task has a medium priority, the medium-priority queue is selected; and if the target task has a low priority, the low-priority queue is selected. This allows for reasonable resource allocation based on different task priorities, ensuring that status updates of critical tasks can be processed with priority.

[0092] In step S330 of some embodiments, the number of reference message queues is obtained, and the number of queues is an integer greater than 0.

[0093] In step S340 of some embodiments, if the number of queues is equal to 1, it means there is only one reference message queue, and the reference message queue is used as the target message queue. If the number of queues is greater than 1, it means there are multiple reference message queues. In order to obtain a message queue with better performance, the load factor of the reference message queue is obtained, and the reference message queues are filtered according to the load factor. The load factor is an indicator used to measure the load of the reference message queue. The larger the load factor, the higher the load of the reference message queue.

[0094] In step S350 of some embodiments, the load conditions of each reference message queue are different. In order to cope with complex and ever-changing business needs and achieve load balancing, the task execution status needs to be evenly distributed among the reference message queues to avoid overloading a single queue. A reference message queue with a smaller load coefficient can be selected as the target message queue. For example, the reference message queues can be sorted according to their load coefficients from smallest to largest, and a reference message queue can be randomly selected from the top k sorted queues as the target message queue, where k is an integer greater than or equal to 1 and less than the number of queues. Alternatively, the reference message queue with the smallest load coefficient can be selected as the target message queue.

[0095] In financial transaction scenarios, when order transaction volume suddenly surges, the order transaction status can be distributed to message queues with lower load by filtering message queues through load coefficients, avoiding overload of a single queue and ensuring timely updates of order transaction status.

[0096] Through the above steps S310 to S350, load balancing of the message queue can be achieved, and the processing efficiency of task execution status can be optimized.

[0097] Please see Figure 4 In some embodiments, step S340 may include, but is not limited to, steps S410 to S430:

[0098] Step S410: Obtain the queue length, queue processing speed, and queue resource utilization of the reference message queue;

[0099] Step S420: Calculate the average waiting time based on the queue length and queue processing speed;

[0100] Step S430: Calculate the load factor based on the average waiting time and queue resource utilization.

[0101] In step S410 of some embodiments, parameters affecting the load of the reference message queue are obtained, including queue length, queue processing speed and queue resource utilization. The queue length is the number of status messages stored in the reference message queue, the queue processing speed is the number of status information obtained by the task executor from the message queue per unit time, and the queue resource utilization refers to the proportion of system resources occupied by the queue. System resources can be CPU resources, memory resources, etc.

[0102] In step S420 of some embodiments, the queue length and the queue processing speed are divided to obtain the average waiting time.

[0103] In step S430 of some embodiments, the average waiting time and queue resource utilization are summed to obtain the load factor.

[0104] Through the above steps S410 to S430, the load factor of the queue can be obtained, so as to quantitatively evaluate the load of the queue based on the load factor.

[0105] Please see Figure 5 In some embodiments, step S430 may include, but is not limited to, steps S510 to S530:

[0106] Step S510: Obtain the task complexity of the target task and determine the current time period;

[0107] Step S520: Determine the weight parameters based on the task complexity and the current time period;

[0108] Step S530: The average waiting time and queue resource utilization are weighted according to the weight parameters to obtain the load coefficient.

[0109] In step S510 of some embodiments, a time complexity score is calculated based on the script execution time of the target task's task script, and a space complexity score is calculated based on the memory space occupied by the target process when executing the target task's task script. The time complexity score and the space complexity score are added together to obtain the task complexity.

[0110] Specifically, a duration threshold is set. If the script execution time is less than or equal to the duration threshold, it indicates that the target task has a short execution time, and the time complexity score is set to 0. If the script execution time is greater than the duration threshold, the time complexity score is set to 1. A capacity threshold is set. If the memory space occupied is less than or equal to the capacity threshold, it indicates that the memory space occupied by the target task is small, and the space complexity score is set to 0. If the memory space occupied is greater than the capacity threshold, the space complexity score is set to 1.

[0111] The current time period is determined by acquiring the time period used to calculate the load factor or the time period during which the target task is executed. The time period type is then identified, including peak, off-peak, or neutral periods. Peak periods are the busiest times for business activities, during which a large number of business tasks need to be executed. Off-peak periods are times with relatively less business activity, during which only a small number of business tasks need to be executed. Neutral periods are periods between peak and off-peak periods, during which business activities are relatively stable.

[0112] In step S520 of some embodiments, the time period score of the current time period is obtained. If the current time period is a peak period, the time period score is 3; if the current time period is an off-peak period, the time period score is 2; and if the current time period is a low-peak period, the time period score is 1.

[0113] The task complexity and the current time period score are added together. The sum is then divided by the maximum possible value of the sum to obtain the weight parameter. The weight parameter is located in the range [0,1]. It should be noted that the task complexity value is [0,2], the time period score value is [1,3], and the maximum possible value of the sum is 5.

[0114] In step S530 of some embodiments, the average waiting time and queue resource utilization are summed, and the weight parameter is multiplied by the summation value to obtain the load coefficient.

[0115] Steps S510 to S530 above, by considering the impact of task complexity and the time period in which the task is executed on the load, can more accurately measure the load and thus select a queue with better performance for storing state information.

[0116] Please see Figure 6In some embodiments, step S350 may include, but is not limited to, steps S610 to S630:

[0117] Step S610: Filter the reference message queues according to the load factor to obtain the selected message queues; wherein, the selected message queues include message partitions;

[0118] Step S620: Calculate the target load of the message partition and calculate the load difference between message partitions based on the target load;

[0119] Step S630: Expand the selected message queue by partitioning it according to the load difference to obtain the target message queue.

[0120] In step S610 of some embodiments, the reference message queue with the smallest load factor is selected as the selected message queue. The selected message queue includes message partitions, which are the basic units for storing and processing state information.

[0121] In step S620 of some embodiments, the partition length, partition processing speed, and partition resource utilization of the message partition are obtained. The partition length is the number of state messages stored in the message partition, the partition processing speed is the number of state information messages the task executor retrieves from the message partition per unit time, and the partition resource utilization is the proportion of system resources occupied by the message partition. The partition waiting time is obtained by dividing the partition length by the partition processing speed. The target load is obtained by adding the partition waiting time and the queue resource utilization. Alternatively, the target load can be obtained by multiplying the sum of the partition waiting time and the queue resource utilization by the weighting coefficient calculated in step S520. It should be noted that each message partition needs to use the same target load calculation method to perform load difference calculation on the same dimension.

[0122] Calculate the absolute value of the difference in target load between message partitions to obtain the load variability. The load variability is used to determine whether the load is balanced between any two message partitions. If the load variability is too large, it indicates that the load is unbalanced among the message partitions within the selected message queue.

[0123] In step S630 of some embodiments, the maximum load difference is obtained. If the maximum load difference is greater than or equal to a preset difference threshold, it indicates that there is a load imbalance among message partitions within the selected message queue. A preset number of message partitions are then added to obtain the target message queue. The load coefficient of the selected message queue can be compared with the ideal partition load to obtain the ideal number of partitions. The ideal partition load is the expected average load of the message partitions. The preset number is obtained by subtracting the number of ideal partitions from the number of existing message partitions in the selected message queue. If the maximum load difference is less than the preset difference threshold, it indicates that the load of each message partition within the selected message queue is relatively balanced, and the selected message queue is taken as the target message queue.

[0124] Alternatively, the average target load of all message partitions in the selected message queue can be calculated to obtain the average load. The maximum load difference is then subtracted from the average load to obtain the load imbalance value. The load imbalance value is then divided by the average load to obtain the load imbalance ratio. If the load imbalance ratio is greater than a preset ratio threshold, such as 0.5, it indicates a significant degree of load imbalance. In this case, the selected message queue is expanded to obtain the target message queue.

[0125] Through the above steps S610 to S630, the load imbalance of message partitions within the queue can be alleviated.

[0126] Please see Figure 7 In some embodiments, the target message queue includes a reference partition, and step S230 may include, but is not limited to, steps S710 to S730:

[0127] Step S710: Perform a hash calculation on the status message to obtain a hash value;

[0128] Step S720: Filter the reference partitions according to the hash value to obtain the target partition;

[0129] Step S730: Store the status message in the target partition.

[0130] In step S710 of some embodiments, the status message is hashed using a hash function to obtain a hash value. A hash function is a function that converts an input of arbitrary length into an output of fixed length; hash functions can be SHA-256, SHA-3, etc.

[0131] In step S720 of some embodiments, each hash value corresponds to a unique partition number. The partition number is determined based on the hash value, and the reference partitions are filtered based on the partition number to obtain the target partition.

[0132] In step S730 of some embodiments, the status message is stored in the target partition of the target message queue by the target process.

[0133] Steps S710 to S730 above use a hash function to evenly store state information across different partitions of the message queue, thereby achieving load balancing of the message queue.

[0134] In step S150 of some embodiments, the second task executor obtains the execution status of the target task from the target message queue according to the task ID of the target task, and feeds back the execution status to the scheduling controller, so that the scheduling controller dynamically adjusts the task scheduling strategy based on the execution status, such as adjusting the task priority, retrying the task execution failure, etc., to optimize resource allocation.

[0135] Please see Figure 8 This application also provides a task execution apparatus that can implement the above-described task execution method. The task execution apparatus includes:

[0136] Module 810 is called to create a target thread through the first task executor and call the target execution interface through the target thread.

[0137] The execution module 820 is used to create a target process based on the invoked target execution interface, and execute the task script of the target task through the target process; wherein, the task script has a script execution duration;

[0138] The response module 830 is used to respond to the shutdown operation of the first task executor within a preset time, release the target thread, and start the second task executor; wherein the preset time is less than the script execution time.

[0139] The storage module 840 is used to obtain the execution status of the task script through the target process and store the execution status to the target message queue according to the target task.

[0140] The acquisition module 850 is used to obtain the execution status from the target message queue through the second task executor.

[0141] The specific implementation of this task execution device is basically the same as the specific implementation of the task execution method described above, and will not be repeated here.

[0142] This application also provides an electronic device, which includes a memory and a processor. The memory stores a computer program, and the processor executes the computer program to implement the above-described task execution method. This electronic device can be any smart terminal, including tablet computers, in-vehicle computers, etc.

[0143] Please see Figure 9 , Figure 9 The hardware structure of an electronic device according to another embodiment is illustrated. The electronic device includes:

[0144] The processor 910 can be implemented using a general-purpose central processing unit (CPU), microprocessor, application specific integrated circuit (ASIC), or one or more integrated circuits, and is used to execute relevant programs to implement the technical solutions provided in the embodiments of this application.

[0145] The memory 920 can be implemented as a read-only memory (ROM), static storage device, dynamic storage device, or random access memory (RAM). The memory 920 can store the operating system and other applications. When the technical solutions provided in the embodiments of this specification are implemented through software or firmware, the relevant program code is stored in the memory 920 and is called by the processor 910 to execute the task execution method of the embodiments of this application.

[0146] The input / output interface 930 is used to implement information input and output;

[0147] The communication interface 940 is used to enable communication and interaction between this device and other devices. Communication can be achieved through wired means (such as USB, network cable, etc.) or wireless means (such as mobile network, WIFI, Bluetooth, etc.).

[0148] Bus 950 transmits information between various components of the device (e.g., processor 910, memory 920, input / output interface 930, and communication interface 940);

[0149] The processor 910, memory 920, input / output interface 930 and communication interface 940 are connected to each other within the device via bus 950.

[0150] This application also provides a computer-readable storage medium storing a computer program that, when executed by a processor, implements the above-described task execution method.

[0151] Memory, as a non-transitory computer-readable storage medium, can be used to store non-transitory software programs and non-transitory computer-executable programs. Furthermore, memory may include high-speed random access memory, and may also include non-transitory memory, such as at least one disk storage device, flash memory device, or other non-transitory solid-state storage device. In some embodiments, memory may optionally include memory remotely located relative to the processor, and these remote memories can be connected to the processor via a network. Examples of such networks include, but are not limited to, the Internet, intranets, local area networks, mobile communication networks, and combinations thereof.

[0152] The task execution method, task execution device, electronic device, and computer storage medium provided in this application embodiment create a target message queue. The target process, which becomes an orphan process, stores the execution status of the target task in the target message queue, so that the newly created task executor can consume the execution status of the target task from the target message queue.

[0153] The embodiments described in this application are for the purpose of more clearly illustrating the technical solutions of the embodiments of this application, and do not constitute a limitation on the technical solutions provided by the embodiments of this application. As those skilled in the art will know, with the evolution of technology and the emergence of new application scenarios, the technical solutions provided by the embodiments of this application are also applicable to similar technical problems.

[0154] Those skilled in the art will understand that the technical solutions shown in the figures do not constitute a limitation on the embodiments of this application, and may include more or fewer steps than shown, or combine certain steps, or different steps.

[0155] The device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate; 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 this embodiment according to actual needs.

[0156] Those skilled in the art will understand that all or some of the steps in the methods disclosed above, as well as the functional modules / units in the systems and devices, can be implemented as software, firmware, hardware, or suitable combinations thereof.

[0157] The terms “first,” “second,” “third,” “fourth,” etc. (if present) in the specification and accompanying drawings of this application are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments of this application described herein can be implemented in orders other than those illustrated or described herein. Furthermore, the terms “comprising” and “having,” and any variations thereof, are intended to cover non-exclusive inclusion; for example, a process, method, system, product, or apparatus that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or apparatus.

[0158] It should be understood that in this application, "at least one (item)" means one or more, and "more than" means two or more. "And / or" is used to describe the relationship between related objects, indicating that three relationships can exist. For example, "A and / or B" can represent three cases: only A exists, only B exists, and both A and B exist simultaneously, where A and B can be singular or plural. The character " / " generally indicates that the preceding and following related objects are in an "or" relationship. "At least one (item) of the following" or similar expressions refer to any combination of these items, including any combination of single or plural items. For example, at least one (item) of a, b, or c can represent: a, b, c, "a and b", "a and c", "b and c", or "a and b and c", where a, b, and c can be single or multiple.

[0159] In the several embodiments provided in this application, it should be understood that the disclosed apparatus and methods can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative; for instance, the division of the units described above is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be through some interfaces; the indirect coupling or communication connection between apparatuses or units may be electrical, mechanical, or other forms.

[0160] The units described above as separate components may or may not be physically separate. The components shown 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 units can be selected to achieve the purpose of this embodiment according to actual needs.

[0161] Furthermore, the functional units in the various embodiments of this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.

[0162] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes multiple instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods of the various embodiments of this application. The aforementioned storage medium includes various media capable of storing programs, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.

[0163] The preferred embodiments of the present application have been described above with reference to the accompanying drawings, but this does not limit the scope of the claims of the present application. Any modifications, equivalent substitutions, and improvements made by those skilled in the art without departing from the scope and substance of the embodiments of the present application shall be within the scope of the claims of the present application.

Claims

1. A task execution method, characterized in that, The method includes: The target thread is created through the first task executor, and the target execution interface is called through the target thread. A target process is created based on the invoked target execution interface, and the task script of the target task is executed through the target process; wherein, the task script has a script execution duration; In response to the shutdown operation of the first task executor after a preset duration, the target thread is released and the second task executor is started; wherein, the preset duration is less than the script execution duration; The execution status of the task script is obtained through the target process, and the execution status is stored in the target message queue according to the target task; The execution status is obtained from the target message queue through the second task executor.

2. The method according to claim 1, characterized in that, The step of storing the execution status to the target message queue according to the target task includes: The execution state is encapsulated to obtain a status message; The preset message queue is filtered according to the target task to obtain the target message queue; The status message is stored in the target message queue.

3. The method according to claim 2, characterized in that, The step of filtering the preset message queue according to the target task to obtain the target message queue includes: Obtain the task priority of the target task; The preset message queue is first filtered according to the task priority to obtain a reference message queue; Obtain the number of queues in the reference message queue; The load factor of the reference message queue is obtained based on the number of queues; The reference message queue is filtered a second time based on the load coefficient to obtain the target message queue.

4. The method according to claim 3, characterized in that, The step of obtaining the load factor of the reference message queue based on the queue quantity includes: Obtain the queue length, queue processing speed, and queue resource utilization of the reference message queue; Calculate the average waiting time based on the queue length and the queue processing speed; The load factor is calculated based on the average waiting time and the queue resource utilization rate.

5. The method according to claim 4, characterized in that, The calculation of the load coefficient based on the average waiting time and the queue resource utilization includes: Obtain the task complexity of the target task and determine the current time period; The weight parameters are determined based on the task complexity and the current time period. The load coefficient is obtained by weighting the average waiting time and the queue resource utilization rate according to the weight parameters.

6. The method according to claim 3, characterized in that, The step of performing a second filtering on the reference message queue based on the load coefficient to obtain the target message queue includes: The reference message queues are filtered according to the load coefficient to obtain selected message queues; wherein, the selected message queues include message partitions; Calculate the target load of the message partition, and calculate the load difference between the message partitions based on the target load; The selected message queue is partitioned and expanded according to the load difference to obtain the target message queue.

7. The method according to claim 2, characterized in that, The target message queue includes a reference partition, and storing the status message in the target message queue includes: The status message is hashed to obtain a hash value; The reference partition is filtered based on the hash value to obtain the target partition; The status message is stored in the target partition.

8. A task execution device, characterized in that, The device includes: The calling module is used to create a target thread through the first task executor and call the target execution interface through the target thread. An execution module is used to create a target process based on the invoked target execution interface, and execute the task script of the target task through the target process; wherein, the task script has a script execution duration; A response module is configured to respond to the shutdown operation of the first task executor within a preset duration, release the target thread, and start the second task executor; wherein the preset duration is less than the script execution duration; The storage module is used to obtain the execution status of the task script through the target process and store the execution status to the target message queue according to the target task; The acquisition module is used to acquire the execution status from the target message queue through the second task executor.

9. An electronic device, characterized in that, The electronic device includes a memory and a processor, the memory storing a computer program, and the processor executing the computer program to implement the method according to any one of claims 1 to 7.

10. A computer-readable storage medium storing a computer program, characterized in that, When the computer program is executed by a processor, it implements the method described in any one of claims 1 to 7.