A method for executing asynchronous tasks

By obtaining the number of failures and initial priority of the task, dynamically adjusting the target priority of the task, solving the problem of failure of tasks and inability to retry and waste of resources during asynchronous task execution, realizing the timely processing of tasks and rational utilization of resources.

CN114090207BActive Publication Date: 2025-07-18SUNSHINE PROPERTY & CASUALTY INSURANCE CO
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202111381805.1
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-11-19
Publication Date
2025-07-18
Estimated Expiration
2041-11-19

AI Technical Summary

Technical Problem

When performing asynchronous tasks, the existing technology cannot effectively monitor the task execution status, resulting in the task failure and retrying, and the task execution order cannot be optimized, resulting in waste of resources and untimely processing.

Method used

By obtaining the number of failures and initial priority of the task, dynamically adjust the target priority of the task, filter out different types of task collections, and sort and lock processing based on the number of failures and initial priority, ensuring that emergency tasks are processed in a timely manner and avoid resource waste.

Benefits of technology

The execution order of tasks is optimized to ensure that emergency tasks are processed in a timely manner, avoid resource waste when tasks fail, and improve the rational use of system resources.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114090207B_ABST
    Figure CN114090207B_ABST
Patent Text Reader

Abstract

This application belongs to the field of computer technology, and discloses a method, device, electronic device and readable storage medium for asynchronous task execution. The method includes obtaining the failure times and initial priorities of each task in the set of tasks to be processed respectively, where the set of tasks to be processed contains at least one task; determining the target priority of each task respectively according to the failure times and initial priorities of the tasks in the set of tasks to be processed; and performing a task processing operation according to the target priorities of the tasks in the set of tasks to be processed. In this way, the execution order of tasks can be optimized when executing asynchronous tasks.
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 more particularly, to methods, devices, electronic devices, and readable storage media for asynchronous task execution. Background Art

[0002] With the rapid development of Internet technology, the interaction between server systems has become increasingly frequent, and the processed services have become more and more complex. In the case of low real-time requirements and long task execution times, asynchronous execution methods are usually used to execute tasks.

[0003] In the prior art, when executing asynchronous tasks, threads and a simple task list are usually used to process tasks.

[0004] Among them, when using threads to execute tasks, the tasks cannot be monitored, and if the execution fails, they cannot be executed again. And when using a simple task list to execute tasks, some tasks cannot be processed in time, or even cannot be processed at all.

[0005] Therefore, when executing asynchronous tasks, how to optimize the execution order of tasks is a technical problem that needs to be solved. Summary of the Invention

[0006] The purpose of the embodiments of this application is to provide methods, devices, electronic devices, and readable storage media for asynchronous task execution, so as to optimize the execution order of tasks when executing asynchronous tasks.

[0007] On the one hand, a method for asynchronous task execution is provided, including:

[0008] Obtain the failure times and initial priorities of each task in the set of tasks to be processed respectively, where the set of tasks to be processed contains at least one task;

[0009] Determine the target priority of each task respectively according to the failure times and initial priorities of the tasks in the set of tasks to be processed;

[0010] Execute task processing operations according to the target priorities of the tasks in the set of tasks to be processed.

[0011] In the above implementation process, according to the failure times and initial priorities of the tasks, the target priorities of the tasks are determined, and the target priorities of the tasks are dynamically adjusted according to the failure times, optimizing the execution order of the tasks.

[0012] In one implementation, determining the target priority of each task respectively according to the failure times and initial priorities of the tasks in the set of tasks to be processed includes:

[0013] From the set of tasks to be processed, filter out the first tasks whose failure times are lower than the first preset number threshold to obtain the first task set;

[0014] Respectively determine the initial priority of each first task in the first task set as the target priority of the corresponding first task;

[0015] From the set of tasks to be processed, filter out the second tasks that meet the first preset filtering conditions to obtain the second task set;

[0016] Sort each second task in the second task set according to the failure times and initial priorities of each second task;

[0017] Determine the target priority of each second task according to the sorting of each second task, where the target priority of each second task is higher than the target priority of each first task;

[0018] From the set of tasks to be processed, filter out the third tasks that meet the second preset filtering conditions to obtain the third task set;

[0019] Set the target priority of each third task in the third task set to the specified priority. In the above implementation process, the target priority of the task is determined according to the failure times of the task, so that the target priority of the task can be dynamically adjusted according to the failure times of the task.

[0020] In one implementation, sorting each second task in the second task set according to the failure times and initial priorities of each second task includes:

[0021] Sort each second task in the second task set according to the failure times of each second task;

[0022] If there are at least two second tasks with the same failure times, then adjust the sorting of the at least two second tasks according to the initial priorities of the at least two second tasks.

[0023] In the above implementation process, if there are tasks with the same failure times, then determine the target priorities of the tasks with the same failure times according to the initial priorities of the tasks, and sort according to the target priorities.

[0024] In one implementation, filtering out the second tasks that meet the first preset filtering conditions from the set of tasks to be processed to obtain the second task set includes:

[0025] From the set of tasks to be processed, filter out the first failed tasks whose failure times are not less than the first preset number threshold and less than the second preset number threshold, and filter out the second failed tasks whose failure times are not less than the second preset number threshold and less than the third preset number threshold;

[0026] Determine the decay time of each second failed task respectively according to the number of failures of each second failed task;

[0027] Obtain the failure duration of each second failed task respectively, where the failure duration is the duration between the failure time point when the second failed task is executed unsuccessfully and the current time point;

[0028] From the filtered second failed tasks, filter out the third failed tasks whose corresponding failure duration is not less than the corresponding decay time;

[0029] Determine the filtered first failed tasks and third failed tasks as the second tasks, and obtain the second task set.

[0030] In the above implementation process, set the decay time according to the number of failures of the task, avoid the task from executing in a loop all the time, and improve the utilization of system resources.

[0031] In one implementation manner, filter out the third tasks that meet the second preset filtering condition from the to-be-processed task set, and obtain the third task set, including:

[0032] Filter out the third tasks whose corresponding failure duration is lower than the corresponding decay time from the filtered second failed tasks, and obtain the third task set.

[0033] In the above implementation process, obtain the third task set according to the tasks whose failure duration is lower than the corresponding decay time.

[0034] In one implementation manner, obtain the number of failures and the initial priority of each task in the to-be-processed task set respectively, and further include:

[0035] If it is determined that there are fourth tasks in the to-be-processed task set whose number of failures is not less than the third preset number threshold, then move each fourth task from the to-be-processed task set to the failure set;

[0036] Based on the tasks moved to the failure set, send a task exception warning notification.

[0037] In the above implementation process, when the number of failures of the task reaches the third preset number threshold, move the task to the failure set, which requires manual intervention to avoid wasting system resources.

[0038] In one implementation manner, perform task processing operations according to the target priorities of the tasks in the to-be-processed task set, including:

[0039] Filter out the target priorities of the tasks that are not locked from the to-be-processed task set;

[0040] Determine the highest priority among the target priorities of the filtered tasks;

[0041] Lock the task corresponding to the highest priority;

[0042] Execute the task corresponding to the highest priority;

[0043] After determining that the task corresponding to the highest priority is completed, unlock the task corresponding to the highest priority.

[0044] In the above implementation process, select the task with the highest priority from the tasks that have not been locked, and lock it. After the task is completed, unlock the task to prevent the task from being executed repeatedly.

[0045] On the one hand, a device for executing asynchronous tasks is provided, including:

[0046] An acquisition unit, configured to respectively acquire the failure times and initial priorities of each task in the set of tasks to be processed, where the set of tasks to be processed includes at least one task;

[0047] A setting unit, configured to respectively determine the target priority of each task according to the failure times and initial priorities of the tasks in the set of tasks to be processed;

[0048] An execution unit, configured to perform a task processing operation according to the target priorities of the tasks in the set of tasks to be processed.

[0049] In one implementation, the setting unit is specifically configured to:

[0050] Screen out the first tasks with failure times lower than the first preset number threshold from the set of tasks to be processed, and obtain a first task set;

[0051] Respectively determine the initial priority of each first task in the first task set as the target priority of the corresponding first task;

[0052] Screen out the second tasks that meet the first preset screening condition from the set of tasks to be processed, and obtain a second task set;

[0053] Sort the second tasks according to the failure times and initial priorities of the second tasks in the second task set;

[0054] According to the sorting of the second tasks, determine the target priorities of the second tasks, where the target priority of each second task is higher than the target priorities of the first tasks;

[0055] Screen out the third tasks that meet the second preset screening condition from the set of tasks to be processed, and obtain a third task set;

[0056] Set the target priority of each third task in the third task set to a specified priority.

[0057] In one implementation, the setting unit is further configured to:

[0058] Sort the second tasks according to the failure times of the second tasks in the second task set;

[0059] If there are at least two second tasks with the same failure times, adjust the sorting of the at least two second tasks according to the initial priorities of the at least two second tasks.

[0060] In one implementation, the setting unit is specifically configured to:

[0061] Screen out first failed tasks from the set of tasks to be processed, where the failure times of the first failed tasks are not less than a first preset number threshold and less than a second preset number threshold, and screen out second failed tasks with failure times not less than the second preset number threshold and less than a third preset number threshold;

[0062] Determine the decay time of each second failed task respectively according to the failure times of the second failed tasks;

[0063] Obtain the failure duration of each second failed task respectively, where the failure duration is the duration between the failure time point when the second failed task fails and the current time point;

[0064] Screen out third failed tasks from the screened second failed tasks, where the corresponding failure durations of the third failed tasks are not less than the corresponding decay times;

[0065] Determine the screened first failed tasks and third failed tasks as second tasks to obtain a second task set.

[0066] In one implementation, the setting unit is further configured to:

[0067] Screen out third tasks from the screened second failed tasks, where the corresponding failure durations of the third tasks are not less than the corresponding decay times, to obtain a third task set.

[0068] In one implementation, the obtaining unit is further configured to:

[0069] If it is determined that there are fourth tasks in the set of tasks to be processed with failure times not less than the third preset number threshold, move each fourth task from the set of tasks to be processed to the failure set;

[0070] Based on the movement to the failure set, send out a task exception warning notification.

[0071] In one implementation, the execution unit is specifically configured to:

[0072] Screen out the target priorities of the tasks that are not locked from the set of tasks to be processed;

[0073] Determine the highest priority among the target priorities of each task selected by screening;

[0074] Lock the task corresponding to the highest priority;

[0075] Execute the task corresponding to the highest priority;

[0076] After determining that the task corresponding to the highest priority has been executed, unlock the task corresponding to the highest priority.

[0077] On the one hand, an electronic device is provided, including a processor and a memory. The memory stores computer-readable instructions. When the computer-readable instructions are executed by the processor, the steps of the method provided in any of the various optional implementation manners of the asynchronous task execution described above are run.

[0078] On the one hand, a readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the steps of the method provided in any of the various optional implementation manners of the asynchronous task execution described above are run.

[0079] In the method, device, electronic device, and readable storage medium for asynchronous task execution provided by the embodiments of the present application, the failure times and initial priorities of each task in the set of tasks to be processed are respectively obtained, where the set of tasks to be processed contains at least one task; according to the failure times and initial priorities of the tasks in the set of tasks to be processed, the target priority of each task is respectively determined; according to the target priorities of the tasks in the set of tasks to be processed, a task processing operation is executed. In this way, when executing an asynchronous task, according to the failure times and initial priorities of the tasks, the target priority of the tasks is determined, and according to the failure times, the target priority of the tasks is dynamically adjusted, the execution order of the tasks is optimized, and the reasonable utilization of system resources is improved.

[0080] Other features and advantages of the present application will be described in the following specification, and, in part, will be obvious from the specification, or will be understood by implementing the present application. The objectives and other advantages of the present application can be realized and obtained by the structures specifically pointed out in the written specification, claims, and drawings. BRIEF DESCRIPTION OF THE DRAWINGS

[0081] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the following will briefly introduce the drawings required to be used in the embodiments of the present application. It should be understood that the following drawings only show some embodiments of the present application, and therefore should not be regarded as limiting the scope. For those of ordinary skill in the art, other related drawings can be obtained based on these drawings without creative efforts.

[0082] Figure 1A schematic diagram of an application scenario for asynchronous task execution provided by an embodiment of the present application;

[0083] Figure 2 A flowchart of an embodiment of a method for asynchronous task execution provided by an embodiment of the present application;

[0084] Figure 3 A detailed flowchart of an embodiment of a method for asynchronous task execution provided by an embodiment of the present application;

[0085] Figure 4 A schematic diagram of the structure of a device for asynchronous task execution provided by an embodiment of the present application;

[0086] Figure 5 A schematic diagram of the structure of an electronic device in an embodiment of the implementation manner of the present application. Specific implementation manner

[0087] Next, the technical solutions in the embodiments of the present application will be clearly and completely described in conjunction with the accompanying drawings in the embodiments of the present application. Obviously, the described embodiments are only a part of the embodiments of the present application, rather than all the embodiments. Usually, the components of the embodiments of the present application described and illustrated in the accompanying drawings here can be arranged and designed in various different configurations. Therefore, the following detailed description of the embodiments of the present application provided in the accompanying drawings is not intended to limit the scope of the present application to be protected, but only represents the selected embodiments of the present application. All other embodiments obtained by those skilled in the art based on the embodiments of the present application without creative efforts fall within the scope of protection of the present application.

[0088] It should be noted that: similar reference numerals and letters denote similar items in the following drawings. Therefore, once an item is defined in one drawing, it does not need to be further defined and explained in subsequent drawings. At the same time, in the description of the present application, the terms "first", "second", etc. are only used for distinguishing descriptions and cannot be understood as indicating or implying relative importance.

[0089] First, some terms involved in the embodiments of the present application will be described to facilitate the understanding of those skilled in the art.

[0090] Terminal device: It can be a mobile terminal, a fixed terminal or a portable terminal, such as a mobile phone, a site, a unit, a device, a multimedia computer, a multimedia tablet, an Internet node, a communicator, a desktop computer, a laptop computer, a notebook computer, a netbook computer, a tablet computer, a personal communication system device, a personal navigation device, a personal digital assistant, an audio / video player, a digital camera / video camera, a positioning device, a TV receiver, a radio broadcast receiver, an e-book device, a gaming device or any combination thereof, including accessories and peripherals of these devices or any combination thereof. It is also foreseeable that the terminal device can support any type of interface for users (such as wearable devices), etc.

[0091] Server: It can be an independent physical server, or a server cluster or distributed system composed of multiple physical servers, or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, and big data and artificial intelligence platforms.

[0092] Polling: It is a way for the central processing unit to provide services to peripheral devices. The central processing unit sequentially asks each peripheral device whether it needs its service. If so, it provides the service. After the service is completed, it asks the next peripheral, and so on.

[0093] Locking: A process controls that a shared resource cannot be accessed by other processes.

[0094] Thread: It is the smallest unit that the operating system can perform operation scheduling.

[0095] Message queue: It is a container that stores messages during the transmission of messages.

[0096] In order to improve the reasonable utilization of system resources when executing asynchronous tasks, the embodiments of the present application provide a method, device, electronic device and readable storage medium for executing asynchronous tasks.

[0097] Refer to Figure 1 As shown, it is a schematic diagram of an application scenario for executing asynchronous tasks provided by the embodiments of the present application. This application scenario includes a scheduling control center and a server.

[0098] Optionally, the server can be a terminal device. Figure 1 In this case, only two devices are taken as an example for the server, that is, server 1 and server 2. In actual applications, the number of servers can be one or more, which is not limited here.

[0099] Among them, the scheduling control center is used to: schedule the server to execute tasks through second-level polling.

[0100] The server is used to: respectively obtain the failure times and initial priorities of each task in the set of tasks to be processed, and determine the target priority of each task according to the failure times and initial priorities of the tasks in the set of tasks to be processed, and perform task processing operations according to the target priorities of the tasks.

[0101] In one implementation, the scheduling control center schedules the server to execute tasks by second-level polling. The server obtains the failure times and initial priorities of each task in the set of tasks to be processed, filters out the first tasks whose failure times are lower than the first preset number threshold from the set of tasks to be processed to form a first task set, and determines the initial priority of the first task as the target priority of the corresponding first task. From the set of tasks to be processed, filter out the first failed tasks whose failure times are not lower than the first preset number threshold and lower than the second preset number threshold, and the third failed tasks whose failure times are not lower than the second preset number threshold and lower than the third preset number threshold and whose failure duration is not lower than the corresponding decay time, and determine them as the second tasks, and sort the second tasks according to their failure times. If there are second tasks with the same failure times, the second task with the higher initial priority also has a higher target priority. From the filtered second failed tasks, filter out the third tasks whose corresponding failure durations are lower than the corresponding decay time, and set the target priority of each third task to the lowest priority. If it is determined that there are fourth tasks in the set of tasks to be processed whose failure times are not lower than the third preset number threshold, move each fourth task from the set of tasks to be processed to the failure set, and send a task exception alarm notification. From the set of tasks to be processed, filter out the target priorities of the tasks that are not locked, select the highest priority among the filtered target priorities of the tasks, lock the task, execute the task, and unlock the task after the task execution is completed.

[0102] In this way, when executing asynchronous tasks, the target priority of the task can be determined according to the failure times and initial priorities of the task, and the target priority of the task can be dynamically adjusted according to the failure times, so that each task in the task list can be executed. By setting the task decay time, it is avoided that the system resources are wasted when the task always fails to execute, and the reasonable utilization of the system resources is improved.

[0103] In the embodiments of the present application, only the server is taken as an example of the execution entity for illustration. In practical applications, the execution entity can also be other electronic devices such as terminal devices, which is not limited herein.

[0104] Refer to Figure 2 As shown, it is a flowchart of the implementation of a method for executing asynchronous tasks provided by the embodiments of the present application. The specific implementation process of this method is as follows:

[0105] Step 200: Obtain the failure times and initial priorities of each task in the set of tasks to be processed respectively.

[0106] Specifically, obtain the failure times and initial priorities of each task in the set of tasks to be processed respectively. Among them, the set of tasks to be processed contains at least one task.

[0107] Among them, the set of tasks to be processed contains at least one task.

[0108] Optionally, the failure times of each task can be obtained by manual input, or can be obtained by detecting the current failure times of the task in real time.

[0109] In practical applications, the failure times of tasks can also be obtained by other means, which are not limited here.

[0110] Among them, the tasks can be submitted by the business system. The tasks can include business-related names, business types, system sources, and maximum failure times, etc. The tasks can be local tasks or can be remote callback tasks.

[0111] Optionally, the server can implement the callback processing of tasks through the callback interface.

[0112] Optionally, if the task is a system task, the priority of the task is set by the system. If the task is a task processed by a module, the priority of the task is set manually.

[0113] In practical applications, the setting of the priority of tasks can be set according to the actual application situation, which is not limited here.

[0114] Among them, the initial priority is set in advance.

[0115] In this way, the failure times and initial priorities of each task in the set of tasks to be processed can be obtained.

[0116] Furthermore, if it is determined that there is a fourth task in the set of tasks to be processed whose failure times are not less than the third preset number threshold, then move each fourth task from the set of tasks to be processed to the failure set, and based on the movement to the failure set, issue a task exception warning notification.

[0117] Specifically, screen each task in the set of tasks to be processed. If it is determined that there is a fourth task whose failure times are not less than the third preset number threshold, then move each fourth task from the set of tasks to be processed to the failure set. After moving the fourth task whose failure times are not less than the third preset number threshold from the set of tasks to be processed to the failure set, issue a warning notification of task exception.

[0118] Among them, the fourth task in the failure set requires manual intervention and processing operations.

[0119] In practical applications, the third preset number threshold can be set according to the actual application situation, and no limitation is imposed here.

[0120] In this way, tasks with a relatively large number of failures can be moved from the set of tasks to be processed to the failure set, avoiding the continuous execution of the task and improving the reasonable utilization of system resources.

[0121] Step 201: Determine the target priority of each task according to the failure times and initial priorities of the tasks in the set of tasks to be processed.

[0122] Specifically, to execute Step 201, the following steps can be adopted:

[0123] S2011: From the set of tasks to be processed, screen out the first tasks whose failure times are lower than the first preset number threshold to obtain the first task set.

[0124] Specifically, from the set of tasks to be processed, screen out the first tasks that have been executed before and whose failure times are lower than the first preset number threshold, and form these first tasks into the first task set.

[0125] Among them, the failure times of each task in the set of tasks to be processed can be compared with the first preset number threshold to screen out the first tasks whose failure times are lower than the first preset number threshold.

[0126] In practical applications, screening can also be performed by other methods, and no limitation is imposed here.

[0127] In practical applications, the first preset number threshold can be set according to the actual application situation, and no limitation is imposed here.

[0128] In this way, the first task set can be obtained by screening out the first tasks whose failure times are lower than the first preset number threshold.

[0129] S2012: Determine the initial priority of each first task in the first task set as the corresponding target priority of the first task.

[0130] Specifically, determine the initial priority of each first task in the previously obtained first task set as the target priority of the corresponding first task.

[0131] S2013: From the set of tasks to be processed, screen out the second tasks that meet the first preset screening condition to obtain the second task set.

[0132] Specifically, to execute Step S2013, the following steps can be adopted:

[0133] Step 1: From the set of tasks to be processed, screen out the first failed tasks whose number of failure times is not less than the first preset number threshold and less than the second preset number threshold, and screen out the second failed tasks whose number of failure times is not less than the second preset number threshold and less than the third preset number threshold.

[0134] Specifically, from the set of tasks to be processed, screen out the first failed tasks whose number of failure times is not less than the first preset number threshold and less than the second preset number threshold, and the second failed tasks whose number of failure times is not less than the second preset number threshold and less than the third preset number threshold.

[0135] Among them, screening can be carried out by comparison or other methods, which is not limited here.

[0136] In practical applications, the first preset number threshold can be set according to the actual application situation, which is not limited here.

[0137] In practical applications, the second preset number threshold can be set according to the actual application situation, which is not limited here.

[0138] Step 2: According to the number of failure times of each second failed task, determine the decay time of each second failed task respectively.

[0139] Specifically, according to the number of failure times of each second failed task, determine the decay time of each second failed task respectively. Different numbers of failure times of the second task correspond to different set decay times.

[0140] Among them, the decay time is the task stop execution time, and the decay time is determined according to the number of failure times of the third task.

[0141] In one implementation, the decay time can be 1 minute, 3 minutes, 5 minutes, 15 minutes, 50 minutes, 5 hours, etc.

[0142] In practical applications, the decay time can be set according to the actual application situation, which is not limited here.

[0143] Step 3: Obtain the failure duration of each second failed task respectively.

[0144] Among them, the failure duration is the duration between the failure time point when the second failed task is executed unsuccessfully and the current time point.

[0145] Step 4: From the screened second failed tasks, screen out the third failed tasks whose corresponding failure duration is not less than the corresponding decay time.

[0146] Specifically, from the second failed tasks screened out, the duration between the failure time point when the corresponding second failed task failed and the current time point is not less than the corresponding decaying task, and it is determined as the third failed task, that is, the task has passed the decay time.

[0147] Step Five: Determine the first failed tasks and the third failed tasks screened out as the second tasks, and obtain the second task set.

[0148] S2014: Sort each second task according to the failure times and the initial priorities of the second tasks in the second task set.

[0149] Specifically, to execute step S2014, the following steps can be adopted:

[0150] Step One: Sort each second task according to the failure times of the second tasks in the second task set.

[0151] Specifically, according to the failure times of the second tasks in the second task set, sort each second task in the second task set according to the failure times.

[0152] In one implementation, according to the failure times of each second task in the second task set, sort each second task in the second task set from more to less failure times, and obtain a second task sequence queue with failure times from more to less.

[0153] In one implementation, there are three second tasks in the second task set, and the failure times of the three second tasks are 1, 2, and 3 respectively. Sort the three second tasks in the second task set according to the failure times, and obtain a second task sequence queue with failure times from more to less, that is, the task with a failure time of 3 is ranked at the front, the task with a failure time of 2 is ranked behind the task with a failure time of 3, and the task with a failure time of 1 is ranked at the end.

[0154] Step Two: If there are at least two second tasks with the same failure times, adjust the sorting of the at least two second tasks according to the initial priorities of the at least two second tasks.

[0155] Specifically, when sorting each second task according to the number of failures of each second task in the second task set, the target priority of the second task with more failure times is higher than the target priority of the second task with fewer failure times, that is, the target priority is positively correlated with the number of failures. If there are at least two second tasks with the same number of failures, then compare the initial priorities of the at least two second tasks, and sort the at least two second tasks according to the initial priorities of the at least two second tasks. The target priority of the second task with a higher initial priority is higher than the target priority of the second task with a lower initial priority, that is, the target priority is positively correlated with both the number of failures and the initial priority.

[0156] Among them, the target priority is positively correlated with both the number of failures and the initial priority.

[0157] In an implementation manner, the two second tasks are A and B respectively. The number of failures of the two second tasks is the same. The initial priority of A is 8, and the initial priority of B is 5. Then the target priority of A is higher than the target priority of B.

[0158] S2015: Determine the target priority of each second task according to the sorting of each second task.

[0159] Specifically, determine the target priority of each second task according to the queuing order of each second task. Among them, the target priority of each second task is higher than the target priority of each first task.

[0160] In an implementation manner, determine the target priority of each second task according to the sorting of each second task. The more the number of failures of the second task, the higher the target priority of the second task.

[0161] In an implementation manner, there are three first tasks in the first task set. In the second task set, there are five second tasks. The target priorities of the five second tasks are all higher than the target priorities of the three first tasks.

[0162] S2016: Screen out the third tasks that meet the second preset screening conditions from the set of tasks to be processed to obtain the third task set.

[0163] Optionally, it is possible to screen out the third tasks with corresponding failure durations lower than the corresponding decay times from the screened second failed tasks to obtain the third task set.

[0164] Specifically, screen out the third tasks with corresponding failure durations lower than the corresponding decay times from the screened second failed tasks, so as to obtain the third task set.

[0165] S2017: Set the target priority of each third task in the third task set to the specified priority.

[0166] Among them, the specified priority is the lowest priority.

[0167] Furthermore, for each third task, the priority of the third task whose failure duration is not less than the corresponding decay time first is the highest.

[0168] Step 202: Perform task processing operations according to the target priorities of the tasks in the task set to be processed.

[0169] Specifically, to execute Step 202, the following steps can be executed:

[0170] S2021: From the task set to be processed, filter out the target priorities of the tasks that are not locked.

[0171] Specifically, judge each task from the task set to be processed to determine whether the task is locked. If so, record a log; otherwise, filter out the tasks that are not locked and obtain the target priorities of the above-mentioned tasks that are not locked.

[0172] Among them, the log can be the locked tasks recorded.

[0173] It should be noted that after a task is locked, other servers or terminals in the distributed scheduling system will not be able to perform execution operations on this task.

[0174] S2022: Determine the highest priority among the target priorities of the filtered tasks.

[0175] Specifically, compare the target priorities of the filtered tasks that are not locked pairwise to determine the highest priority among the target priorities of the tasks.

[0176] S2023: Lock the task corresponding to the highest priority.

[0177] Specifically, perform a locking operation on the task corresponding to the highest priority.

[0178] S2024: Execute the task corresponding to the highest priority.

[0179] S2025: After determining that the task corresponding to the highest priority has been executed, unlock the task corresponding to the highest priority.

[0180] Specifically, if the task corresponding to the highest priority has been executed, then perform an unlocking operation on the task corresponding to the highest priority.

[0181] Furthermore, after the task corresponding to the highest priority has been executed, obtain the task execution result. If the task execution result indicates that the task has been executed successfully, modify the task status; otherwise, record the failure information.

[0182] Specifically, if the task execution result indicates that the task is successfully executed, the status of the task is changed from unexecuted to executed; otherwise, the failure information of the task is recorded.

[0183] Among them, the failure information can be the cause of failure, the number of failures, etc.

[0184] When the traditional execution field waits for services, generally a thread is started to execute the task. The task execution cannot be monitored, and it cannot be retried if it fails. Traditionally, the message queue method can also be used, which requires a complete set of cluster support, increasing the difficulty and cost of operation and maintenance. In addition, a simple task table can be used, which cannot execute tasks distributively and adjust priorities dynamically.

[0185] In the embodiments of the present application, when executing an asynchronous task, the application is in a distributed scheduling system to implement distributed task execution. According to the number of task failures and the initial priority, the execution order of the tasks is determined, and the target priority of the task is dynamically adjusted according to the number of failures, so that urgent tasks can be processed in time. Since it is applied to distributed system scheduling and multiple devices execute in parallel, a large number of tasks can be processed, so that tasks with lower priorities can also be processed in time, optimizing the execution order of tasks, and enabling tasks to be processed in quasi-real time. By setting the task decay time, it is avoided that the system resources are wasted when the task has been executed and failed all the time, improving the user experience, making the system resources be reasonably used, and improving the utilization rate of system resources.

[0186] Refer to Figure 3 As shown, it is a detailed implementation flowchart of a method for executing an asynchronous task provided by the embodiments of the present application, including:

[0187] Step 300: The server respectively obtains the target priorities of each task.

[0188] Step 301: The server determines whether the set of tasks to be processed is empty. If so, step 312 is executed; otherwise, step 302 is executed.

[0189] Step 302: The server filters out the target priorities of the tasks that are not locked from the set of tasks to be processed.

[0190] Step 303: The server determines the highest priority among the target priorities of the filtered tasks.

[0191] Step 304: The server locks the task corresponding to the highest priority.

[0192] Step 305: The server determines whether the task is a local task of the server. If so, step 306 is executed; otherwise, step 307 is executed.

[0193] Step 306: The server executes the task corresponding to the highest priority.

[0194] Step 307: The server remotely calls back the task.

[0195] Step 308: After the server determines that the task corresponding to the highest priority has been completed, it obtains the task execution result and unlocks the task corresponding to the highest priority.

[0196] Step 309: The server determines whether the task corresponding to the highest priority is executed successfully. If so, it executes Step 310; otherwise, it executes Step 311.

[0197] Step 310: The server modifies the task status of the task.

[0198] Step 311: The server records the failure information.

[0199] It should be noted that after Step 311 is executed, Step 302 is executed.

[0200] Step 312: The server task execution ends.

[0201] Specifically, when executing Steps 300 - 312, for the specific steps, refer to the above Steps 200 - 202, which will not be elaborated here.

[0202] Based on the same inventive concept, an apparatus for asynchronous task execution is also provided in an embodiment of the present application. Since the principle of solving problems by the above apparatus and device is similar to that of a method for asynchronous task execution, therefore, for the implementation of the above apparatus, refer to the implementation of the method, and the repeated parts will not be elaborated.

[0203] Refer to Figure 4 As shown, it is a schematic structural diagram of an apparatus for asynchronous task execution provided by an embodiment of the present application, including:

[0204] On the one hand, an apparatus for asynchronous task execution is provided, including:

[0205] An acquisition unit 400, configured to respectively acquire the failure times and initial priorities of each task in the set of tasks to be processed, where the set of tasks to be processed includes at least one task;

[0206] A setting unit 401, configured to respectively determine the target priority of each task according to the failure times and initial priorities of the tasks in the set of tasks to be processed;

[0207] An execution unit 402, configured to perform task processing operations according to the target priorities of the tasks in the set of tasks to be processed.

[0208] In an implementation manner, the setting unit 401 is specifically configured to:

[0209] From the set of tasks to be processed, filter out the first tasks whose failure times are lower than the first preset number threshold to obtain a first task set;

[0210] Respectively determine the initial priority of each first task in the first task set as the target priority of the corresponding first task;

[0211] From the set of tasks to be processed, filter out the second tasks that meet the first preset filtering condition to obtain a second task set;

[0212] Sort the second tasks according to the failure times and initial priorities of the second tasks in the second task set;

[0213] Determine the target priority of each second task according to the sorting of the second tasks, where the target priority of each second task is higher than the target priority of each first task;

[0214] From the set of tasks to be processed, filter out the third tasks that meet the second preset filtering condition to obtain a third task set;

[0215] Set the target priority of each third task in the third task set to the specified priority.

[0216] In one implementation, the setting unit 401 is further configured to:

[0217] Sort the second tasks according to the failure times of the second tasks in the second task set;

[0218] If there are at least two second tasks with the same failure time, adjust the sorting of the at least two second tasks according to the initial priorities of the at least two second tasks.

[0219] In one implementation, the setting unit 401 is specifically configured to:

[0220] From the set of tasks to be processed, filter out the first failed tasks whose failure times are not lower than the first preset number threshold and lower than the second preset number threshold, and filter out the second failed tasks whose failure times are not lower than the second preset number threshold and lower than the third preset number threshold;

[0221] Respectively determine the decay time of each second failed task according to the failure time of each second failed task;

[0222] Respectively obtain the failure duration of each second failed task, where the failure duration is the duration between the failure time point when the second failed task fails and the current time point;

[0223] From the filtered second failed tasks, filter out the third failed tasks whose corresponding failure durations are not lower than the corresponding decay times;

[0224] Determine the first failed task and the third failed task selected as the second task, and obtain a second task set.

[0225] In one implementation, the setting unit 401 is further configured to:

[0226] From the second failed tasks selected, select the third tasks whose corresponding failure duration is not less than the corresponding decay time, and obtain the third task set.

[0227] In one implementation, the obtaining unit 400 is further configured to:

[0228] If it is determined that there are fourth tasks in the to-be-processed task set whose failure times are not less than the third preset number threshold, move each fourth task from the to-be-processed task set to the failure set;

[0229] Based on the tasks moved to the failure set, send a task exception alarm notification.

[0230] In one implementation, the execution unit 402 is specifically configured to:

[0231] From the to-be-processed task set, screen out the target priorities of the tasks that are not locked;

[0232] Determine the highest priority among the target priorities of the tasks screened out;

[0233] Lock the task corresponding to the highest priority;

[0234] Execute the task corresponding to the highest priority;

[0235] After determining that the task corresponding to the highest priority is executed, unlock the task corresponding to the highest priority.

[0236] In the method, device, electronic device, and readable storage medium for asynchronous task execution provided by the embodiments of the present application, the failure times and initial priorities of each task in the to-be-processed task set are respectively obtained, where the to-be-processed task set includes at least one task; according to the failure times and initial priorities of the tasks in the to-be-processed task set, the target priority of each task is respectively determined; according to the target priorities of the tasks in the to-be-processed task set, a task processing operation is performed. In this way, when executing an asynchronous task, according to the failure times and initial priorities of the tasks, the execution order of the tasks is determined, and according to the failure times, the target priorities of the tasks are dynamically adjusted, so that urgent tasks are processed in a timely manner, and a task decay time is set to avoid wasting system resources when tasks keep failing, improving the reasonable utilization of system resources.

[0237] Figure 5The structural schematic diagram of an electronic device 5000 is shown. Refer to Figure 5 As shown, the electronic device 5000 includes: a processor 5010, a memory 5020, a power supply 5030, a display unit 5040, and an input unit 5050.

[0238] The processor 5010 is the control center of the electronic device 5000, connecting each component through various interfaces and circuits, and executing various functions of the electronic device 5000 by running or executing software programs and / or data stored in the memory 5020, thereby monitoring the electronic device 5000 as a whole.

[0239] In the embodiment of the present application, when the processor 5010 calls the computer program stored in the memory 5020, it executes the method for executing asynchronous tasks provided by the embodiment shown in Figure 2 the embodiment shown.

[0240] Optionally, the processor 5010 may include one or more processing units; preferably, the processor 5010 may integrate an application processor and a modem processor. Among them, the application processor mainly processes the operating system, user interface, applications, etc., and the modem processor mainly processes wireless communication. It can be understood that the above modem processor may not be integrated into the processor 5010. In some embodiments, the processor and the memory may be implemented on a single chip, and in some embodiments, they may also be separately implemented on independent chips.

[0241] The memory 5020 may mainly include a program storage area and a data storage area. Among them, the program storage area may store the operating system, various applications, etc.; the data storage area may store data created according to the use of the electronic device 5000, etc. In addition, the memory 5020 may include a high-speed random access memory, and may also include a non-volatile memory, such as at least one magnetic disk storage device, a flash memory device, or other volatile solid-state storage devices, etc.

[0242] The electronic device 5000 further includes a power supply 5030 (such as a battery) for supplying power to each component. The power supply can be logically connected to the processor 5010 through a power management system, so as to manage functions such as charging, discharging, and power consumption through the power management system.

[0243] The display unit 5040 can be used to display information input by the user or information provided to the user, as well as various menus of the electronic device 5000, etc. In the embodiments of the present invention, it is mainly used to display the display interfaces of various applications in the electronic device 5000 and objects such as text and pictures displayed in the display interfaces. The display unit 5040 may include a display panel 5041. The display panel 5041 may be configured in the form of a liquid crystal display (LCD), an organic light-emitting diode (OLED), etc.

[0244] The input unit 5050 can be used to receive information such as numbers or characters input by the user. The input unit 5050 may include a touch panel 5051 and other input devices 5052. Among them, the touch panel 5051, also known as a touch screen, can collect touch operations of the user on or near it (such as operations of the user using a finger, a stylus, or any suitable object or accessory on or near the touch panel 5051).

[0245] Specifically, the touch panel 5051 can detect the user's touch operation, detect the signals brought by the touch operation, convert these signals into contact coordinates, send them to the processor 5010, and receive and execute the commands sent by the processor 5010. In addition, the touch panel 5051 can be implemented in multiple types such as resistive, capacitive, infrared, and surface acoustic wave. The other input devices 5052 may include, but are not limited to, one or more of a physical keyboard, function keys (such as volume control keys, power on / off keys, etc.), a trackball, a mouse, a joystick, etc.

[0246] Of course, the touch panel 5051 can cover the display panel 5041. After the touch panel 5051 detects a touch operation on or near it, it is transmitted to the processor 5010 to determine the type of touch event. Subsequently, the processor 5010 provides a corresponding visual output on the display panel 5041 according to the type of touch event. Although in Figure 5 the touch panel 5051 and the display panel 5041 are implemented as two independent components to realize the input and output functions of the electronic device 5000, in some embodiments, the touch panel 5051 and the display panel 5041 can be integrated to realize the input and output functions of the electronic device 5000.

[0247] The electronic device 5000 may also include one or more sensors, such as a pressure sensor, a gravitational acceleration sensor, a proximity light sensor, etc. Of course, according to the needs in specific applications, the above-mentioned electronic device 5000 may also include other components such as a camera. Since these components are not the key components used in the embodiments of the present application, therefore, in Figure 5It is not shown in [the figure] and will not be elaborated further.

[0248] Those skilled in the art can understand that Figure 5 [The example] is merely an example of an electronic device and does not constitute a limitation on the electronic device. It may include more or fewer components than those shown in the figure, or combine certain components, or have different components.

[0249] In an embodiment of the present application, a readable storage medium stores a computer program. When the computer program is executed by a processor, a communication device can execute each step in the above embodiment.

[0250] For convenience of description, the above parts are divided into respective modules (or units) according to functions and described separately. Of course, when implementing the present application, the functions of the respective modules (or units) can be implemented in the same or multiple software or hardware.

[0251] Those skilled in the art should understand that the embodiments of the present application can be provided as a method, a system, or a computer program product. Therefore, the present application can take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware aspects. Moreover, the present application can take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk memories, CD-ROMs, optical memories, etc.) containing computer-usable program codes.

[0252] The present application is described with reference to the flowcharts and / or block diagrams of methods, devices (systems), and computer program products according to the embodiments of the present application. It should be understood that each flow and / or block in the flowchart and / or block diagram can be implemented by computer program instructions, and the combination of the flows and / or blocks in the flowchart and / or block diagram can also be implemented by computer program instructions. These computer program instructions can be provided to the processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing devices to generate a machine, such that the instructions executed by the processor of the computer or other programmable data processing devices generate a device for implementing the functions specified in Figure 1 one or more flows and / or Figure 1 one or more blocks.

[0253] These computer program instructions can also be stored in a computer-readable memory that can direct a computer or other programmable data processing device to work in a specific manner, such that the instructions stored in the computer-readable memory generate a manufactured article including an instruction device that implements the functions specified in Figure 1 one or more flows and / or Figure 1 one or more blocks.

[0254] These computer program instructions can also be loaded onto a computer or other programmable data processing apparatus, so that a series of operation steps are performed on the computer or other programmable apparatus to produce a computer-implemented process, thereby providing instructions for implementing the process Figure 1 in one process or a plurality of processes and / or blocks Figure 1 or steps for implementing the functions specified in one block or a plurality of blocks.

[0255] Although the preferred embodiments of the present application have been described, additional changes and modifications can be made to these embodiments by those skilled in the art once they learn of the basic creative concept. Therefore, the appended claims are intended to be construed to cover the preferred embodiments as well as all changes and modifications falling within the scope of the present application.

[0256] Obviously, those skilled in the art can make various changes and modifications to the present application without departing from the spirit and scope of the present application. Thus, if these modifications and variations of the present application fall within the scope of the claims of the present application and their equivalent technologies, the present application is also intended to include these modifications and variations.

Claims

1. A method for executing an asynchronous task, characterized in that, Applied to each server in a distributed scheduling system, including: Obtaining the failure times and initial priorities of each task in the set of tasks to be processed respectively, where the set of tasks to be processed contains at least one task; From the set of tasks to be processed, screening out the first tasks with failure times lower than the first preset number threshold to form a first task set, and screening out a second task set and a third task set with failure times not lower than the second preset number threshold and lower than the third preset number threshold, where the second task set is a set composed of at least one task with a failure duration not lower than the corresponding decay time, and the third task set is a set composed of at least one task with a failure duration lower than the corresponding decay time; the first preset number threshold is lower than the second preset number threshold; Determining the initial priority of the first task as the target priority of the corresponding first task, and setting the target priority of each third task in the third task set to the lowest priority; where the target priority of each second task in the second task set is higher than the target priority of each first task; Determining the highest priority among the target priorities of each task, and executing the task corresponding to the highest priority.

2. The method according to claim 1, wherein, The target priority of a task is determined through the following steps: Sorting each second task according to the failure times and initial priorities of each second task in the second task set; Determining the target priorities of each second task according to the sorting of each second task.

3. The method according to claim 2, characterized in that, The sorting of each second task according to the failure times and initial priorities of each second task in the second task set includes: Sorting each second task according to the failure times of each second task in the second task set; If there are at least two second tasks with the same failure times, then adjusting the sorting of the at least two second tasks according to the initial priorities of the at least two second tasks.

4. The method according to claim 1, characterized in that, Screening the second task set through the following steps: From the set of tasks to be processed, screening out the first failed tasks with failure times not lower than the first preset number threshold and lower than the second preset number threshold, and screening out the second failed tasks with failure times not lower than the second preset number threshold and lower than the third preset number threshold; the first failed tasks include the first tasks, and the second failed tasks include the second tasks; Respectively determining the decay time of each second failed task according to the failure times of each second failed task; Respectively obtaining the failure duration of each second failed task, where the failure duration is the duration between the failure time point when the second failed task fails to execute and the current time point; From the screened second failed tasks, screening out the third failed tasks with corresponding failure durations not lower than the corresponding decay times; Determining the screened first failed tasks and third failed tasks as the second tasks to obtain the second task set.

5. The method according to claim 4, wherein Screening the third task set through the following steps: From the screened second failed tasks, screening out the third tasks with corresponding failure durations lower than the corresponding decay times to obtain the third task set.

6. The method according to any one of claims 1 to 5, characterized in that, Separately obtaining the failure times and initial priorities of each task in the set of tasks to be processed further includes: If it is determined that there is a fourth task in the set of tasks to be processed whose failure times are not less than a third preset number threshold, each fourth task is removed from the set of tasks to be processed and moved to a failure set; Based on the movement to the failure set, a task exception alarm notification is sent.

7. The method according to any one of claims 1-5, characterized in that Determining the highest priority among the target priorities of each task and executing the task corresponding to the highest priority includes: Filtering out the target priorities of each unlocked task from the set of tasks to be processed; Determining the highest priority among the filtered target priorities of each task; Locking the task corresponding to the highest priority; Executing the task corresponding to the highest priority; After determining that the task corresponding to the highest priority has been executed, unlocking the task corresponding to the highest priority.

8. An apparatus for executing an asynchronous task, characterized in that, Applied to each server in a distributed scheduling system, it includes: An acquisition unit for separately obtaining the failure times and initial priorities of each task in the set of tasks to be processed, where the set of tasks to be processed contains at least one task; A setting unit for filtering out first tasks with failure times lower than a first preset number threshold from the set of tasks to be processed to form a first task set, and filtering out a second task set and a third task set with failure times not less than a second preset number threshold and lower than a third preset number threshold, where the second task set is a set composed of at least one task whose failure duration is not less than the corresponding decay time, and the third task set is a set composed of at least one task whose failure duration is lower than the corresponding decay time; the first preset number threshold is lower than the second preset number threshold; determining the initial priority of the first task as the target priority of the corresponding first task, and setting the target priority of each third task in the third task set to the lowest priority; where the target priority of each second task in the second task set is higher than the target priority of each first task. An execution unit for determining the highest priority among the target priorities of each task and executing the task corresponding to the highest priority.

9. An electronic device, characterized in that, It includes a processor and a memory, and the memory stores computer-readable instructions. When the computer-readable instructions are executed by the processor, the method according to any one of claims 1-7 is run.

10. A readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by the processor, the method according to any one of claims 1-7 is run.

Citation Information

Patent Citations

  • Asynchronous task scheduling method, device and system and electronic equipment

    CN106598705A

  • Webpage information acquisition method and device, computer equipment and storage medium

    CN112347394A