Asynchronous request processing method and device, equipment and storage medium
By obtaining and encapsulating the functional functions required for asynchronous request processing, and uniformly processing asynchronous requests, the problems of duplication of code, improper error handling and complicated scenarios in the existing technology are solved, and simpler and more efficient Asynchronous request processing.
Patent Information
- Application Number
- CN202411547235.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-31
- Publication Date
- 2025-02-14
AI Technical Summary
In the prior art, the asynchronous request processing methods have problems such as duplicate code, improper error handling, lack of built-in functions, and complicated processing of complex scenarios, resulting in high development difficulty and difficult code maintenance.
Provides an asynchronous request processing method, which uniformly handles asynchronous requests by obtaining and encapsulating idiomatic function functions, complex scene function functions and unified interface state management functions, so as to prevent developers from implementing state management logic by themselves.
It reduces development difficulty and workload, unifies state management, simplifies the call of complex scenario functions, and reduces code complexity and maintenance difficulty.
Smart Images

Figure CN119440673A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of communication technology, and in particular to an asynchronous request processing method, device, equipment and medium. Background Art
[0002] Modern society is full of uncertainty, and risks such as natural disasters, diseases, and accidents are everywhere. Insurance can help people deal with these unforeseen risks and provide financial protection. The business processes of the insurance industry usually involve a large amount of data processing, customer interaction, and background operations, which often need to be completed through network requests, including asynchronous requests. Asynchronous requests play an important role in the insurance industry.
[0003] However, in the process of managing asynchronous requests, developers need to manually manage various states of asynchronous requests (such as loading state, error state or data state, etc.), which easily leads to code duplication and improper error handling. In addition, traditional asynchronous request processing usually relies on traditional asynchronous request libraries, which lack built-in common functions, such as polling and anti-shake functions. These functions need to be implemented by developers themselves during the processing of asynchronous requests, which increases the difficulty and workload of development. In addition, these functions require developers to design and implement state management logic by themselves, which makes it difficult to unify and maintain state management when different developers are involved. For complex asynchronous request scenarios, such as concurrent requests, request dependencies, and paging loading, the processing of traditional methods is usually cumbersome, making the implementation code complex and difficult to maintain.
[0004] In summary, there is an urgent need for an asynchronous request processing method in the prior art to solve various problems existing in the current asynchronous request processing method. Summary of the invention
[0005] The present invention provides an asynchronous request processing method, device, equipment and storage medium to solve various problems existing in the asynchronous request processing method in the prior art.
[0006] In a first aspect, an asynchronous request processing method is provided, comprising:
[0007] Obtaining a function to be called required for processing an asynchronous request, wherein the function to be called includes a conventional function, a complex scenario function, and a state management function with a unified interface;
[0008] Encapsulate all the functions to be called;
[0009] Sending a target asynchronous request to trigger a function function corresponding to the target asynchronous request in the to-be-called function function to process the target asynchronous request;
[0010] When the function function corresponding to the target asynchronous request is the state management function, the state characterization variables corresponding to each state of the target asynchronous request are determined, and the current state of the target asynchronous request is reflected according to the current value of the state characterization variable.
[0011] In a second aspect, an asynchronous request processing device is provided, comprising:
[0012] An acquisition module, used to acquire the function functions to be called required for processing asynchronous requests, wherein the function functions to be called include conventional function functions, complex scenario function functions, and state management functions with a unified interface;
[0013] An encapsulation module, used for encapsulating all the functions to be called;
[0014] A sending module, used for sending a target asynchronous request, triggering a function function corresponding to the asynchronous request in the to-be-called function function, so as to process the target asynchronous request;
[0015] A determination module is used to determine the state characterization variables corresponding to each state of the target asynchronous request when the function function corresponding to the target asynchronous request is the state management function, and reflect the current state of the target asynchronous request according to the current value of the state characterization variable.
[0016] In a third aspect, a computer 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-mentioned asynchronous request processing method when executing the computer program.
[0017] In a fourth aspect, a computer-readable storage medium is provided, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of the above-mentioned asynchronous request processing method are implemented.
[0018] In the scheme implemented by the above-mentioned asynchronous request processing method, various functional functions required for asynchronous requests, such as conventional functional functions and complex scene functional functions, are sealed together. In this way, when it is necessary to call conventional functional functions, complex scene functional functions and state management functions during the asynchronous request processing, it is no longer necessary for the developer to implement them by themselves during the asynchronous request processing, thereby reducing the development difficulty and workload, and these functions are packaged together for use after unified settings, avoiding the problem that different developers design and implement state management logic by themselves, making state management difficult to unify and maintain. In addition, the complex scene functional functions are also encapsulated in this scheme, so that the complex scene functions can be directly called during asynchronous requests, thereby avoiding the need to build complex scene functional functions on site when calling complex scene functions in traditional methods, and the problem that the implementation code is complex and difficult to maintain due to the cumbersome process. In summary, this scheme can solve various problems existing in the asynchronous request processing method in the prior art. BRIEF DESCRIPTION OF THE DRAWINGS
[0019] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the accompanying drawings required for use in the description of the embodiments of the present invention will be briefly introduced below. Obviously, the accompanying drawings in the following description are only some embodiments of the present invention. For ordinary technicians in this field, other accompanying drawings can be obtained based on these accompanying drawings without paying creative labor.
[0020] Figure 1 is a schematic diagram of an application environment of an asynchronous request processing method in one embodiment of the present invention;
[0021] Figure 2 It is a flowchart of an asynchronous request processing method according to an embodiment of the present invention;
[0022] Figure 3 yes Figure 2 A schematic flow chart of a specific implementation of step S30;
[0023] Figure 4 is a schematic diagram of the structure of an asynchronous request processing device in one embodiment of the present invention;
[0024] Figure 5 is a schematic diagram of a structure of a computer device in one embodiment of the present invention;
[0025] Figure 6 It is another structural schematic diagram of a computer device in one embodiment of the present invention. DETAILED DESCRIPTION
[0026] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0027] The asynchronous request processing method provided by the embodiment of the present invention can be applied in Figure 1 In an application environment, the client communicates with the server through a network. The server can obtain the function function to be called required to process the asynchronous request, and the function function to be called includes a conventional function function, a complex scenario function and a state management function with a unified interface; encapsulate all the function functions to be called; send a target asynchronous request, trigger the function function corresponding to the target asynchronous request in the function function to be called to process the target asynchronous request; when the function function corresponding to the target asynchronous request is the state management function, determine the state characterization variable corresponding to each state of the target asynchronous request, and reflect the current state of the target asynchronous request according to the current value of the state characterization variable. Among them, the client can be but is not limited to various personal computers, laptops, smart phones, tablet computers and portable wearable devices. The server can be implemented with an independent server or a server cluster consisting of multiple servers. The present invention is described in detail below through specific embodiments.
[0028] See also Figure 2 As shown, Figure 2 A flowchart of an asynchronous request processing method provided by an embodiment of the present invention includes the following steps:
[0029] Step S10, obtaining the function to be called required to process the asynchronous request.
[0030] The function functions to be called include conventional function functions, complex scenario function functions and state management functions with a unified interface.
[0031] It should be noted that the asynchronous request in this step can be multiple pre-defined asynchronous requests or one asynchronous request; the function to be called required to process the asynchronous request can be multiple function calls that need to be called during the asynchronous request processing or one function call that needs to be called during the asynchronous request processing. As a specific example, for example, the asynchronous request in this step can be a claims processing asynchronous request in the insurance industry. The function called during the claims processing asynchronous request can include a data verification function to verify whether the data of the claim application is complete and the format is correct, a preprocessing function to clean and standardize the input data to ensure data consistency and security, and a payment processing function to calculate the claim amount, start the payment process, and verify the payment status.
[0032] It should be noted that the customary function is a function that is called frequently when processing asynchronous requests. The customary function can be set according to the specific needs of the application. For example, when processing the target asynchronous request, the number of calls of each function called during the asynchronous request processing is counted, and the function whose number of calls exceeds the first threshold is set as the customary function. The complex scenario function is a function that calls a more complex program. It can be set according to the specific needs of the application. For example, it can be a concurrent request function, which will initiate multiple independent requests at the same time and wait for the results of all requests. For example, it can also be a paging loading function, which will divide a large amount of data into multiple pages, and only load a part of the data each time. The user needs to turn the page to view more data. The state management function is a function function used to determine the current state of the asynchronous request. For example, the state management function can be a function function used to determine the current loading state of the asynchronous request, or it can be a function function used to determine the current error state of the asynchronous request. The state management function with a unified interface indicates that all state management functions have a unified interface. It can be understood that the state management function has a unified interface. First, all state management functions follow the same interface, so that developers can call these function functions in a consistent way, reducing the learning cost. The unified interface makes the code more consistent and concise, easy to maintain and update, and when a new state management function needs to be added, it is only necessary to implement the unified interface without modifying the existing calling logic. Each state management function can be developed and tested as an independent module, which improves the modularity of the system.
[0033] Step S20, encapsulating all the function to be called.
[0034] It should be noted that encapsulating all the function functions to be called means encapsulating all the function functions as a whole to form an independent asynchronous request processing tool. In this way, when testing all the function functions to be called of the asynchronous request, the function functions to be called in the asynchronous request processing tool can be directly tested through the value returned by the asynchronous request processing tool.
[0035] Step S30, sending a target asynchronous request, triggering a function function corresponding to the target asynchronous request in the to-be-called function function, so as to process the target asynchronous request.
[0036] It should be noted that different asynchronous requests usually call different function functions during the processing process. For example, in the insurance industry's policy management business, concurrent asynchronous requests can be used for the basic information of the user's policy and related claims records. The function functions called can be user basic information acquisition functions and user policy information acquisition functions, etc. Paginated loading asynchronous requests can be used to display the customer's claims records, loading only a part of the records each time. The function functions called can include a function for obtaining a policy list with a specified page number and number of pages per page from the backend interface, a function responsible for updating the obtained policy list to the page, and a function for processing paging logic.
[0037] In one embodiment of the present invention, the triggering of the function function corresponding to the target asynchronous request in the to-be-called function function in step S30 to process the target asynchronous request includes:
[0038] Step S311, when the function function corresponding to the target asynchronous request is a request retry function, determining the request retry count and retry interval of the target asynchronous request according to the error state of the target asynchronous request;
[0039] Step S312: resend the target asynchronous request according to the request retry count and the retry interval.
[0040] It should be noted that when an asynchronous request has an error or fails, the request retry function will be called to retry the asynchronous request.
[0041] It is understandable that in order to improve the request efficiency and accuracy of asynchronous requests, the number of request retries and the retry interval of the asynchronous requests are set. It is understandable that the number of request retries is inversely proportional to the retry interval.
[0042] It is understandable that since the reason for triggering the request retry function is that the asynchronous request has an error or fails, determining the number of request retries and the retry interval time that are adapted to the error state according to the error state of the asynchronous request can effectively save the time for the asynchronous request to succeed while ensuring that the asynchronous request can succeed. Specifically, the number of request retries and the retry interval time determined according to the error state of the target asynchronous request can be set according to the specific error state of the target asynchronous request in the actual application, and are not limited in detail here.
[0043] In one embodiment of the present invention, determining the number of request retries and the retry interval of the target asynchronous request according to the error status of the target asynchronous request in step S311 includes the following steps.
[0044] Step S3111, when the error state of the target asynchronous request is a permanent error, canceling the retry of the target asynchronous request;
[0045] Step S3112, when the error state of the target asynchronous request is a temporary error, increasing the number of request retries of the target asynchronous request and / or reducing the retry interval;
[0046] Step S3113, when reducing the retry interval, control the retry interval to increase exponentially with the increase of the number of request retries, and the growth rate of the exponential growth is inversely proportional to the severity level of the temporary error.
[0047] It should be noted that permanent errors of target asynchronous requests are irrecoverable errors, such as data validation errors (such as invalid data format or missing required fields, etc.), permission and authentication errors (the resource that the request attempts to access is not authorized, identity authentication fails or permissions are insufficient, etc.), and errors such as resource non-existence. It is understandable that when the error status of the target asynchronous request is a permanent error, resending the asynchronous request will not succeed, so canceling the retry of the asynchronous request can effectively save related resources.
[0048] It should be noted that the temporary error of the target asynchronous request is a recoverable error (such as network connection timeout, network interruption, server overload or file system busy errors). In this way, in the process of continuously performing the target asynchronous request, the target asynchronous request will succeed in a certain asynchronous request. Therefore, step S3112 can make the target asynchronous request succeed more quickly by controlling to increase the number of request retries of the target asynchronous request and / or reducing the retry interval time.
[0049] It should be noted that in step S3113, the severity level of the temporary error can be set according to the specific needs of the application, and is not specifically limited here. The proportional relationship between the exponential growth rate and the severity level of the temporary error can also be set according to the specific needs of the application.
[0050] It is understandable that controlling the retry interval to grow exponentially with the increase in the number of retries makes the waiting time grow exponentially with the increase in the number of retries each time a request fails, which can effectively avoid frequent retries in a short period of time causing excessive server load or network congestion. And the growth rate of exponential growth is inversely proportional to the severity of the temporary error, which means that for lighter errors, we hope to restore the service faster, so the speed of exponential growth can be faster. For example, each retry interval is multiplied by a larger cardinality; for more serious errors, we need to give the system more time to recover, so the speed of exponential growth should be slower. For example, each retry interval is multiplied by a smaller cardinality, so that resources can be used reasonably.
[0051] In one embodiment of the present invention, the triggering of the function function corresponding to the target asynchronous request in the to-be-called function function in step S30 to process the target asynchronous request includes:
[0052] Step S321, when the function function corresponding to the target asynchronous request is a configuration option function, obtaining the configuration function function configured by the user for the target asynchronous request;
[0053] Step S322, when the configuration function is a refresh dependent function, if a preset array element changes, a new target asynchronous request is triggered;
[0054] Step S323, when the configuration function is a ready function, detecting the output value of the ready function, triggering a new target asynchronous request when the output value is a first output value, and stopping triggering subsequent operations when the output value is a second output value;
[0055] Step S324, when the configuration function is a cache key function, set the data identifier corresponding to the target asynchronous request, cache the request data obtained by the target asynchronous request, and return the request data to the inside of the component when the component is initialized.
[0056] It should be noted that the configuration option function is a function used to control and optimize the asynchronous request behavior. These function functions allow developers to adjust the request behavior according to specific needs, so as to better adapt to different application scenarios. In this embodiment, the specific configuration function can be set according to the specific needs of the developer in the application.
[0057] It should be noted that the refresh dependency function is used to trigger a new asynchronous request when certain states or data change. By using the refresh dependency function, you can monitor the state changes in real time and initiate new requests or perform corresponding operations in a timely manner to ensure that the application is always up to date. Reasonable configuration of dependencies can help avoid unnecessary re-rendering and calculations, and clearly indicate which variables are the key factors that trigger certain behaviors, which helps to increase the predictability of program behavior and debugging efficiency. Developers can quickly understand which changes will lead to subsequent actions by viewing the dependency list. The preset array elements can be set according to the specific needs of the application, and are not specified in detail here. For example, if the target asynchronous request is a request for a car insurance policy, the array elements may include the insured's age, gender, occupation, and driving record, so that if the insured's driving record changes (for example, a new traffic accident), the relevant elements in the array can be updated, thereby triggering a new target asynchronous request to re-evaluate the premium.
[0058] Understandably, the ready function allows you to perform conditional checks before initiating an asynchronous request. This ensures that requests are made only when certain conditions are met, thus avoiding invalid or unnecessary requests. In addition, the ready function allows for better resource management by ensuring that preconditions have been met. For example, you may not want to initiate a new request until some data has been loaded, which can reduce the pressure on the server. Moreover, the ready function can improve the user experience by avoiding initiating requests at inappropriate times. For example, if a component is not ready to receive data, initiating a request too early may result in errors or inconsistent interface displays.
[0059] It is understandable that the cache key function generates a unique identifier for storing and retrieving data in the cache. This avoids repeated requests for the same data, thereby reducing network traffic and server load. And the cache key function can significantly improve the responsiveness and performance of the application by quickly obtaining data from the cache. Especially in the case where data is frequently requested but does not change much, caching can bring great performance improvements. In addition, the cache key function can ensure that consistent data is returned in a short time through caching, even if the data has changed in the background. This is very useful for some scenarios with high requirements for data consistency.
[0060] In one embodiment of the present invention, the step of setting the data identifier corresponding to the target asynchronous request in step S324 includes:
[0061] Step S3241, determining the core attributes of the request data;
[0062] Step S3242, extracting a data segment for expressing the core attribute in the request data according to the core attribute of the request data;
[0063] Step S3243, generating the data identifier according to the data segment of the core attribute.
[0064] It should be noted that the core attributes of the request data in step S3241 are key information or attributes in the request data, which can uniquely identify a piece of data. As a specific example, assuming that an asynchronous request for an insurance claim is processed, the core attributes may include the claim number, customer number, and insurance policy number.
[0065] It should be noted that the method of generating a data identifier based on the data segments of the core attributes can be any feasible method. As a specific example, the data segments of the core attributes can be concatenated to form a string to obtain a data identifier. For example, for an asynchronous request to process an insurance claim, the data identifier can concatenate the claim number, the customer number, and the insurance policy number to generate a data identifier.
[0066] In one embodiment of the present invention, Figure 3 The flowchart shown in step S3243 includes the following steps:
[0067] Step S32431, setting a first weight corresponding to the data segment of the core attribute;
[0068] Step S32432, scoring the requested data according to the importance level of the core attribute, and setting a second weight corresponding to the data score;
[0069] Step S32433, observing in real time the real-time value of the preset evaluation parameter of the request data, and dynamically adjusting the second weight according to the real-time value;
[0070] Step 32437, determining a first weighted value of the data segment of the core attribute and the first weight, and a second weighted value of the data score and the second weight, and calculating a weighted sum of the first weighted value and the second weighted value;
[0071] Step S32438, performing a hash operation on the weighted sum to obtain a data identifier corresponding to the target asynchronous request.
[0072] The data score is proportional to the importance level, and the real-time value is proportional to the value of the second weight.
[0073] It should be noted that in step S32431, the first weight corresponding to the data segment of the core attribute can be set according to the specific needs of the application, but it is necessary to ensure that the first weight is the largest weight among all weights (that is, the largest weight value between the first weight and the second weight).
[0074] It should be noted that in step S32432, each attribute of the requested data may be pre-evaluated according to its importance, and a score corresponding to each unit importance level may be set, so that the requested data may be scored according to the importance level of the core attribute. The corresponding second weight of the data score may be set according to the specific needs of the application.
[0075] It should be noted that the preset evaluation parameters of the request data can be parameters that can score the quality of the request data, and the larger the real-time value of the evaluation parameter, the greater the significance of scoring the request data, and the stronger the reference value of the data score of the request data. In this way, the second weight can be adjusted according to the real-time value, that is, when the data score is more important to the request data, the importance of the data score can be increased. In this way, when the data score is set in the data identifier through a hash operation, the data identifier can better reflect the quality of the request data.
[0076] It should be noted that the hash operation can be implemented by a hash algorithm. The specific hash algorithm can be selected according to the specific needs of the application, for example, it can be a SHA-256 hash algorithm or a SHA-3 hash algorithm.
[0077] In this way, by performing multi-dimensional analysis of the request data (including the importance rating of core attributes and real-time value adjustment), combined with hash operations to generate unique data identifiers, malicious attacks or illegal access can be prevented to a certain extent. Because even if two different requests are similar in some parameters, it is almost impossible for them to produce the same identifier after weighted calculation and hash conversion. In addition, based on different attribute weight settings and dynamic adjustment mechanisms, the system can more reasonably allocate computing resources to requests of different types or importance, ensuring that key tasks are given priority while avoiding resource waste. In addition, by quantifying the importance of each indicator and its impact, it helps the business party better understand the current situation and make more scientific and reasonable decisions accordingly. For example, in the insurance industry, premiums are adjusted according to the risk characteristics of customers.
[0078] In one embodiment of the present invention, after step S32433 and before step S32437, the method further includes:
[0079] Step S32434, obtaining environmental factors of the environment in which the requested data is located;
[0080] Step S32435, observing the influence of the environmental factors on the weighted factors of the data identifiers;
[0081] Step S32436: if the environmental factor has a positive impact on the weighted factor identified by the data, the weight corresponding to the weighted factor is adjusted positively; otherwise, the weight corresponding to the weighted factor is adjusted negatively.
[0082] It should be noted that the environmental factors in step S32434 are factors that can affect the requested data, such as network conditions or server load conditions. The weighting factors are the data segments of the core attributes and the data scores. When the environmental factors have a positive impact on the weighting factors, it proves that under the influence of the current environmental factors, the weighting factors are relatively stable. At this time, the weight of the weighting factors can naturally be increased, so that the obtained data identification is more reliable. On the contrary, the weight of the weighting factors can be reduced, so that the obtained data identification can avoid the influence of environmental factors as much as possible.
[0083] Step S40, when the function function corresponding to the target asynchronous request is the state management function, determine the state representation variables corresponding to each state of the target asynchronous request, and reflect the current state of the target asynchronous request according to the current value of the state representation variable.
[0084] Specifically, the state management function is a functional function that can express the current state of the request. The current state of the request can be any state of the request, such as the loading state of the request, the error state of the request, or the data state of the request. The state representation variable corresponding to the state of the asynchronous request can be any variable that can reflect the current state of the asynchronous request. For example, the state representation variable of the loading state of the request can be a Boolean value, the state representation variable corresponding to the error state of the request can be an error object, and the state representation variable corresponding to the data state of the request can be the state of the data returned by the asynchronous request.
[0085] In this way, all kinds of function functions required for asynchronous requests, such as conventional function functions and complex scene function functions, are sealed together. In this way, when it is necessary to call conventional function functions, complex scene function functions and state management functions during the asynchronous request processing, it is no longer necessary for the developer to implement them by themselves during the asynchronous request processing, thereby reducing the development difficulty and workload. Moreover, these functions are packaged together for use after unified setting, avoiding the problem that different developers design and implement state management logic by themselves, making it difficult to unify and maintain state management. In addition, the complex scene function function is also encapsulated in this solution, so that the complex scene function can be directly called during asynchronous requests, thereby avoiding the problem that the traditional method needs to build a complex scene function on site when calling the complex scene function, and the cumbersome process makes the implementation code complex and difficult to maintain. In summary, the solution provided by the embodiment of the present invention can solve various problems existing in the asynchronous request processing method in the prior art.
[0086] It should be understood that the order of execution of the steps in the above embodiment does not necessarily 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 embodiment of the present invention.
[0087] In one embodiment, an asynchronous request processing device is provided, and the asynchronous request processing device corresponds one-to-one to the asynchronous request processing method in the above embodiment. Figure 4 As shown, the asynchronous request processing device includes an acquisition module 410, an encapsulation module 420, a sending module 430 and a determination module 440. The functional modules are described in detail as follows:
[0088] An acquisition module 410 is used to acquire a function to be called required for processing an asynchronous request, wherein the function to be called includes a conventional function, a complex scenario function, and a state management function with a unified interface;
[0089] The encapsulation module 420 is used to encapsulate all the functions to be called;
[0090] The sending module 430 is used to send a target asynchronous request and trigger a function function corresponding to the asynchronous request in the to-be-called function function to process the target asynchronous request;
[0091] The determination module 440 is used to determine the state characterization variables corresponding to each state of the target asynchronous request when the function function corresponding to the target asynchronous request is the state management function, and reflect the current state of the target asynchronous request according to the current value of the state characterization variable.
[0092] In one embodiment, the sending module 430 is specifically used for:
[0093] When the function function corresponding to the target asynchronous request is a request retry function, determining the request retry count and retry interval of the target asynchronous request according to the error state of the target asynchronous request;
[0094] Resend the target asynchronous request according to the request retry count and the retry interval.
[0095] In one embodiment, the sending module 430 is further configured to:
[0096] When the error state of the target asynchronous request is a permanent error, canceling the retry of the target asynchronous request;
[0097] When the error state of the target asynchronous request is a temporary error, increasing the number of request retries of the target asynchronous request and / or reducing the retry interval;
[0098] When reducing the retry interval, the retry interval is controlled to increase exponentially with the increase of the number of request retries, and the growth rate of the exponential growth is inversely proportional to the severity level of the temporary error.
[0099] In one embodiment, the sending module 430 is specifically used for:
[0100] When the function function corresponding to the target asynchronous request is a configuration option function, obtaining a configuration function configured by a user for the target asynchronous request;
[0101] When the configuration function is a refresh dependent function, if a preset array element changes, a new target asynchronous request is triggered;
[0102] When the configuration function function is a ready function, detecting an output value of the ready function, triggering a new target asynchronous request when the output value is a first output value, and stopping triggering subsequent operations when the output value is a second output value;
[0103] When the configuration function is a cache key function, the data identifier corresponding to the target asynchronous request is set, and the request data obtained by the target asynchronous request is cached, and the request data is returned to the inside of the component when the component is initialized.
[0104] In one embodiment, the sending module 430 is further configured to:
[0105] Determining core attributes of the request data;
[0106] According to the core attribute of the request data, extracting a data segment in the request data for expressing the core attribute;
[0107] The data identifier is generated according to the data segment of the core attribute.
[0108] In one embodiment, the sending module 430 is further configured to:
[0109] Setting a first weight corresponding to the data segment of the core attribute;
[0110] According to the importance level of the core attribute, the request data is scored, and a second weight corresponding to the data score is set, wherein the data score is proportional to the importance level;
[0111] Observe in real time the real-time value of the preset evaluation parameter of the request data, and dynamically adjust the second weight according to the real-time value, wherein the real-time value is proportional to the value of the second weight;
[0112] Determine a first weighted value of the data segment of the core attribute and the first weight, and a second weighted value of the data score and the second weight, and calculate a weighted sum of the first weighted value and the second weighted value;
[0113] A hash operation is performed on the weighted sum to obtain a data identifier corresponding to the target asynchronous request.
[0114] In one embodiment, the sending module 430 is further configured to:
[0115] Acquire environmental factors of the environment in which the requested data is located;
[0116] Observe the degree of influence of the environmental factors on the weighted factors of the data identification;
[0117] If the environmental factor has a positive impact on the weighted factor identified by the data, the weight corresponding to the weighted factor is adjusted positively, otherwise the weight corresponding to the weighted factor is adjusted negatively.
[0118] The present invention provides an asynchronous request processing device, which encapsulates all kinds of function functions required for asynchronous requests, such as conventional function functions and complex scene function functions, together. In this way, when it is necessary to call conventional function functions, complex scene function functions and state management functions during the asynchronous request processing, it is no longer necessary for developers to implement them by themselves during the asynchronous request processing, thereby reducing the development difficulty and workload, and these functions are packaged together for use after unified setting, avoiding the problem that different developers design and implement state management logic by themselves, making state management difficult to unify and maintain. In addition, the complex scene function function is also encapsulated in this solution, so that the complex scene function can be directly called during asynchronous requests, thereby avoiding the problem that in the traditional method, when the complex scene function is called, the complex scene function function needs to be built on site, and the implementation code is complicated and difficult to maintain due to the cumbersome process. In summary, the asynchronous request processing device provided by the present invention can solve various problems existing in the asynchronous request processing method in the prior art.
[0119] For the specific definition of the asynchronous request processing device, please refer to the definition of the asynchronous request processing method above, which will not be repeated here. Each module in the above-mentioned asynchronous request processing device can be implemented in whole or in part by software, hardware and a combination thereof. The above-mentioned modules can be embedded in or independent of the processor in the computer device in the form of hardware, or can be stored in the memory of the computer device in the form of software, so that the processor can call and execute the operations corresponding to the above modules.
[0120] Based on the above asynchronous request processing method, such as Figure 5 As shown, an embodiment of the present invention further provides a schematic diagram of the structure of an asynchronous request processing device, the generating device includes a processor 51 and a memory 52 coupled to the processor 51. The memory 52 stores a computer program, and when the computer program is executed by the processor 51, the processor 51 executes the steps of the asynchronous request processing method in the above embodiment.
[0121] For other details about how the processor 51 in the asynchronous request processing device implements the above technical solution, please refer to the description of the asynchronous request processing method provided in the above invention embodiment, which will not be repeated here.
[0122] Among them, the processor 51 can also be called a CPU (Central Processing Unit), and the processor 51 may be an integrated circuit chip with signal processing capabilities; the processor 51 can also be a general-purpose processor, DSP (Digital Signal Process), ASIC (Application Specific Integrated Circuit), FPGA (Field Programmable Gate Array) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, among which the general-purpose processor can be a microprocessor or the processor 51 can also be any conventional processor, etc.
[0123] like Figure 6 As shown, the embodiment of the present invention also provides a schematic diagram of the structure of a computer-readable storage medium, on which a readable computer program 61 is stored; wherein the computer program 61 can be stored in the above storage medium in the form of a software product, including a number of instructions for enabling a computer device (which can be a personal computer, a server, or a network device, etc.) or a processor to execute all or part of the steps of the method described in each embodiment of the present invention. The aforementioned storage medium includes: U disk, mobile hard disk, magnetic disk or optical disk, ROM (Read-Only Memory), RAM (Random Access Memory) and other media that can store program codes, or terminal devices such as computers, servers, mobile phones, and tablets.
[0124] In the several embodiments provided by the present invention, it should be understood that the disclosed systems, devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of the modules is only a logical function division. There may be other division methods in actual implementation, such as multiple modules 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 an indirect coupling or communication connection through some interfaces, devices or modules, which can be electrical, mechanical or other forms.
[0125] The modules described as separate components may or may not be physically separated, and the components shown as modules may or may not be physical modules, that is, they may be located in one place or distributed on multiple network modules. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0126] In addition, each functional module in each embodiment of the present invention may be integrated into a processing module, or each module may exist physically separately, or two or more modules may be integrated into one module. The above-mentioned integrated module may be implemented in the form of hardware or in the form of a software functional module. If the integrated module is implemented in the form of a software functional module and sold or used as an independent product, it may be stored in a computer-readable storage medium.
[0127] In the above embodiments, all or part of the embodiments may be implemented by software, hardware, firmware or any combination thereof. When implemented by software, all or part of the embodiments may be implemented in the form of a computer program product.
[0128] The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, the process or function described in the embodiment of the present invention is generated in whole or in part. The computer may be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions may be stored in a computer-readable storage medium, or transmitted from one computer-readable storage medium to another computer-readable storage medium. For example, the computer instructions may be transmitted from one website site, computer, server or data center to another website site, computer, server or data center by wired (e.g., coaxial cable, optical fiber, digital subscriber line) or wireless (e.g., infrared, wireless, microwave, etc.) means. The computer-readable storage medium may be any available medium that a computer can store or a data storage device such as a server or data center that includes one or more available media integrated. The available medium may be a magnetic medium (e.g., a floppy disk, a hard disk, a tape), an optical medium), or a semiconductor medium (e.g., an SSD (solid state disk, solid state hard disk)).
[0129] The technical solution provided by the present invention is introduced in detail above. The present invention applies specific examples to illustrate the principle and implementation mode of the present invention. The description of the above embodiments is only used to help understand the method of the present invention and its core idea. At the same time, for those skilled in the art, according to the idea of the present invention, there will be changes in the specific implementation mode and application scope. In summary, the content of this specification should not be understood as limiting the present invention.
[0130] Those skilled in the art will appreciate that embodiments of the present invention may be provided as methods, systems, or computer program products. Therefore, the present invention may take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Moreover, the present invention may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, optical storage, etc.) containing computer-usable program code.
[0131] The present invention is described with reference to flowcharts and / or block diagrams of methods, devices (systems), and computer program products according to the present invention. It should be understood that each process and / or block in the flowchart and / or block diagram, as well as the combination of processes and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0132] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0133] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.
[0134] Obviously, those skilled in the art can make various changes and modifications to the present invention without departing from the spirit and scope of the present invention. Thus, if these modifications and variations of the present invention fall within the scope of the claims of the present invention and their equivalents, the present invention is also intended to include these modifications and variations.
Claims
1. An asynchronous request processing method, characterized in that: include: Obtaining a function to be called required for processing an asynchronous request, wherein the function to be called includes a conventional function, a complex scenario function, and a state management function with a unified interface; Encapsulate all the functions to be called; Sending a target asynchronous request to trigger a function function corresponding to the target asynchronous request in the to-be-called function function to process the target asynchronous request; When the function function corresponding to the target asynchronous request is the state management function, the state characterization variables corresponding to each state of the target asynchronous request are determined, and the current state of the target asynchronous request is reflected according to the current value of the state characterization variable.
2. The asynchronous request processing method according to claim 1, characterized in that: The triggering of the function function corresponding to the target asynchronous request in the to-be-called function function to process the target asynchronous request includes: When the function function corresponding to the target asynchronous request is a request retry function, determining the request retry count and retry interval of the target asynchronous request according to the error state of the target asynchronous request; Resend the target asynchronous request according to the request retry count and the retry interval.
3. The asynchronous request processing method according to claim 2, characterized in that: The step of determining the number of request retries and the retry interval of the target asynchronous request according to the error state of the target asynchronous request includes: When the error state of the target asynchronous request is a permanent error, canceling the retry of the target asynchronous request; When the error state of the target asynchronous request is a temporary error, increasing the number of request retries of the target asynchronous request and / or reducing the retry interval; When reducing the retry interval, the retry interval is controlled to increase exponentially with the increase of the number of request retries, and the growth rate of the exponential growth is inversely proportional to the severity level of the temporary error.
4. The asynchronous request processing method according to claim 1, characterized in that: The triggering of the function function corresponding to the target asynchronous request in the to-be-called function function to process the target asynchronous request includes: When the function function corresponding to the target asynchronous request is a configuration option function, obtaining a configuration function configured by a user for the target asynchronous request; When the configuration function is a refresh dependent function, if a preset array element changes, a new target asynchronous request is triggered; When the configuration function function is a ready function, detecting an output value of the ready function, triggering a new target asynchronous request when the output value is a first output value, and stopping triggering subsequent operations when the output value is a second output value; When the configuration function is a cache key function, the data identifier corresponding to the target asynchronous request is set, and the request data obtained by the target asynchronous request is cached, and the request data is returned to the inside of the component when the component is initialized.
5. The asynchronous request processing method according to claim 4, characterized in that: The step of setting the data identifier corresponding to the target asynchronous request includes: Determining core attributes of the request data; According to the core attribute of the request data, extracting a data segment in the request data for expressing the core attribute; The data identifier is generated according to the data segment of the core attribute.
6. The asynchronous request processing method according to claim 5, characterized in that: The step of generating the data identifier according to the data segment of the core attribute includes: Setting a first weight corresponding to the data segment of the core attribute; According to the importance level of the core attribute, the request data is scored, and a second weight corresponding to the data score is set, wherein the data score is proportional to the importance level; Observe in real time the real-time value of the preset evaluation parameter of the request data, and dynamically adjust the second weight according to the real-time value, wherein the real-time value is proportional to the value of the second weight; Determine a first weighted value of the data segment of the core attribute and the first weight, and a second weighted value of the data score and the second weight, and calculate a weighted sum of the first weighted value and the second weighted value; A hash operation is performed on the weighted sum to obtain a data identifier corresponding to the target asynchronous request.
7. The asynchronous request processing method according to claim 6, characterized in that: After dynamically adjusting the second weight according to the real-time value and before determining the data segment of the core attribute and the first weighted value of the first weight, the method further includes: Acquire environmental factors of the environment in which the requested data is located; Observe the degree of influence of the environmental factors on the weighted factors of the data identification; If the environmental factor has a positive impact on the weighted factor identified by the data, the weight corresponding to the weighted factor is adjusted positively, otherwise the weight corresponding to the weighted factor is adjusted negatively.
8. An asynchronous request processing device, characterized in that: include: An acquisition module, used to acquire the function functions to be called required for processing asynchronous requests, wherein the function functions to be called include conventional function functions, complex scenario function functions, and state management functions with a unified interface; An encapsulation module, used for encapsulating all the functions to be called; A sending module, used for sending a target asynchronous request, triggering a function function corresponding to the asynchronous request in the to-be-called function function, so as to process the target asynchronous request; A determination module is used to determine the state characterization variables corresponding to each state of the target asynchronous request when the function function corresponding to the target asynchronous request is the state management function, and reflect the current state of the target asynchronous request according to the current value of the state characterization variable.
9. An asynchronous request processing device, characterized in that: comprising a memory and a processor, wherein: The memory is used to store computer programs; The processor is used to read the computer program in the memory and execute the steps of any asynchronous request processing method according to claims 1-7.
10. A computer-readable storage medium, characterized in that: A readable computer program is stored thereon, and when the program is executed by a processor, the steps of any asynchronous request processing method as described in claims 1-7 are implemented.
Citation Information
Patent Citations
Asynchronous request processing method and equipment
CN103309728A
Method and device for cross-component state communication
CN113709171A
Asynchronous request processing method and device and electronic equipment
CN118869818A