Retry execution method, device, electronic device and computer readable storage medium

By monitoring microservice exceptions, querying the retry mode object in the database and calling idempotent function objects, the microservice exceptions are automatically processed, solving the problem of slow processing speed in the existing technology and realizing fast and flexible exception handling and retry. Test method durability.

CN116991630BActive Publication Date: 2024-10-18CHONGQING SELIS PHOENIX INTELLIGENT INNOVATION TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202310962217.X
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-07-31
Publication Date
2024-10-18
Estimated Expiration
2043-07-31

AI Technical Summary

Technical Problem

When existing technology handles abnormal situations between microservices, the processing speed is slow and cannot respond to emergencies in a timely manner, which brings a huge workload to operation and maintenance personnel.

Method used

By monitoring the execution of microservices, we obtain data information about abnormal situations, query the retry method objects in the database, and call idempotent function objects through retry annotations to automatically handle abnormal situations and reduce retry data and steps. Improve the speed and durability of retry methods.

Benefits of technology

It achieves fast, flexible, and automated exception handling, reduces the pressure on operation and maintenance personnel, improves the speed and durability of retry methods, and can execute retry methods multiple times without being affected by restarts or execution failures.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116991630B_ABST
    Figure CN116991630B_ABST
Patent Text Reader

Abstract

The present application relates to the field of computer technology, and provides a retry execution method, device, electronic device and computer-readable storage medium. The method includes: monitoring the execution status of each microservice, the execution status includes abnormal situations and normal situations; when an abnormal situation occurs in a microservice, obtaining data information of the abnormal situation; querying in the database based on the data information to determine the retry mode object corresponding to the data information in the database; calling the corresponding retry class stored in the database based on the retry mode object, executing the retry class, and retrying the abnormal situation by means of retry annotation; the retry annotation method is to use the retry mode object as the interface of the retry class to call the idempotent function object, call the corresponding idempotent function object based on the interface, and determine the return value of the idempotent function object. The retry execution method provided by the present application saves the retry class, retry mode object and return value in the database, which improves the flexibility of the retry method.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of computer technology, and in particular to a retry execution method, device, electronic device and computer-readable storage medium. Background Art

[0002] In the prior art, application projects are split into multiple microservices with smaller granularity. In the process of mutual calls between multiple microservices, exceptions will inevitably be encountered, such as network connection timeout or network request interruption, etc. When an exception occurs, the log corresponding to the exception is printed and an alarm message is sent, so that the operation and maintenance personnel can know the exception and notify the developer of the exception. The developer determines the method to handle the exception based on the log to solve the exception.

[0003] However, when handling abnormal situations through the above-mentioned processing method, it is easy to bring a huge workload to the corresponding operation and maintenance personnel and developers, and the processing speed for abnormal situations is slow, and it is impossible to respond to emergencies in time. Summary of the invention

[0004] In view of this, embodiments of the present application provide a retry execution method, device, electronic device and computer-readable storage medium to solve the problem in the prior art that emergencies cannot be responded to in a timely manner.

[0005] A first aspect of an embodiment of the present application provides a retry execution method, including:

[0006] Monitor the execution status of each microservice, including abnormal and normal situations;

[0007] When an abnormal situation occurs in a microservice, obtain data information about the abnormal situation;

[0008] Querying the database based on the data information to determine the retry mode object corresponding to the data information in the database, the retry mode object including a retry object name, a retry class name, a retry class parameter, and a retry class parameter type;

[0009] Based on the retry mode object, the corresponding retry class saved in the database is called and the retry class is executed to retry the exception situation by means of retry annotations;

[0010] The retry annotation method is to use the retry mode object as the interface of the retry class to call the idempotent function object, call the corresponding idempotent function object based on the interface, and determine the return value of the idempotent function object.

[0011] A second aspect of an embodiment of the present application provides a retry execution device, including:

[0012] The monitoring module is configured to monitor the execution status of each microservice, including abnormal and normal conditions;

[0013] The acquisition module is configured to obtain data information of the abnormal situation when an abnormal situation occurs in the microservice;

[0014] A query module is configured to query the database based on the data information to determine the retry mode object corresponding to the data information included in the database, the retry mode object including a retry object name, a retry class name, a retry class parameter, and a retry class parameter type;

[0015] An execution module is configured to call a corresponding retry class stored in a database based on the retry mode object, and execute the retry class to retry the abnormal situation by means of retry annotations;

[0016] The retry annotation method is to use the retry mode object as the interface of the retry class to call the idempotent function object, call the corresponding idempotent function object based on the interface, and determine the return value of the idempotent function object.

[0017] According to a third aspect of an embodiment of the present application, an electronic device is provided, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the steps of the above method when executing the computer program.

[0018] According to a fourth aspect of an embodiment of the present application, a computer-readable storage medium is provided, which stores a computer program, and when the computer program is executed by a processor, the steps of the above method are implemented.

[0019] Compared with the prior art, the embodiments of the present application have the following beneficial effects: through the embodiments provided by the present application, an abnormal situation occurs during the execution of the microservice, the data information corresponding to the abnormal situation is obtained, and the corresponding retry mode object is determined according to the data information. If it exists, the retry mode object is called to retry the abnormal situation. Among them, the corresponding retry class is called according to the retry mode object, and the return value of the idempotent function object is called when the idempotent function object is encountered. When the abnormal situation occurs, the retry mode object and the corresponding retry class stored in the database can be called according to the data information corresponding to the abnormal situation when the abnormal situation is monitored, so as to retry the abnormal situation, and the abnormal situation can be handled quickly, flexibly and automatically, reducing the pressure of operation and maintenance personnel. At the same time, according to the embodiments provided by the present application, the retry class is executed by retry annotation, and the location of the abnormal situation can be located according to the data information of the abnormal situation, and the retry method is executed for the abnormal situation, rather than executing the retry method for the entire microservice, reducing the data and steps for executing the retry, and improving the speed of executing the retry method. At the same time, the retry class of the retry method object can be called from the database, and the return value of the corresponding idempotent function object in the database can be called according to the retry class through the retry annotation. Since the data such as the retry class, idempotent function object and return value are stored in the database, they can be called multiple times to execute the retry method multiple times, so that the retry method is not affected by factors such as restart and execution failure, thereby improving the durability of the retry method. BRIEF DESCRIPTION OF THE DRAWINGS

[0020] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.

[0021] Figure 1 It is a schematic diagram of an application scenario of an embodiment of the present application;

[0022] Figure 2 It is a flowchart of a retry execution method provided in an embodiment of the present application;

[0023] Figure 3 This is a flowchart of a retry execution class provided in an embodiment of the present application;

[0024] Figure 4 is a schematic diagram of a retry execution device provided in an embodiment of the present application;

[0025] Figure 5 It is a schematic diagram of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0026] In the following description, specific details such as specific system structures, technologies, etc. are provided for the purpose of illustration rather than limitation, so as to provide a thorough understanding of the embodiments of the present application. However, it should be clear to those skilled in the art that the present application may also be implemented in other embodiments without these specific details. In other cases, detailed descriptions of well-known systems, devices, circuits, and methods are omitted to prevent unnecessary details from obstructing the description of the present application.

[0027] A retry execution method and device according to an embodiment of the present application will be described in detail below with reference to the accompanying drawings.

[0028] Figure 1 1 is a schematic diagram of an application scenario of an embodiment of the present application. The application scenario may include a first terminal device 101, a second terminal device 102, a third terminal device 103, a server 104, and a network 105.

[0029] The first terminal device 101, the second terminal device 102, and the third terminal device 103 can be hardware or software. When the first terminal device 101, the second terminal device 102, and the third terminal device 103 are hardware, they can be various electronic devices with display screens and supporting communication with the server 104, including but not limited to smart phones, tablet computers, laptop portable computers, and desktop computers; when the first terminal device 101, the second terminal device 102, and the third terminal device 103 are software, they can be installed in the electronic devices described above. The first terminal device 101, the second terminal device 102, and the third terminal device 103 can be implemented as multiple software or software modules, or as a single software or software module, which is not limited in the embodiment of the present application. Further, various applications can be installed on the first terminal device 101, the second terminal device 102, and the third terminal device 103, such as data processing applications, instant messaging tools, social platform software, search applications, shopping applications, etc.

[0030] The server 104 may be a server that provides various services, for example, a background server that receives a request sent by a terminal device that establishes a communication connection with the server, and the background server may receive and analyze the request sent by the terminal device, and generate a processing result. The server 104 may be a single server, or a server cluster composed of several servers, or a cloud computing service center, which is not limited in the present embodiment of the application.

[0031] It should be noted that the server 104 can be hardware or software. When the server 104 is hardware, it can be various electronic devices that provide various services for the first terminal device 101, the second terminal device 102, and the third terminal device 103. When the server 104 is software, it can be multiple software or software modules that provide various services for the first terminal device 101, the second terminal device 102, and the third terminal device 103, or it can be a single software or software module that provides various services for the first terminal device 101, the second terminal device 102, and the third terminal device 103, and the embodiment of the present application does not limit this.

[0032] The network 105 can be a wired network connected by coaxial cable, twisted pair and optical fiber, or it can be a wireless network that can interconnect various communication devices without wiring, such as Bluetooth, Near Field Communication (NFC), infrared, etc., which is not limited in the embodiments of the present application.

[0033] It should be noted that the specific types, quantities and combinations of the first terminal device 101, the second terminal device 102 and the third terminal device 103, the server 104 and the network 105 can be adjusted according to the actual needs of the application scenario, and the embodiments of the present application do not limit this.

[0034] Figure 2 is a flowchart of a retry execution method provided in an embodiment of the present application. Figure 2 As shown, the retry execution method includes the following steps:

[0035] S201, monitoring the execution status of each microservice, including abnormal and normal situations;

[0036] S202, when an abnormal situation occurs in the microservice, obtain data information of the abnormal situation;

[0037] S203, querying the database based on the data information to determine the retry mode object corresponding to the data information included in the database;

[0038] S204, based on the retry mode object, calling the corresponding retry class stored in the database, executing the retry class, so as to retry the abnormal situation by means of retry annotation.

[0039] Figure 2 The retry execution method can be performed by Figure 1 The program can be executed on any terminal device, and the database can be configured in the server.

[0040] Among them, the retry mode object includes the retry object name, the retry class name, the retry class parameters, and the retry class parameter type. The retry annotation method is to use the retry mode object as the interface of the retry class to call the idempotent function object, call the corresponding idempotent function object based on the interface, and determine the return value of the idempotent function object.

[0041] In an exemplary embodiment, a retry annotation is added to each microservice that can resolve abnormal situations through a retry method, so that during the operation of the system, the abnormal situations of each microservice can be flexibly resolved through the retry annotation. The operation process of the system includes the mutual calling and operation between multiple microservices, so whether the execution of each microservice is normal is very important. However, when the microservices call each other, abnormal situations such as network connection timeout and network request interruption are inevitable.

[0042] Monitor the execution status of each microservice during the operation of the system. When an abnormal situation is detected in the microservice, obtain the data information corresponding to the abnormal situation, query the database based on the data information, and determine the retry mode object corresponding to the data information. The retry mode object includes the retry object, the name of the called retry class, the retry class parameters, and the retry class parameter type.

[0043] When the corresponding retry mode object is queried in the database, the retry class stored in the database is called according to the retry mode object, and the retry class is executed, so that the exception situation can be retried through the retry annotation.

[0044] Among them, the retry annotation method is to use the retry mode object as the interface for the retry class to call the idempotent function object. For example, annotate each step of the microservice, mark the execution steps of the microservice as A, B and C, and when executing the microservice, if an abnormal situation occurs at step B, obtain the data information of the abnormal situation, and query the retry mode object corresponding to the abnormal situation in the database. If the query is successful, use the retry mode object as the interface for the retry class to call the idempotent function object, that is, call the corresponding idempotent function object at step B, and determine the return value of the idempotent function object.

[0045] In an exemplary embodiment of the present application, the logic is exemplified by taking the retry() method of the retry class as an example, and taking the database as the ElasticSearch (ES) database as an example:

[0046] Among them, the ElasticSearch database is a distributed database suitable for all types of data including text, numbers, geospatial, structured and unstructured data.

[0047] According to the data information corresponding to the abnormal situation, the retry mode object corresponding to the data information is queried in the ES database. If the retry mode object and the corresponding idempotent mode object exist, the retry object name, retry class name, retry class parameters and retry class parameter types in the retry mode object are taken out. The retry object name is also called the bean name. Through the Spring framework, the Java object is defined as a bean object, and the capabilities provided by the Spring framework are obtained through the bean object. The bean name can determine a unique bean object. The Spring framework is an open source code commonly used in Java application development.

[0048] Through the getBean() method of the ListableBeanFactory class in the Spring framework, the corresponding bean object is obtained using the bean name, thereby satisfying the conditions for executing the retry method using Java (a programming language) reflection technology. The retry method can be executed multiple times to handle abnormal situations.

[0049] According to the technical solution provided in the embodiment of the present application, when an abnormal situation is detected, the retry method object and the corresponding retry class stored in the database can be called according to the data information corresponding to the abnormal situation to retry the abnormal situation, so as to handle the abnormal situation quickly and flexibly. At the same time, according to the embodiment provided by the present application, the retry class is executed by means of retry annotation, and the location of the abnormal situation can be located according to the data information of the abnormal situation, and the retry method is executed for the abnormal situation, rather than executing the retry method for the entire microservice, thereby reducing the data and steps for executing the retry and improving the speed of executing the retry method.

[0050] At the same time, the retry class of the retry method object can be called from the database, and the return value of the corresponding idempotent function object in the database can be called according to the retry class through the retry annotation. Since the data such as the retry class, idempotent function object and return value are stored in the database, they can be called multiple times to execute the retry method multiple times, so that the retry method is not affected by factors such as restart and execution failure, thereby improving the durability of the retry method.

[0051] In some embodiments, calling a corresponding retry class stored in a database based on the retry mode object and executing the retry class includes:

[0052] Determine whether there is an idempotent function object in the retry class. The idempotent function object includes the corresponding idempotent function and the return value of the idempotent function;

[0053] When there is an idempotent function object in the retry class, determine the function category of the idempotent function. The function category includes retry idempotent functions and non-retry idempotent functions. The retry idempotent function represents an idempotent function that is not called for the first time, and the non-retry idempotent function represents an idempotent function that is called for the first time.

[0054] If the function category of the idempotent function is a retry-type idempotent function, the return value of the idempotent function object of the corresponding idempotent function is obtained in the database based on the idempotent function as the return value corresponding to the current idempotent function object;

[0055] When the return value is empty, the idempotent function is executed to determine the return value corresponding to the current idempotent function object.

[0056] Among them, there is an idempotent function object in the retry class.

[0057] There may or may not be a corresponding idempotent function object in the retry class. After obtaining the retry mode object, it is determined whether there is an idempotent function object in the retry class corresponding to the database. The idempotent function object includes the corresponding idempotent function and the return value of the idempotent function.

[0058] When it is determined that there is a corresponding idempotent function object in the retry class, the function category of the idempotent function corresponding to the idempotent function object is determined, wherein the function category includes a retry class idempotent function and a non-retry class idempotent function. The retry class idempotent function represents an idempotent function that is not called for the first time, and the non-retry class idempotent function represents an idempotent function that is called for the first time. It can be understood that the retry class idempotent function and the non-retry class are determined based on the number of times the retry class calls the idempotent function, and do not represent whether the idempotent function is executed successfully or failed.

[0059] If the function category of the idempotent function is a retry-type idempotent function, the return value of the idempotent function object of the corresponding idempotent function is obtained in the database according to the idempotent function, and the return value is used as the return value corresponding to the current idempotent function object. If the idempotent function does not obtain the return value corresponding to the idempotent function object, the return value is determined to be empty, and the idempotent function is executed to determine the return value corresponding to the current idempotent function object.

[0060] According to the technical solution provided in the embodiment of the present application, it is possible to query in the database whether the idempotent function object has a return value based on the idempotent function object called by the retry class. If the database has a return value corresponding to the idempotent function object, the current idempotent function object is controlled to obtain the corresponding return value as the return value of the current idempotent function object. If it does not exist, the idempotent function corresponding to the idempotent function object is executed to determine the corresponding return value. Therefore, when the retry method is executed through the retry annotation, the corresponding retry class, idempotent function object and the corresponding return value are directly retrieved from the database, so that multiple retries can be achieved until the retry is successful and the abnormal situation can be solved.

[0061] In some embodiments, when the return value is null, executing the idempotent function to determine the return value corresponding to the current idempotent function object includes:

[0062] Execute the idempotent function and determine the return value of the idempotent function;

[0063] Create an idempotent function object in the database and store the idempotent function object in an idempotent function list object.

[0064] The idempotent function object also includes the idempotent function name and the execution order of the idempotent function, and the execution order represents the calling order and position of the idempotent function.

[0065] The same idempotent function object may be called multiple times by the same retry class, and the calling interfaces are inconsistent. Therefore, when the idempotent function object is called through different retry mode objects, the idempotent function corresponding to the idempotent function object, the return value of the idempotent function, and the execution order of the idempotent function are the same.

[0066] The execution order of the idempotent function is the calling order and calling position of the idempotent function.

[0067] When the return value corresponding to the idempotent function object in the database is empty, it means that the idempotent function object is not called for the first time, but the corresponding idempotent function failed to execute when the idempotent function object was called before. The idempotent function is executed according to the idempotent function object to determine the return value of the idempotent function, and the return value is used as the return value of the idempotent function object corresponding to the idempotent function.

[0068] Continuing with the above example, if the idempotent function is executed successfully, an idempotent function object is created in the database, and the idempotent function object is stored in the idempotent function list object in the database to update the return value of the idempotent function object stored in the database. The idempotent function object includes the idempotent function, the name of the idempotent function, the execution order of the idempotent function, and the return value of the idempotent function.

[0069] If the idempotent function fails to execute, the return value of the idempotent function object is determined to be still empty, and the return value of the corresponding idempotent function object in the database is not updated. At the same time, the retry method is stopped, and the failure of the idempotent function object corresponding to the idempotent function is used as an alarm message, and the alarm message is displayed on the display screen to inform the operation and maintenance personnel and technical personnel of the reason for the failure of the retry method execution and the corresponding positioning.

[0070] In the embodiments provided in the present application, the number of executions of the retry method can be set. For example, the retry method can be set to be executed repeatedly until the retry method is successfully executed, or the retry method can be set to be executed once. If successful, the next step is performed. If it fails, the operation and maintenance personnel and technical personnel perform data on the idempotent function object according to the alarm information, and execute the retry method again after processing.

[0071] According to the technical solution provided in the embodiment of the present application, when it is determined that the return value of an idempotent function object is empty and the function type of the idempotent function corresponding to the idempotent function object is a retry-type idempotent function, the idempotent function can be executed to determine the return value of the idempotent function object as the return value of the current idempotent function object, thereby triggering the automatic execution of the retry method, which can reduce the workload of operation and maintenance personnel.

[0072] In some embodiments, the method further comprises:

[0073] If the idempotent function is a non-retry function, execute the idempotent function and determine the return value corresponding to the idempotent function;

[0074] When the idempotent function is executed successfully, the return value is saved to the database through the thread local variable.

[0075] When the function category of the idempotent function is a non-retry function, it means that the idempotent function is called for the first time by the retry class to execute the retry method and execute the idempotent function. When the idempotent function is executed successfully, the idempotent function, the name of the idempotent function, the execution order of the idempotent function and the return value are encapsulated into an idempotent function object and saved in the thread local variable ThreadLocal.

[0076] Continuing with the above example, when the retry class calls the idempotent function object, it obtains the idempotent function object from ThreadLocal and assigns it the identity field value of the retry method object, so that the idempotent function in the retry method can be associated with the retry method, and the idempotent function object is saved in the ES database. When the retry class retry() method is executed, the idempotent function object can be directly called in the database.

[0077] According to the technical solution provided in the embodiment of the present application, when a non-retry idempotent function object is called, the idempotent function corresponding to the idempotent function object can be executed and associated with the retry class, so that the return value of the idempotent function object can be directly called in the database when it is called again subsequently.

[0078] In an exemplary embodiment of the present application, the execution of the retry method can be controlled by a retry start instruction. According to the retry start instruction and the retry mode object, the retry class stored in the database is called to execute the retry method, resolve abnormal situations, and control the execution of the retry method.

[0079] Among them, the number of times the retry method is executed can be set in the start retry instruction. For example, it can be set to stop executing the retry method when it is detected that the retry method is executed successfully, or provide an interface for customizing the number of executions so that the retry method is executed according to the custom number of executions. For example, if the custom number of executions is 3 times, the retry method will be executed 3 times or stop after successful execution. The retry method will be executed when an abnormal situation occurs again and the start retry instruction is received.

[0080] In another exemplary embodiment of the present application, the retry mode object, the execution order of the current idempotent function, the return value corresponding to the current idempotent function object and the execution status of the retry class are recorded in the database, and the above parameters are recorded and saved as system log data, so that the system log can be printed for operation and maintenance personnel and developers to view.

[0081] Figure 3 This is a schematic diagram of a retry execution process provided by an embodiment of the present application. Figure 3 As shown, an abnormal situation is monitored, and the data information corresponding to the abnormal situation is obtained. According to the data information, all retry mode objects and corresponding idempotent function list objects that have not been successfully executed are queried in the ES database. Each retry class is traversed, and the bean name, the signature of the retry class, and the retry class parameters are obtained from the retry mode object. The bean object is found by the bean name, and the corresponding Java method is found by the signature of the class. The retry class is executed using Java reflection technology. The execution process of the retry class includes the idempotent function that needs to be executed. The idempotent function list object is searched to see whether the idempotent function to be executed is included, that is, the idempotent function with the return value saved in the database. If so, the idempotent function object and the corresponding return value are obtained from the idempotent function list object, and the idempotent function is no longer executed. After obtaining the return value, the retry class is continued to be executed. If not, the corresponding idempotent function is executed. When the corresponding idempotent function is successfully executed, the retry class is continued to be executed.

[0082] Among them, Java reflection technology is a technology for dynamically obtaining fields, methods, and execution methods of Java classes.

[0083] It should be understood that the size of the serial numbers of the steps in the above embodiments does not mean the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of the present application.

[0084] All the above optional technical solutions can be arbitrarily combined to form optional embodiments of the present application, which will not be described one by one here.

[0085] The following is an embodiment of the device of the present application, which can be used to execute the embodiment of the method of the present application. For details not disclosed in the embodiment of the device of the present application, please refer to the embodiment of the method of the present application.

[0086] Figure 4 Schematic diagram of a retry execution device provided in an embodiment of the present application. Figure 4 As shown, the retry execution device includes:

[0087] The monitoring module 401 is configured to monitor the execution status of each microservice, including abnormal and normal conditions;

[0088] The acquisition module 402 is configured to acquire data information of the abnormal situation when an abnormal situation occurs in the microservice;

[0089] The query module 403 is configured to query the database based on the data information to determine the retry mode object corresponding to the data information included in the database, where the retry mode object includes a retry object name, a retry class name, a retry class parameter, and a retry class parameter type;

[0090] An execution module 404 is configured to call a corresponding retry class stored in a database based on the retry mode object, and execute the retry class to retry the abnormal situation by means of a retry annotation;

[0091] The retry annotation method is to use the retry mode object as the interface of the retry class to call the idempotent function object, call the corresponding idempotent function object based on the interface, and determine the return value of the idempotent function object.

[0092] In some embodiments, there is an idempotent function object in the retry class, and the execution module 404 is configured to call the corresponding retry class stored in the database based on the retry mode object, and execute the retry class for:

[0093] Determine whether there is an idempotent function object in the retry class. The idempotent function object includes the corresponding idempotent function and the return value of the idempotent function;

[0094] When there is an idempotent function object in the retry class, determine the function category of the idempotent function. The function category includes retry idempotent functions and non-retry idempotent functions. The retry idempotent function represents an idempotent function that is not called for the first time, and the non-retry idempotent function represents an idempotent function that is called for the first time.

[0095] If the function category of the idempotent function is a retry-type idempotent function, the return value of the idempotent function object of the corresponding idempotent function is obtained in the database based on the idempotent function as the return value corresponding to the current idempotent function object;

[0096] When the return value is empty, the idempotent function is executed to determine the return value corresponding to the current idempotent function object.

[0097] In some embodiments, the idempotent function object further includes the idempotent function name and the idempotent function execution order, the execution order represents the calling order and position of the idempotent function, and the execution module 404 is configured to execute the idempotent function to determine the return value corresponding to the current idempotent function object when the return value is null, for:

[0098] Execute the idempotent function and determine the return value of the idempotent function;

[0099] Create an idempotent function object in the database and store the idempotent function object in an idempotent function list object.

[0100] In some embodiments, the execution module 404 is configured to further:

[0101] If the idempotent function is a non-retry function, execute the idempotent function and determine the return value corresponding to the idempotent function;

[0102] When the idempotent function is executed successfully, the return value is saved to the database through the thread local variable.

[0103] In some embodiments, the execution module 404 is configured to, before calling the corresponding retry class stored in the database based on the retry mode object, further be used to:

[0104] Receive retry start instruction;

[0105] Based on the retry start instruction and the retry mode object, the corresponding retry class saved in the database is called.

[0106] In some embodiments, the monitoring module 401 is configured to monitor the execution status of each microservice, including abnormal conditions and normal conditions, and is also used to:

[0107] Add retry annotations to each microservice in the preset way. The retry annotations include retry mode objects, retry classes, idempotent functions, and idempotent function objects.

[0108] In some embodiments, the execution retry device is further configured to:

[0109] The retry mode object, the execution order of the current idempotent function, the return value corresponding to the current idempotent function object and the execution status of the retry class are recorded in the database, and the execution status includes a successful execution status and an unsuccessful execution status, so as to be recorded and saved as a system log.

[0110] Figure 5 Schematic diagram of an electronic device 5 provided in an embodiment of the present application. Figure 5 As shown, the electronic device 5 of this embodiment includes: a processor 501, a memory 502, and a computer program 503 stored in the memory 502 and executable on the processor 501. When the processor 501 executes the computer program 503, the steps in the above-mentioned method embodiments are implemented. Alternatively, when the processor 501 executes the computer program 503, the functions of the modules / units in the above-mentioned device embodiments are implemented.

[0111] The electronic device 5 may be a desktop computer, a notebook, a PDA, a cloud server, or other electronic device. The electronic device 5 may include, but is not limited to, a processor 501 and a memory 502. Those skilled in the art will appreciate that Figure 5The electronic device 5 is merely an example and does not limit the electronic device 5 , and may include more or less components than those shown in the figure, or different components.

[0112] The processor 501 may be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc.

[0113] The memory 502 may be an internal storage unit of the electronic device 5, for example, a hard disk or memory of the electronic device 5. The memory 502 may also be an external storage device of the electronic device 5, for example, a plug-in hard disk, a smart media card (SMC), a secure digital (SD) card, a flash card, etc. equipped on the electronic device 5. The memory 502 may also include both an internal storage unit of the electronic device 5 and an external storage device. The memory 502 is used to store computer programs and other programs and data required by the electronic device.

[0114] Those skilled in the art can clearly understand that for the convenience and simplicity of description, only the division of the above-mentioned functional units and modules is used as an example. In actual applications, the above-mentioned functions can be assigned to different functional units and modules as needed, that is, the internal structure of the device can be divided into different functional units or modules to complete all or part of the functions described above. The functional units and modules in the embodiments can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The above-mentioned integrated unit can be implemented in the form of hardware or in the form of software functional units.

[0115] If the integrated module / 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 present application implements all or part of the processes in the above-mentioned embodiment method, and can also be completed by instructing the relevant hardware through a computer program. The computer program can be stored in a computer-readable storage medium, and the computer program can implement the steps of the above-mentioned various method embodiments when executed by the processor. The computer program may include computer program code, and the computer program code may be in source code form, object code form, executable file or some intermediate form. The computer-readable medium may include: any entity or device capable of carrying computer program code, recording medium, U disk, mobile hard disk, magnetic disk, optical disk, computer memory, read-only memory (ROM), random access memory (RAM), electric carrier signal, telecommunication signal and software distribution medium. It should be noted that the content contained in the computer-readable medium can be appropriately increased or decreased according to the requirements of legislation and patent practice in the jurisdiction. For example, in some jurisdictions, according to legislation and patent practice, the computer-readable medium does not include electric carrier signals and telecommunication signals.

[0116] The above embodiments are only used to illustrate the technical solutions of the present application, rather than to limit them. Although the present application has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. These modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present application, and should all be included in the protection scope of the present application.

Claims

1. A retry execution method, characterized in that: include: Monitor the execution status of each microservice, including abnormal and normal conditions; When the microservice encounters the abnormal situation, obtain data information of the abnormal situation; Performing a query in a database based on the data information to determine that the database includes a retry mode object corresponding to the data information, wherein the retry mode object includes a retry object name, a retry class name, a retry class parameter, and a retry class parameter type; Based on the retry mode object, a corresponding retry class stored in the database is called, and the retry class is executed to retry the abnormal situation by means of a retry annotation; The retry annotation method is to use the retry mode object as the interface of the retry class to call the idempotent function object, call the corresponding idempotent function object based on the interface, and determine the return value of the idempotent function object; The idempotent function object exists in the retry class, and the idempotent function object includes the corresponding idempotent function and the return value of the idempotent function. The retry method object is based on the retry mode object and calls the corresponding retry class stored in the database to execute the retry class, including: When the idempotent function object exists in the retry class, the function category of the idempotent function is determined, the function category includes a retry class idempotent function and a non-retry class idempotent function, the retry class idempotent function represents the idempotent function that is not called for the first time, and the non-retry class idempotent function represents the idempotent function that is called for the first time; If the function category of the idempotent function is the retry-class idempotent function, based on the idempotent function, obtaining in the database a return value of the idempotent function object corresponding to the idempotent function as a return value corresponding to the current idempotent function object; When the return value is empty, executing the idempotent function to determine the return value corresponding to the current idempotent function object; If the idempotent function is a non-retry function, execute the idempotent function and determine the return value corresponding to the idempotent function; When the idempotent function is executed successfully, the return value is saved to the database through the thread local variable.

2. The method according to claim 1, characterized in that The idempotent function object also includes the idempotent function name and the idempotent function execution order, wherein the execution order represents the calling order and position of the idempotent function. When the return value is empty, the idempotent function is executed to determine the return value corresponding to the current idempotent function object, including: Executing the idempotent function and determining a return value of the idempotent function; The idempotent function object is created in the database, and the idempotent function object is stored in an idempotent function list object.

3. The method according to claim 1, characterized in that Before calling the corresponding retry class stored in the database based on the retry mode object, it also includes: Receive retry start instruction; The corresponding retry class stored in the database is called based on the retry start instruction and the retry mode object.

4. The method according to claim 1, characterized in that: Monitor the execution status of each microservice, including abnormal and normal situations, and also include: A retry annotation is added to each of the microservices in a preset manner, wherein the retry annotation includes the retry mode object, the retry class, the idempotent function and the idempotent function object.

5. The method according to any one of claims 1 to 4, characterized in that Also includes: The retry mode object, the current execution order of the idempotent function, the return value corresponding to the current idempotent function object and the execution status of the retry class are recorded in the database, and the execution status includes a successful execution status and an unsuccessful execution status, so as to be recorded and saved as a system log.

6. A retry execution device, characterized in that: include: A monitoring module is configured to monitor the execution status of each microservice, including abnormal and normal conditions; An acquisition module is configured to acquire data information of the abnormal situation when the abnormal situation occurs in the microservice; A query module is configured to query a database based on the data information to determine that the database includes a retry mode object corresponding to the data information, wherein the retry mode object includes a retry object name, a retry class name, a retry class parameter, and a retry class parameter type; an execution module configured to call a corresponding retry class stored in the database based on the retry mode object, and execute the retry class to retry the abnormal situation by means of a retry annotation; The retry annotation method is to use the retry mode object as the interface of the retry class to call the idempotent function object, call the corresponding idempotent function object based on the interface, and determine the return value of the idempotent function object; The idempotent function object exists in the retry class, and the idempotent function object includes the corresponding idempotent function and the return value of the idempotent function. The execution module is configured as follows: When the idempotent function object exists in the retry class, the function category of the idempotent function is determined, the function category includes a retry class idempotent function and a non-retry class idempotent function, the retry class idempotent function represents the idempotent function that is not called for the first time, and the non-retry class idempotent function represents the idempotent function that is called for the first time; If the function category of the idempotent function is the retry-class idempotent function, based on the idempotent function, obtaining in the database a return value of the idempotent function object corresponding to the idempotent function as a return value corresponding to the current idempotent function object; When the return value is empty, executing the idempotent function to determine the return value corresponding to the current idempotent function object; If the idempotent function is a non-retry function, execute the idempotent function and determine the return value corresponding to the idempotent function; When the idempotent function is executed successfully, the return value is saved to the database through the thread local variable.

7. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 5 are implemented.

8. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 5 are implemented.

Citation Information

Patent Citations

  • Fault-tolerant retry method and device and terminal

    CN111078442A

  • Data processing method and device and electronic equipment

    CN112667439A