Asynchronous task execution method and device, electronic equipment and storage medium
By generating and managing asynchronous task lists in a distributed service architecture, the problem of inefficient processing of pending tasks is solved and more efficient task processing is achieved.
Patent Information
- Application Number
- CN202411883764.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-19
- Publication Date
- 2025-03-21
AI Technical Summary
Under the distributed service architecture, the processing efficiency of the to-process tasks is low, mainly because the distributed task processing process is complex and in order to maintain the consistency of task processing, the locking of task data takes a long time.
By obtaining the task information of the pending task and the call status of the transaction calling system, a target record is generated and added to the asynchronous task list, the task status is determined based on the feedback information, and the detailed table is called to execute the task to obtain the execution result.
The processing efficiency of pending tasks is improved, and the execution method of asynchronous tasks is reduced in task data locking and the processing capability of the system is improved.
Smart Images

Figure CN119668814A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer science and technology, and in particular to a method, device, electronic device and storage medium for executing asynchronous tasks. Background Art
[0002] At present, under the distributed service architecture, the transaction link is decomposed into service serial links at all levels across multiple computers or network nodes. In order to ensure the correct closed loop of the transaction, services at all levels need to keep the processing status of the task consistent, that is, when the transaction is normal, the service data at all levels flows normally, and in abnormal situations, the service data at all levels rolls back to the consistent moment of the processing status of the previous task. Since the processing process of distributed tasks is relatively complicated, and in order to maintain the consistency of task processing, it takes a long time to lock the task data, which leads to the technical problem of low processing efficiency of pending tasks.
[0003] Currently, no effective solution has been proposed for the technical problem of low processing efficiency of tasks to be processed in related technologies. Summary of the invention
[0004] The main purpose of the present application is to provide a method, device, electronic device and storage medium for executing an asynchronous task, so as to solve the technical problem of low processing efficiency of tasks to be processed in the related art.
[0005] In order to achieve the above-mentioned purpose, according to one aspect of the present application, a method for executing an asynchronous task is provided. The method includes: obtaining task information of a pending task and a call status of a transaction call system for calling the pending task, wherein the task information is used to characterize the attributes and processing behavior of the pending task; generating a target record of the pending task based on the task information and the call status; adding the target record to an asynchronous task detail table; generating feedback information of the pending task based on the added asynchronous task detail table, and determining the pending task as a pending asynchronous task based on the feedback information, wherein the feedback information is used to feedback the failure of the pending task to be executed; calling the added asynchronous task detail table, executing the pending asynchronous task, and obtaining the execution result of the pending asynchronous task, wherein the execution result is used to characterize the execution status of the pending asynchronous task.
[0006] Optionally, generating a target record of the task to be processed based on the task information and the call status includes: in response to the call status being a call abnormal state, generating a target record of the task to be processed based on the task information.
[0007] Optionally, the added asynchronous task details list is called to execute the pending asynchronous tasks to obtain the execution results of the pending asynchronous tasks, including: in the added asynchronous task details list, multiple pending asynchronous tasks whose task status is pending in the task information, and the task priorities in the task information corresponding to the multiple pending tasks; sorting the multiple task priorities to obtain the sorting results; based on the sorting results, executing the pending asynchronous tasks to obtain the execution results.
[0008] Optionally, after executing the asynchronous task to be processed and obtaining the execution result, the method also includes: in response to the execution result being that the asynchronous task to be processed has been successfully executed, obtaining identification information of the asynchronous task to be processed, and updating the task status in the task information corresponding to the asynchronous task to be processed; based on the identification information and the updated task status, determining an updated asynchronous task details table.
[0009] Optionally, after executing the pending asynchronous task and obtaining the execution result, the method also includes: obtaining the target redo number in the task information corresponding to the pending asynchronous task from the asynchronous task details table; in response to the execution result being the failure of the pending asynchronous task to be executed, determining the redo number of the pending asynchronous task; based on the redo number of the pending asynchronous task and the target redo number, determining the redo result of the pending asynchronous task, wherein the redo result is used to characterize the reprocessing status of the pending asynchronous task.
[0010] Optionally, based on the number of redo times of the pending asynchronous task and the target redo number, a redo result of the pending asynchronous task is determined, including: in response to the number of redo times being less than the target redo number, determining that the redo result is that the pending asynchronous task has been reprocessed; in response to the number of redo times being equal to or greater than the target redo number, determining that the redo result is that the pending asynchronous task has not been reprocessed.
[0011] Optionally, the task information includes at least one of the following: task type, task name, task preemption number, task execution delay, task redo number, task redo time interval and task execution timeout.
[0012] In order to achieve the above-mentioned purpose, according to another aspect of the present application, an execution device for an asynchronous task is provided. The device comprises: a first acquisition unit, used to acquire task information of a pending task and a call status of a transaction call system for calling the pending task, wherein the task information is used to characterize the attributes and processing behavior of the pending task; a generation unit, used to generate a target record of the pending task based on the task information and the call status; an adding unit, used to add the target record to an asynchronous task list; a first determination unit, used to generate feedback information of the pending task based on the added asynchronous task list, and determine the pending task as a pending asynchronous task based on the feedback information, wherein the feedback information is used to feedback the failure of the pending task to be executed; an execution unit, used to call the added asynchronous task list, execute the pending asynchronous task, and obtain the execution result of the pending asynchronous task, wherein the execution result is used to characterize the execution status of the pending asynchronous task.
[0013] Optionally, the generating unit may include: a generating module, configured to generate a target record of the task to be processed based on the task information in response to the calling state being a calling abnormal state.
[0014] Optionally, the execution unit may include: a first acquisition module, used to acquire, in the added asynchronous task details table, multiple pending asynchronous tasks whose task status in the task information is a pending status, and task priorities in the task information corresponding to the multiple pending tasks; a sorting module, used to sort the multiple task priorities to obtain a sorting result; and an execution module, used to execute the pending asynchronous tasks based on the sorting result to obtain an execution result.
[0015] Optionally, after executing the asynchronous task to be processed and obtaining the execution result, the device may also include: an updating unit, used to obtain the identification information of the asynchronous task to be processed in response to the execution result being that the asynchronous task to be processed has been successfully executed, and to update the task status in the task information corresponding to the asynchronous task to be processed; a second acquisition unit, used to determine an updated asynchronous task details table based on the identification information and the updated task status.
[0016] Optionally, after executing the pending asynchronous task and obtaining the execution result, the device may further include: a third acquisition unit, used to acquire the target redo number in the task information corresponding to the pending asynchronous task from the asynchronous task details table; a second determination unit, used to determine the redo number of the pending asynchronous task in response to the execution result being the failure of the pending asynchronous task to be executed; a third determination unit, used to determine the redo result of the pending asynchronous task based on the redo number and the target redo number of the pending asynchronous task, wherein the redo result is used to characterize the reprocessing status of the pending asynchronous task.
[0017] Optionally, the third determination unit may include: a second acquisition module, used to determine that the redo result is that the pending asynchronous task has been reprocessed in response to the number of redo times being less than the target redo number; a third acquisition module, used to determine that the redo result is that the pending asynchronous task has not been reprocessed in response to the number of redo times being equal to or greater than the target redo number.
[0018] Optionally, the task information includes at least one of the following: task type, task name, task preemption number, task execution delay, task redo number, task redo time interval and task execution timeout.
[0019] In order to achieve the above-mentioned purpose, according to one aspect of the present application, an electronic device is provided, which includes: a memory storing an executable program; and a processor for running the program, wherein the method in the embodiment is executed when the program is running.
[0020] In order to achieve the above-mentioned purpose, according to one aspect of the present application, a computer-readable storage medium is provided, which storage medium includes: the computer-readable storage medium includes a stored executable program, wherein when the executable program is running, the device where the computer-readable storage medium is located is controlled to execute the method in the embodiment.
[0021] In an embodiment of the present application, the task information of the pending task and the call status of the transaction call system for calling the pending task can be obtained first, and then the target record of the pending task can be generated based on the task information and call status obtained above, and the target record obtained at this time can be added to the asynchronous task detail list, and then the feedback information of the pending task is generated based on the added asynchronous task detail list, and the pending task is determined as the pending asynchronous task according to the feedback information obtained above, and finally the added asynchronous task detail list can be called to execute the pending asynchronous task, so as to obtain the execution result used to characterize the execution status of the pending asynchronous task. Considering that after adding the target record to the asynchronous task detail list, the feedback information of the pending task is generated based on the added asynchronous task detail list, and the pending task at this time is determined as the pending asynchronous task according to the feedback information, the added asynchronous task detail list is called, and the pending asynchronous task is executed, the purpose of obtaining the execution result of the pending asynchronous task is achieved, thereby achieving the technical effect of improving the processing efficiency of the pending task, and then solving the technical problem of low processing efficiency of the pending task. BRIEF DESCRIPTION OF THE DRAWINGS
[0022] The drawings constituting a part of the present application are used to provide a further understanding of the present application. The illustrative embodiments and descriptions of the present application are used to explain the present application and do not constitute an improper limitation on the present application. In the drawings:
[0023] Figure 1A hardware structure block diagram of a computer terminal for implementing an asynchronous task execution method is shown;
[0024] Figure 2 is a flowchart of a method for executing an asynchronous task according to an embodiment of the present application;
[0025] Figure 3 is a schematic diagram of an asynchronous task execution device according to an embodiment of the present application;
[0026] Figure 4 It is a structural block diagram of an electronic device according to an embodiment of the present application. DETAILED DESCRIPTION
[0027] In order to enable those skilled in the art to better understand the solution of the present application, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work should fall within the scope of protection of the present application.
[0028] It should be noted that the terms "first", "second", etc. in the specification and claims of the present application and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchangeable where appropriate, so that the embodiments of the present application described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device comprising a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0029] According to an embodiment of the present application, a method embodiment of an asynchronous task execution method is also provided. It should be noted that the steps shown in the flowchart of the accompanying drawings can be executed in a computer system such as a set of computer executable instructions, and although the logical order is shown in the flowchart, in some cases, the steps shown or described can be executed in an order different from that shown here.
[0030] The method embodiment provided in the first embodiment of the present application can be executed in a mobile terminal, a computer terminal or a similar computing device. Figure 1 FIG. 1 shows a hardware structure block diagram of a computer terminal for implementing an asynchronous task execution method. Figure 1As shown, the computer terminal 10 (or mobile device) may include one or more (102a, 102b, ..., 102n are used to illustrate) processors 102 (the processor 102 may include but is not limited to a processing device such as a microprocessor MCU or a programmable logic device FPGA), a memory 104 for storing data, and a transmission device 106 for communication functions. In addition, it may also include: a display, an input / output interface (I / O interface), a universal serial bus (USB) port (which may be included as one of the ports of the BUS bus), a network interface, a power supply and / or a camera. It can be understood by those skilled in the art that Figure 1 The structure shown is only for illustration and does not limit the structure of the above electronic device. Figure 1 More or fewer components as shown, or with Figure 1 Different configurations shown.
[0031] It should be noted that the one or more processors 102 and / or other data processing circuits described above may generally be referred to herein as "data processing circuits". The data processing circuits may be embodied in whole or in part as software, hardware, firmware, or any other combination thereof. In addition, the data processing circuit may be a single independent processing module, or may be incorporated in whole or in part into any of the other components in the computer terminal 10 (or mobile device). As described in the embodiments of the present application, the data processing circuit acts as a processor control (e.g., selection of a variable resistor terminal path connected to an interface).
[0032] The memory 104 can be used to store software programs and modules of application software, such as the program instructions / data storage device corresponding to the execution method of the asynchronous task in the embodiment of the present application. The processor 102 executes various functional applications and data processing by running the software programs and modules stored in the memory 104, that is, the execution method of the asynchronous task described above is realized. The memory 104 may include a high-speed random access memory, and may also include a non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some instances, the memory 104 may further include a memory remotely arranged relative to the processor 102, and these remote memories may be connected to the computer terminal 10 via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.
[0033] The transmission device 106 is used to receive or send data via a network. The specific example of the above network may include a wireless network provided by a communication provider of the computer terminal 10. In one example, the transmission device 106 includes a network adapter (Network Interface Controller, referred to as NIC), which can be connected to other network devices through a base station so as to communicate with the Internet. In one example, the transmission device 106 can be a radio frequency (RF) module, which is used to communicate with the Internet wirelessly.
[0034] The display may be, for example, a touch screen liquid crystal display (LCD) that enables a user to interact with a user interface of the computer terminal 10 (or mobile device).
[0035] Under the above operating environment, this application provides Figure 2 The execution method of the asynchronous task is shown. Figure 2 : is a flowchart of a method for executing an asynchronous task according to an embodiment of the present application, the method mainly comprises the following steps:
[0036] Step S201, obtaining task information of the task to be processed and the calling status of the transaction calling system for calling the task to be processed.
[0037] In step S201 of the embodiment of the present application, the task information of the task to be processed and the calling status of the transaction calling system for calling the task to be processed can be obtained. The task information can be recorded in the definition table of the task to be processed.
[0038] Optionally, the task information is used to characterize the attributes and processing behavior of the task to be processed, such as the task name, task description information, task priority, task deadline, task status, etc. It should be noted that the task information is only illustrated here, and the specific content of the task information is not limited.
[0039] Optionally, the call status can be used to characterize whether the transaction call system calls the pending task normally, and can be divided into a normal call status and an abnormal call status. The normal call status is used to characterize that the transaction call system can call the pending task normally, and the abnormal call status is used to characterize that the transaction call system cannot call the pending task normally.
[0040] Step S202: Generate a target record of the task to be processed based on the task information and the calling status.
[0041] In step S202 of the embodiment of the present application, a target record of the task to be processed may be generated according to the obtained task information and call status, wherein the target record may be referred to as a record for short, and the record contains relevant information such as the task information, call status and unique identifier of the task to be processed.
[0042] It should be noted that this is only a preferred implementation method for obtaining the target record of the task to be processed, and does not specifically limit the process and method for obtaining the target record of the task to be processed. As long as the process and method for generating the target record of the task to be processed are based on the task information and the call status, they are within the scope of protection of this application and will not be listed here.
[0043] Step S203: Add the target record to the asynchronous task details table.
[0044] In step S203 of the embodiment of the present application, the target record can be added to the asynchronous task details table according to the target record obtained in the above steps, wherein the asynchronous task details table is used to characterize the detailed information of the asynchronous tasks being executed in the system, which can be referred to as the task details table.
[0045] Optionally, the asynchronous task details table includes task type, keywords (including business information, used for parameter passing for subsequent task execution), task status (pending, entering queue, starting work, ending work), task priority, submission time, queue entry time, server unique identifier, task start execution time, task end time, execution result error code, execution result information, planned execution time, supplementary business information and last update time, etc.
[0046] Optionally, through the asynchronous task details table, you can view the execution status of all asynchronous tasks in the system, help monitor the execution progress and results of tasks, and promptly discover and solve problems during task execution.
[0047] Step S204: Generate feedback information of the task to be processed based on the added asynchronous task list, and determine the task to be processed as the asynchronous task to be processed based on the feedback information.
[0048] In step S204 of the embodiment of the present application, feedback information of the pending task can be generated according to the added asynchronous task details list, and the pending task can be determined as a pending asynchronous task according to the feedback information, wherein the feedback information is used to feedback the failure of the execution of the pending task, that is, the resources for directly processing the task are occupied or the waiting time is long, and the task cannot be processed in time.
[0049] Optionally, the data of each item in the added asynchronous task detail table is consistent with the data type corresponding to the data in the task information in the pending task. For example, the task type of the newly added detail data is consistent with the type of the definition table, indicating that the information of the task in the definition table can be used.
[0050] Step S205, calling the added asynchronous task list, executing the asynchronous task to be processed, and obtaining the execution result of the asynchronous task to be processed.
[0051] In step S205 of the embodiment of the present application, the added asynchronous task list can be called to execute the asynchronous task to be processed, so as to obtain the execution result of the asynchronous task to be processed, wherein the execution result is used to characterize the execution status of the asynchronous task to be processed.
[0052] Optionally, the control server is in a startup state, calls the added asynchronous task list, loads the relevant information of the pending asynchronous task in the added asynchronous task list into the memory, and executes the pending asynchronous task to obtain the execution result of the pending asynchronous task. For example, when the server starts, the asynchronous task information is loaded into the memory, and the main thread of the asynchronous task is started to execute the pending asynchronous task and obtain the execution result.
[0053] It should be noted that this is only a preferred implementation method for obtaining the execution results of pending asynchronous tasks, and does not specifically limit the process and method for obtaining the execution results of pending asynchronous tasks. As long as the added asynchronous task list is called, the pending asynchronous tasks are executed, and the process and method for obtaining the execution results of the pending asynchronous tasks are obtained, they are all within the scope of protection of this application and are not listed here.
[0054] In this embodiment, the task information of the pending task and the call status of the transaction call system for calling the pending task can be obtained first, and then the target record of the pending task can be generated according to the task information and call status obtained above, and the target record obtained at this time can be added to the asynchronous task detail list, and then the feedback information of the pending task is generated according to the added asynchronous task detail list, and the pending task is determined as the pending asynchronous task according to the feedback information obtained above, and finally the added asynchronous task detail list can be called to execute the pending asynchronous task, so as to obtain the execution result used to characterize the execution status of the pending asynchronous task. Considering that after adding the target record to the asynchronous task detail list, the feedback information of the pending task is generated according to the added asynchronous task detail list, and the pending task at this time is determined as the pending asynchronous task according to the feedback information, the added asynchronous task detail list is called, and the pending asynchronous task is executed, the purpose of obtaining the execution result of the pending asynchronous task is achieved, thereby achieving the technical effect of improving the processing efficiency of the pending task, and then solving the technical problem of low processing efficiency of the pending task.
[0055] In the asynchronous task execution method provided in the embodiment of the present application, a target record of the task to be processed is generated based on the task information and the call status, including: in response to the call status being a call exception state, a target record of the task to be processed is generated based on the task information.
[0056] In this embodiment, after obtaining the task information and the call status, if the call status at this time is a call abnormality state, a target record of the pending task can be generated according to the task information. The call status can also be used to characterize the abnormality of the service called by the transaction call system before calling the pending task.
[0057] For example, when a transaction calls the system for online transactions, if a service call exception occurs, a new record needs to be added to the asynchronous task detail table, and the upstream result is returned as execution failure, so as to ensure that the task can be completed as expected. In addition, the target record obtained above can also be used as a basis for subsequent task tracking and evaluation, which can effectively improve the management and execution of task processing.
[0058] In the asynchronous task execution method provided in the embodiment of the present application, the added asynchronous task detail list is called, the pending asynchronous task is executed, and the execution result of the pending asynchronous task is obtained, including: in the added asynchronous task detail list, a plurality of pending asynchronous tasks whose task status is a pending status in the task information are obtained, and the task priorities in the task information corresponding to the plurality of pending tasks respectively; the plurality of task priorities are sorted to obtain the sorting result; based on the sorting result, the pending asynchronous task is executed to obtain the execution result.
[0059] In this embodiment, in the asynchronous task details table after adding, you can first obtain multiple pending asynchronous tasks whose task status is pending in the task information, and the task priorities in the task information corresponding to the multiple pending tasks respectively, and then sort the multiple task priorities obtained above to obtain the sorting results. Finally, according to the sorting results obtained above, the pending asynchronous tasks can be executed to obtain the execution results.
[0060] Optionally, from the added asynchronous task details list, multiple pending asynchronous tasks with a task status of pending are filtered, and the priorities corresponding to the multiple pending asynchronous tasks are sorted in order from high to low, so that pending asynchronous tasks with higher priorities can be processed first, so as to achieve the technical effect of improving the processing efficiency of pending asynchronous tasks.
[0061] For example, the main thread periodically scans the pending tasks in the task list, sorts them by priority, and preempts the tasks, thereby updating the task status of the task at this time and the unique identifier of the server.
[0062] In the asynchronous task execution method provided in an embodiment of the present application, after executing the asynchronous task to be processed and obtaining the execution result, the method also includes: in response to the execution result being that the asynchronous task to be processed has been successfully executed, obtaining the identification information of the asynchronous task to be processed, and updating the task status in the task information corresponding to the asynchronous task to be processed; based on the identification information and the updated task status, determining an updated asynchronous task details table.
[0063] In this embodiment, after executing the asynchronous task to be processed and obtaining the execution result, if the execution result at this time is that the asynchronous task to be processed has been successfully executed, the task status in the task information corresponding to the asynchronous task to be processed can be updated, and the identification information of the asynchronous task to be processed can be obtained, and based on the identification information and the updated task status, the server of the asynchronous task to be processed can be used to obtain an updated asynchronous task details list.
[0064] Optionally, after the pending asynchronous task is executed and the execution result is obtained, if the task has been successfully executed, the server of the pending asynchronous task can be used to update the asynchronous task details table based on the obtained identification information of the pending asynchronous task and the updated task status, so as to achieve the effect of obtaining the pending asynchronous task in real time and effectively processing the task.
[0065] For example, in the next preemption time interval, the pending tasks preempted by the server can only be processed by the server, and the task list can be updated with the processed results. After the task processing is completed, the task list is written into the history table, and then the list data is deleted to generate a new task list.
[0066] It should be noted that this is only a preferred implementation method for obtaining the updated asynchronous task list, and does not specifically limit the process and method for obtaining the updated asynchronous task list.
[0067] In the asynchronous task execution method provided in the embodiment of the present application, after executing the pending asynchronous task and obtaining the execution result, the method also includes: obtaining the target redo number in the task information corresponding to the pending asynchronous task from the asynchronous task detail table; in response to the execution result being the failure of the pending asynchronous task to be executed, determining the redo number of the pending asynchronous task; based on the redo number and the target redo number of the pending asynchronous task, determining the redo result of the pending asynchronous task, wherein the redo result is used to characterize the reprocessing status of the pending asynchronous task.
[0068] In this embodiment, the target redo number in the task information corresponding to the pending asynchronous task can be obtained from the asynchronous task details table. If the execution result at this time is that the pending asynchronous task fails to execute, it is necessary to determine the redo number of the pending asynchronous task, and based on the redo number and the target redo number, the purpose of determining the redo result of the pending asynchronous task can be achieved. Among them, the target redo number is a preset number, that is, the redo number in the definition table, for example, 3 times, 4 times, etc.
[0069] Optionally, if the current asynchronous task fails to execute, it is necessary to determine whether the number of redo times of the asynchronous task at this time meets the target redo number, and then determine whether to re-execute the asynchronous task to achieve the effect of effective resource utilization.
[0070] In the asynchronous task execution method provided in the embodiment of the present application, the redo result of the pending asynchronous task is determined based on the redo number of the pending asynchronous task and the target redo number, including: in response to the redo number being less than the target redo number, determining that the redo result is that the pending asynchronous task has been reprocessed; in response to the redo number being equal to or greater than the target redo number, determining that the redo result is that the pending asynchronous task has not been reprocessed.
[0071] In this embodiment, the number of redo times can be compared with the target redo number. If the number of redo times is less than the target redo number, the redo result is that the pending asynchronous task has been reprocessed; if the number of redo times at this time is equal to or greater than the target redo number, the redo result is that the pending asynchronous task has not been reprocessed.
[0072] For example, after a task fails to be processed, it is necessary to obtain the number of redoes for the task from the asynchronous task detail table to determine whether the number of redoes is less than the number of redoes in the definition table. If the condition is met, redo is performed. If the condition is not met, there is no need to execute the task again.
[0073] In the asynchronous task execution method provided in the embodiment of the present application, the task information includes at least one of the following: task type, task name, task preemption number, task execution delay, task redo number, task redo time interval and task execution timeout.
[0074] In this embodiment, the task information may include at least: task type, task name, number of task preemptions, task execution delay, number of task redoes, time interval for task redoes, and task execution timeout. For example, a task may be defined, which includes task type, task name, task implementation class (asynchronous task specific business logic), time interval between two task executions, number of task preemptions, task execution delay, task execution thread pool size, task queue size, number of task redoes, time interval for task redoes, and task timeout. At the same time, the task is defined in the asynchronous task definition table.
[0075] The asynchronous task execution method provided in the embodiment of the present application can first obtain the task information of the pending task and the call status of the transaction call system used to call the pending task, and then generate the target record of the pending task according to the task information and call status obtained above, and add the target record obtained at this time to the asynchronous task detail list, and then generate feedback information of the pending task according to the added asynchronous task detail list, and determine the pending task as the pending asynchronous task according to the feedback information obtained above, and finally call the added asynchronous task detail list to execute the pending asynchronous task, so as to obtain the execution result used to characterize the execution status of the pending asynchronous task. Considering that after adding the target record to the asynchronous task detail list, the feedback information of the pending task is generated according to the added asynchronous task detail list, and the pending task at this time is determined as the pending asynchronous task according to the feedback information, the added asynchronous task detail list is called, and the pending asynchronous task is executed, the purpose of obtaining the execution result of the pending asynchronous task is achieved, thereby achieving the technical effect of improving the processing efficiency of the pending tasks, and then solving the technical problem of low processing efficiency of the pending tasks.
[0076] The technical solution of the embodiment of the present application is illustrated below in conjunction with preferred implementation modes.
[0077] At present, under the distributed service architecture, the transaction link is decomposed into service serial links at all levels across multiple computers or network nodes. In order to ensure the correct closed loop of the transaction, services at all levels need to maintain the consistency of the task processing status, that is, when the transaction is normal, the service data at all levels flows normally, and in abnormal cases, the service data at all levels rolls back to the consistent moment of the processing status of the previous task. Considering that the processing process of distributed tasks is relatively complicated, and in order to maintain the consistency of task processing, it is easy to lock the various task data involved for a long time, and there are fewer concurrent transactions, resulting in low processing efficiency of pending tasks.
[0078] In order to solve the above problems, this application proposes a transaction closed-loop method based on customized asynchronous tasks, which includes inserting an asynchronous task in the online transaction link when a service calls a downstream service abnormally, setting the transaction result as unknown and returning it to the upstream, and then closing the transaction with asynchronous tasks, wherein the asynchronous task is used to characterize that during the program execution, some tasks need to be processed in the background or another thread without blocking the execution of the main thread or program. The above method mainly includes three steps: defining tasks, inserting tasks, and scheduled scanning and execution of tasks.
[0079] In this embodiment, the process of defining a task is: determining the task information of the task, including: task type, task name, task implementation class (asynchronous task specific business logic), time interval between two task executions, number of task preemptions, task execution delay, task execution thread pool size, task queue size, number of task redoes, task redo time interval, and task timeout. At the same time, the task is defined in the asynchronous task definition table.
[0080] To be more specific, the process of inserting a task is as follows: when a transaction calls the system to conduct an online transaction, if a service call exception occurs, a new record needs to be added to the asynchronous task detail table, and the upstream result is returned as an execution failure. The asynchronous task detail table includes: task type, keywords (including business information, used for parameter transfer for subsequent task execution), task status (pending, entering the queue, starting work, ending work), task priority, submission time, queue entry time, server unique identifier, task start execution time, task end time, execution result error code, execution result information, planned execution time, supplementary business information, and last update time. The task type of the newly added detail data is consistent with the type of the definition table, indicating that the information of the task in the definition table can be used.
[0081] In addition, the process of task timing scanning and execution is as follows: when the server starts, the asynchronous task information is loaded into the memory, and the main thread of the asynchronous task is started. The main thread regularly scans the pending tasks in the task list, sorts them according to the priority of the task, and preempts the task, so that the task status of the task at this time and the unique identifier of the server can be updated. In the next preemption time interval, the pending tasks preempted by the server can only be processed by the server, and the task list can be updated with the processed results. After the task processing is completed, the task list is written to the history table, and then the list data is deleted to generate a new task list. After the task processing fails, it is necessary to obtain the number of redoes of the task from the asynchronous task list, and determine whether the number of redoes is less than the number of redoes in the definition table. If the conditions are met, redo is performed. If the conditions are not met, there is no need to execute the task again.
[0082] In this embodiment, considering that after adding the target record to the asynchronous task detail list, feedback information of the task to be processed is generated according to the above-mentioned added asynchronous task detail list, and the task to be processed at this time is determined as the asynchronous task to be processed according to the feedback information, the added asynchronous task detail list is called, and the asynchronous task to be processed is executed, thereby achieving the purpose of obtaining the execution result of the asynchronous task to be processed, thereby achieving the technical effect of improving the processing efficiency of the task to be processed, and then solving the technical problem of low processing efficiency of the task to be processed.
[0083] The embodiment of the present application also provides an asynchronous task execution device. It should be noted that the asynchronous task execution device of the embodiment of the present application can be used to execute the asynchronous task execution method provided by the embodiment of the present application. The following introduces the asynchronous task execution device provided by the embodiment of the present application.
[0084] According to the embodiment of the present application, Figure 3 is a schematic diagram of an asynchronous task execution device according to an embodiment of the present application, such as Figure 3 As shown, the execution device of the asynchronous task includes:
[0085] The first acquisition unit 301 is used to acquire task information of the task to be processed and the calling status of the transaction calling system for calling the task to be processed, wherein the task information is used to characterize the attributes and processing behavior of the task to be processed.
[0086] The generating unit 302 is used to generate a target record of the task to be processed based on the task information and the calling status.
[0087] The adding unit 303 is used to add the target record to the asynchronous task detail table.
[0088] The first determining unit 304 is configured to generate feedback information of the pending task based on the added asynchronous task list, and determine the pending task as a pending asynchronous task based on the feedback information, wherein the feedback information is used to feedback execution failure of the pending task.
[0089] The execution unit 305 is used to call the added asynchronous task list, execute the asynchronous task to be processed, and obtain the execution result of the asynchronous task to be processed, wherein the execution result is used to represent the execution status of the asynchronous task to be processed.
[0090] Optionally, the generating unit 302 may include: a generating module, configured to generate a target record of the task to be processed based on the task information in response to the calling state being a calling abnormal state.
[0091] The asynchronous task execution device provided in the embodiment of the present application obtains the task information of the pending task and the call status of the transaction call system for calling the pending task through a first acquisition unit, wherein the task information is used to characterize the attributes and processing behavior of the pending task; generates a target record of the pending task based on the task information and the call status through a generation unit; adds the target record to the asynchronous task list through an adding unit; generates feedback information of the pending task based on the added asynchronous task list through a first determination unit, and determines the pending task as a pending asynchronous task based on the feedback information, wherein the feedback information is used to feedback the failure of the execution of the pending task; calls the added asynchronous task list through the execution unit to execute the pending asynchronous task and obtain the execution result of the pending asynchronous task, wherein the execution result is used to characterize the execution status of the pending asynchronous task, thereby achieving the technical effect of improving the processing efficiency of the pending task, and further solving the technical problem of low processing efficiency of the pending task.
[0092] Optionally, in the asynchronous task execution device provided in the embodiment of the present application, the execution unit 305 may include: a first acquisition module, used to acquire, in the asynchronous task details table after being added, multiple pending asynchronous tasks whose task status in the task information is a pending status, and task priorities in the task information corresponding to the multiple pending tasks respectively; a sorting module, used to sort the multiple task priorities to obtain a sorting result; and an execution module, used to execute the pending asynchronous tasks based on the sorting result to obtain an execution result.
[0093] Optionally, in the asynchronous task execution device provided in the embodiment of the present application, after executing the asynchronous task to be processed and obtaining the execution result, the device may also include: an updating unit, used to obtain the identification information of the asynchronous task to be processed in response to the execution result being that the asynchronous task to be processed has been successfully executed, and to update the task status in the task information corresponding to the asynchronous task to be processed; a second acquisition unit, used to determine an updated asynchronous task details list based on the identification information and the updated task status.
[0094] Optionally, in the asynchronous task execution device provided in the embodiment of the present application, after executing the pending asynchronous task and obtaining the execution result, the device may also include: a third acquisition unit, used to obtain the target redo number in the task information corresponding to the pending asynchronous task from the asynchronous task details table; a second determination unit, used to determine the redo number of the pending asynchronous task in response to the execution result being the failure of the pending asynchronous task to be executed; a third determination unit, used to determine the redo result of the pending asynchronous task based on the redo number and the target redo number of the pending asynchronous task, wherein the redo result is used to characterize the reprocessing status of the pending asynchronous task.
[0095] Optionally, in the asynchronous task execution device provided in the embodiment of the present application, the third determination unit may include: a second acquisition module, used to determine that the redo result is that the pending asynchronous task has been reprocessed in response to the number of redo times being less than the target redo number; a third acquisition module, used to determine that the redo result is that the pending asynchronous task has not been reprocessed in response to the number of redo times being equal to or greater than the target redo number.
[0096] Optionally, in the asynchronous task execution device provided in the embodiment of the present application, the task information includes at least one of the following: task type, task name, task preemption number, task execution delay, task redo number, task redo time interval and task execution timeout.
[0097] It should be noted that the above-mentioned modules or units can be hardware components or software components stored in a memory (e.g., memory 104) and processed by one or more processors (e.g., processors 102a, 102b, ..., 102n), and the above-mentioned modules can also be run as part of the device in the computer terminal 10 provided in the embodiment.
[0098] An embodiment of the present application may provide an electronic device, Figure 4 is a structural block diagram of an electronic device according to an embodiment of the present application. Figure 4 As shown, the electronic device may include: one or more ( Figure 4(only one is shown) processor 402, memory 404, storage controller, and peripheral interface, wherein the peripheral interface is connected to the radio frequency module, audio module and display.
[0099] Among them, the memory can be used to store software programs and modules, such as program instructions / modules corresponding to the methods and devices in the embodiments of the present application, and the processor executes various functional applications and data processing by running the software programs and modules stored in the memory, that is, realizing the above-mentioned method. The memory may include a high-speed random access memory, and may also include a non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some instances, the memory may further include a memory remotely arranged relative to the processor, and these remote memories may be connected to the terminal via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.
[0100] The processor can call the information and application stored in the memory through the transmission device to perform the following steps: obtain the task information of the pending task and the call status of the transaction call system used to call the pending task, wherein the task information is used to characterize the attributes and processing behavior of the pending task; based on the task information and the call status, generate a target record of the pending task; add the target record to the asynchronous task details table; based on the added asynchronous task details table, generate feedback information of the pending task, and determine the pending task as a pending asynchronous task based on the feedback information, wherein the feedback information is used to feedback the failure of the execution of the pending task; call the added asynchronous task details table, execute the pending asynchronous task, and obtain the execution result of the pending asynchronous task, wherein the execution result is used to characterize the execution status of the pending asynchronous task.
[0101] The processor can also call the information and application stored in the memory through the transmission device to perform the following steps: generate a target record of the task to be processed based on the task information and the call status, including: in response to the call status being a call exception state, generate a target record of the task to be processed based on the task information.
[0102] The processor can also call the information and application programs stored in the memory through the transmission device to perform the following steps: call the added asynchronous task list, execute the pending asynchronous tasks, and obtain the execution results of the pending asynchronous tasks, including: in the added asynchronous task list, obtain multiple pending asynchronous tasks whose task status in the task information is a pending status, and the task priorities in the task information corresponding to the multiple pending tasks; sort the multiple task priorities to obtain the sorting results; based on the sorting results, execute the pending asynchronous tasks to obtain the execution results.
[0103] The processor can also call the information and application stored in the memory through the transmission device to perform the following steps: in response to the execution result that the asynchronous task to be processed has been successfully executed, obtain the identification information of the asynchronous task to be processed, and update the task status in the task information corresponding to the asynchronous task to be processed; based on the identification information and the updated task status, determine the updated asynchronous task details table.
[0104] The processor can also call the information and application stored in the memory through the transmission device to perform the following steps: obtain the target redo number in the task information corresponding to the asynchronous task to be processed from the asynchronous task details table; in response to the execution result being the failure of the asynchronous task to be processed, determine the redo number of the asynchronous task to be processed; based on the redo number and the target redo number of the asynchronous task to be processed, determine the redo result of the asynchronous task to be processed, wherein the redo result is used to characterize the reprocessing status of the asynchronous task to be processed.
[0105] The processor can also call the information and application stored in the memory through the transmission device to perform the following steps: based on the redo count of the pending asynchronous task and the target redo count, determine the redo result of the pending asynchronous task, including: in response to the redo count being less than the target redo count, determine the redo result is that the pending asynchronous task has been reprocessed; in response to the redo count being equal to or greater than the target redo count, determine the redo result is that the pending asynchronous task has not been reprocessed.
[0106] The processor can also call the information and application stored in the memory through the transmission device to perform the following steps: the task information includes at least one of the following: task type, task name, number of task preemptions, task execution delay, number of task redoes, task redo time interval and task execution timeout.
[0107] By adopting the embodiment of the present application, a scheme of an execution method of an asynchronous task is provided. The scheme first obtains the task information of the pending task and the call status of the transaction call system for calling the pending task, and then generates the target record of the pending task according to the task information and call status obtained above, and adds the target record obtained at this time to the asynchronous task detail label, and then generates the feedback information of the pending task according to the added asynchronous task detail table, and determines the pending task as the pending asynchronous task according to the feedback information obtained above, and finally calls the added asynchronous task detail table to execute the pending asynchronous task, so as to obtain the execution result for characterizing the execution status of the pending asynchronous task, considering that after adding the target record to the asynchronous task detail table, the feedback information of the pending task is generated according to the added asynchronous task detail table, and the pending task at this time is determined as the pending asynchronous task according to the feedback information, and the added asynchronous task detail table is called to execute the pending asynchronous task, so as to achieve the purpose of obtaining the execution result of the pending asynchronous task, thereby achieving the technical effect of improving the processing efficiency of the pending task, and then solving the technical problem of low processing efficiency of the pending task.
[0108] It can be understood by those skilled in the art that Figure 4 The structure shown is for illustration only, and the electronic device may also be a smart phone (such as an Android phone, an iOS phone, etc.), a tablet computer, a PDA, a mobile Internet device (Mobile Internet Devices, referred to as MID), a PAD, and other terminal devices. Figure 4 The structure of the electronic device is not limited. Figure 4 More or fewer components (such as network interfaces, display devices, etc.) shown in, or having Figure 4 Different configurations shown.
[0109] A person of ordinary skill in the art can understand that all or part of the steps in the various methods of the above embodiments can be completed by instructing the hardware related to the terminal device through a program, and the program can be stored in a computer-readable storage medium, and the storage medium may include: a flash drive, a read-only memory (ROM), a random access memory (RAM), a disk or an optical disk, etc.
[0110] The embodiment of the present application further provides a storage medium. Optionally, in this embodiment, the storage medium can be used to store the program code executed by the asynchronous task execution method provided in the first embodiment.
[0111] Optionally, in this embodiment, the above storage medium may be located in any computer terminal in a computer terminal group in a computer network, or in any mobile terminal in a mobile terminal group.
[0112] The present application also provides a computer program product, which, when executed on a data processing device, is suitable for executing the program of the execution method steps of the asynchronous task.
[0113] The serial numbers of the above-mentioned embodiments of the present application are for description only and do not represent the advantages or disadvantages of the embodiments.
[0114] In the above embodiments of the present application, the description of each embodiment has its own emphasis. For parts that are not described in detail in a certain embodiment, please refer to the relevant description of other embodiments.
[0115] In the several embodiments provided in this application, it should be understood that the disclosed technical content can be implemented in other ways. Among them, the device embodiments described above are only schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of units or modules, which can be electrical or other forms.
[0116] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0117] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.
[0118] If the integrated unit is implemented in the form of 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 the present 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, and the computer software product is stored in a storage medium, including a number of instructions to enable a computer device (which can be a personal computer, a server or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present application. The aforementioned storage medium includes: U disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), mobile hard disk, disk or optical disk and other media that can store program codes.
[0119] The above is only a preferred implementation of the present application. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the principles of the present application. These improvements and modifications should also be regarded as the scope of protection of the present application.
Claims
1. A method for executing an asynchronous task, characterized in that: include: Acquire task information of the task to be processed and the calling status of the transaction calling system used to call the task to be processed, wherein the task information is used to characterize the attributes and processing behavior of the task to be processed; Based on the task information and the calling status, generating a target record of the task to be processed; Add the target record to the asynchronous task list; Generate feedback information of the pending task based on the added asynchronous task list, and determine the pending task as a pending asynchronous task based on the feedback information, wherein the feedback information is used to feedback the failure of execution of the pending task; The added asynchronous task list is called to execute the asynchronous task to be processed, and an execution result of the asynchronous task to be processed is obtained, wherein the execution result is used to characterize the execution status of the asynchronous task to be processed.
2. The method according to claim 1, characterized in that Based on the task information and the call status, a target record of the task to be processed is generated, including: In response to the calling status being a calling abnormal state, a target record of the task to be processed is generated based on the task information.
3. The method according to claim 1, characterized in that Call the added asynchronous task list, Executing the asynchronous task to be processed and obtaining the execution result of the asynchronous task to be processed includes: In the added asynchronous task list, a plurality of pending asynchronous tasks whose task status in the task information is a pending status are obtained, and task priorities in the task information respectively corresponding to the plurality of pending tasks; Sorting the priorities of the plurality of tasks to obtain a sorting result; Based on the sorting result, the to-be-processed asynchronous task is executed to obtain the execution result.
4. The method according to claim 1, characterized in that: After executing the asynchronous task to be processed and obtaining the execution result, the method further includes: In response to the execution result being that the asynchronous task to be processed has been successfully executed, obtaining identification information of the asynchronous task to be processed, and updating the task status in the task information corresponding to the asynchronous task to be processed; Based on the identification information and the updated task status, an updated asynchronous task list is determined.
5. The method according to claim 1, characterized in that After executing the asynchronous task to be processed and obtaining the execution result, the method further includes: From the asynchronous task list, obtaining the target number of redoes in the task information corresponding to the asynchronous task to be processed; In response to the execution result being that the asynchronous task to be processed fails to be executed, determining the number of times the asynchronous task to be processed is to be redone; Based on the redo count of the asynchronous task to be processed and the target redo count, a redo result of the asynchronous task to be processed is determined, wherein the redo result is used to characterize a reprocessing situation of the asynchronous task to be processed.
6. The method according to claim 5, characterized in that Determining a redo result of the asynchronous task to be processed based on the redo count of the asynchronous task to be processed and the target redo count includes: In response to the number of redo times being less than the target number of redo times, determining that the redo result is that the to-be-processed asynchronous task has been reprocessed; In response to the redo number being equal to or greater than the target redo number, determining the redo result as not reprocessing the to-be-processed asynchronous task.
7. The method according to claim 1, characterized in that The task information includes at least one of the following: task type, task name, task preemption number, task execution delay, task redo number, task redo time interval and task execution timeout.
8. An asynchronous task execution device, characterized in that: include: A first acquisition unit is used to acquire task information of a task to be processed and a call status of a transaction call system for calling the task to be processed, wherein the task information is used to characterize the attributes and processing behavior of the task to be processed; A generating unit, configured to generate a target record of the task to be processed based on the task information and the calling state; An adding unit, used for adding the target record to the asynchronous task detail table; a first determining unit, configured to generate feedback information of the pending task based on the added asynchronous task list, and determine the pending task as a pending asynchronous task based on the feedback information, wherein the feedback information is used to feedback execution failure of the pending task; The execution unit is used to call the added asynchronous task list, execute the asynchronous task to be processed, and obtain the execution result of the asynchronous task to be processed, wherein the execution result is used to characterize the execution status of the asynchronous task to be processed.
9. An electronic device, characterized in that: include: A memory storing an executable program; A processor, configured to run the program, wherein the program executes the method according to any one of claims 1 to 7 when running.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium includes a stored executable program, wherein when the executable program is executed, the device where the computer-readable storage medium is located is controlled to execute the method according to any one of claims 1 to 7.