Disclosure of Invention
The present application provides a method and an apparatus for processing a service, so as to effectively solve the above existing technical problems.
In order to achieve the above object, embodiments of the present application are implemented as follows:
in a first aspect, an embodiment of the present application provides a method for processing a service, where the method includes:
obtaining relevant parameters of a service request;
storing the relevant parameters and associating the service request into a service execution queue;
when the service execution queue executes the service request, executing the service request according to the stored related parameters, and obtaining an execution result of the service request;
and when the execution failure of the service request is determined according to the execution result, recording a service log generated according to the relevant parameters and the execution result.
In some optional implementations of the first aspect, storing the relevant parameters and associating the service request into a service execution queue includes:
and storing the relevant parameters stored in the first temporary variable into a storage area corresponding to the service request in Redis, and establishing a Redis service key name associated with the service request in the service execution queue.
In some optional implementation manners of the first aspect, executing the service request according to storing the relevant parameter, and obtaining an execution result of the service request includes:
according to the Redis service key name in the service execution queue, obtaining the related parameters which are stored in the storage area and are related to the Redis service key name, and establishing a second temporary variable to store the related parameters;
and executing the service request according to the related parameters in the second temporary variable, and obtaining the execution result of the service request.
In some optional implementations of the first aspect, the relevant parameters include a request parameter and a port call result;
the obtaining of the relevant parameters of the service request includes:
establishing a first temporary variable to store a request parameter for obtaining a service request;
and calling a relevant port required for executing the service request according to the request parameter, obtaining a port calling result, and storing the port calling result in the first temporary variable.
In some optional implementation manners of the first aspect, when the service execution queue executes the service request, after the service request is executed according to the stored relevant parameters and an execution result of the service request is obtained, the method further includes:
and deleting the relevant parameters and the execution result when the execution success of the service request is determined according to the execution result.
In a second aspect, an embodiment of the present application provides an apparatus for processing a service, where the apparatus includes:
the obtaining module is used for obtaining relevant parameters of the service request;
the processing module is used for storing the related parameters and associating the service request into a service execution queue;
the execution module is used for executing the service request according to the stored related parameters and obtaining the execution result of the service request when the service execution queue executes the service request;
and the recording module is used for recording a service log generated according to the relevant parameters and the execution result when the execution failure of the service request is determined according to the execution result.
In some optional implementations of the second aspect, the processing module is further configured to store the relevant parameter stored in the first temporary variable to a storage area corresponding to the service request in Redis, and establish a Redis service key name associated with the service request in the service execution queue.
In some optional implementations of the second aspect, the execution module is further configured to obtain, according to the Redis service key name in the service execution queue, the relevant parameter stored in the storage area and associated with the Redis service key name, and establish a second temporary variable to store the relevant parameter; and executing the service request according to the related parameters in the second temporary variable, and obtaining the execution result of the service request.
In some optional implementations of the second aspect, the relevant parameters include a request parameter and a port call result;
the obtaining module is further configured to establish a first temporary variable to store a request parameter of a service obtaining request; and calling a relevant port required for executing the service request according to the request parameter, obtaining a port calling result, and storing the port calling result in the first temporary variable.
In some optional implementations of the second aspect, the apparatus further comprises:
and the deleting module is used for deleting the relevant parameters and the execution result when the execution success of the service request is determined according to the execution result.
In a third aspect, an embodiment of the present application provides an electronic device, where the electronic device includes: a processor, a memory, a bus and a communication interface; the processor, the communication interface and the memory are connected by the bus.
The memory is used for storing programs.
The processor is configured to execute the first aspect and the method for processing the service according to any one of the embodiments of the first aspect by calling a program stored in the memory.
In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium having a non-volatile program code executable by a computer, where the program code causes the computer to execute the first aspect and the method for processing a service according to any embodiment of the first aspect.
The beneficial effects of the embodiment of the application are that:
by storing the relevant parameters of the service request, when the service execution queue asynchronously executes to the service request, the service request can be executed according to the stored relevant parameters, and when the execution of the service request is determined to fail according to the execution result, even if the execution of the service request is asynchronously executed to split the execution of the service request, a service log capable of expressing the complete execution process of the service request can be generated according to the stored relevant parameters and the execution result. The operation and maintenance personnel can know what the whole execution process of the service request is according to the service log, so that the operation and maintenance personnel can conveniently search and locate the problem that the execution of the service request is wrong.
In order to make the aforementioned objects, features and advantages of the present application more comprehensible, preferred embodiments accompanied with figures are described in detail below.
Detailed Description
The technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the drawings in the embodiments of the present application, and it is obvious that the described embodiments are only a part of the embodiments of the present application, and not all of the embodiments. The components of the embodiments of the present application, generally described and illustrated in the figures herein, can be arranged and designed in a wide variety of different configurations. Thus, the following detailed description of the embodiments of the present application, presented in the accompanying drawings, is not intended to limit the scope of the claimed application, but is merely representative of selected embodiments of the application. All other embodiments, which can be derived by a person skilled in the art from the embodiments of the present application without inventive step, are within the scope of the present application.
It should be noted that: like reference numbers and letters refer to like items in the following figures, and thus, once an item is defined in one figure, it need not be further defined and explained in subsequent figures. The terms "first," "second," and the like are used solely to distinguish one from another and are not to be construed as indicating or implying relative importance.
First embodiment
Referring to fig. 1, an electronic device 10 is provided in the embodiment of the present application, and the electronic device 10 may be a terminal device or a server. The terminal device may be a Personal Computer (PC), a tablet PC, a smart phone, a Personal Digital Assistant (PDA), or the like; the server may be a web server, a database server, a cloud server, or a server assembly composed of a plurality of sub servers, etc.
In this embodiment, the electronic device 10 may include: memory 11, communication module 12, bus 13, and processor 14. Wherein the processor 14, the communication module 12 and the memory 11 are connected by a bus 13. The processor 14 is arranged to execute executable modules, such as computer programs, stored in the memory 11. The components and configurations of electronic device 10 shown in FIG. 1 are for example, and not for limitation, and electronic device 10 may have other components and configurations as desired.
The Memory 11 may include a high-speed Random Access Memory (Random Access Memory RAM) and may also include a non-volatile Memory (non-volatile Memory), such as at least one disk Memory. In the present embodiment, the memory 11 stores a program required to execute a processing method of a service.
The bus 13 may be an ISA bus, a PCI bus, an EISA bus, or the like. The bus may be divided into an address bus, a data bus, a control bus, etc. For ease of illustration, only one double-headed arrow is shown in FIG. 1, but this does not indicate only one bus or one type of bus.
The processor 14 may be an integrated circuit chip having signal processing capabilities. In implementation, the steps of the above method may be performed by instructions in the form of hardware, integrated logic circuits, or software in the processor 14. The Processor 14 may be a general-purpose Processor, and includes a Central Processing Unit (CPU), a Network Processor (NP), and the like; but may also be a Digital Signal Processor (DSP), an Application Specific Integrated Circuit (ASIC), an off-the-shelf programmable gate array (FPGA) or other programmable logic device, discrete gate or transistor logic, discrete hardware components. The various methods, steps and logic blocks disclosed in the embodiments of the present invention may be implemented or performed. A general purpose processor may be a microprocessor or the processor may be any conventional processor or the like. The steps of the method disclosed in connection with the embodiments of the present invention may be directly implemented by a hardware decoding processor, or implemented by a combination of hardware and software modules in the decoding processor. The software module may be located in ram, flash memory, rom, prom, or eprom, registers, etc. storage media as is well known in the art.
The method performed by the flow process or the defined device disclosed in any of the embodiments of the present invention may be applied to the processor 14, or may be implemented by the processor 14. After the processor 14 receives the execution instruction and calls the program stored in the memory 11 through the bus 13, the processor 14 controls the communication module 12 through the bus 13 so as to execute the flow of the processing method of the service.
Second embodiment
Referring to fig. 2, the present embodiment provides a service processing method, where the service processing method is applied to an electronic device, and the service processing method includes: step S100, step S200, step S300, and step S400.
Step S100: and obtaining relevant parameters of the service request.
Step S200: storing the relevant parameters, and associating the service request into a service execution queue.
Step S300: and when the service execution queue executes the service request, executing the service request according to the stored related parameters, and obtaining an execution result of the service request.
Step S400: and when the execution failure of the service request is determined according to the execution result, recording a service log generated according to the relevant parameters and the execution result.
The process flow of the present application will be described in detail below.
Step S100: and obtaining relevant parameters of the service request.
The service request may be a request initiated by a user, or the service request may also be a request that needs to be generated by the electronic device or an application program on the electronic device in the running process according to a preset program. For example, when the service request is a request initiated by a user, the service request may be, for example, a payment request, a video acquisition request, or the like; for another example, when the service request is a request generated according to a preset program, the service request may be, for example, a data update request, an image compression request, or the like.
Of course, the electronic device obtains the request parameter in the service request based on generating the service request, whether the request is initiated by the user or generated according to the operation of the preset program.
Optionally, the request parameters obtained by the electronic device may include: a path of the service request, a type of the service request, parameters of the service request, a request body of the service request, a header of the service request, and a source of the service request.
Since the electronic device executes the service request as being executed in the memory of the electronic device, the electronic device may establish a first temporary variable in the memory, so as to store the obtained request parameter in the temporary variable in the form of an array. Thus, the electronic device can call the relevant port required for executing the service request according to the request parameter in the first temporary variable, and obtain the port calling result. The called relevant port may be a third-party port on the electronic device, for example, a video APP on the electronic device initiates a payment request, and then the electronic device needs to call the relevant port of the payment APP on the electronic device to implement a final payment function when executing the payment request.
Of course, to ensure the integrity of the data, the electronic device also stores the obtained port call result in the form of an array into the first temporary variable. Thus, the first temporary variable stores the request parameter and the port call result, which can be regarded as the relevant parameters of the service request, i.e. the electronic device obtains the relevant parameters of the service request including the request parameter and the port call result.
After the electronic device obtains the relevant parameters, the electronic device may continue to perform step S200.
Step S200: storing the relevant parameters, and associating the service request into a service execution queue.
The first temporary variable is located in a memory of the electronic device, and the first temporary variable occupies resources of the memory. In order to optimize the resource utilization rate of the memory, after the electronic device stores the obtained port call result in the first temporary variable, the electronic device may store the relevant parameter in the first temporary variable in a storage area corresponding to the service request in the Redis of the electronic device, and delete the first temporary variable in the memory. Therefore, the relevant parameters of the service request are guaranteed not to be lost by being stored in the storage area, the first temporary variable in the memory is deleted, and the resource utilization rate of the memory is optimized. A
In this embodiment, since the service request is executed asynchronously, the service request needs to be executed in the service execution queue subsequently. Then, while the storage area in the Redis stores the relevant parameters of the service request, the service request may also be associated into the service execution queue, so that the service request can be continuously executed through the service execution queue in the following.
As a way of associating the service request with the service execution queue, a Redis service key name for associating the service request may be established in the service execution queue, and when the Redis service key name enables the electronic device to execute the service in the service execution queue to the Redis service key name, the electronic device may search a storage area of the Redis for a relevant parameter of the service request according to the Redis service key name.
It is understood that after associating the service request in the service execution queue, the electronic device may continue to perform step S300.
Step S300: and when the service execution queue executes the service request, executing the service request according to the stored related parameters, and obtaining an execution result of the service request.
As the electronic device sequentially executes the services sequentially ordered in the service execution queue, the electronic device may execute the service request in the service execution queue at the Redis service key name in the service execution queue. Thus, the electronic device can obtain the Redis service key name.
By analyzing the Redis service key name, the electronic device can know that the Redis service key name indicates that the electronic device needs to obtain the relevant parameters of the service request. Then, the electronic device can find the storage area associated with the Redis service key name from the Redis according to the Redis service key name, so as to obtain the stored relevant parameters of the service request from the storage area.
Also, since the electronic device executes the service request as being executed in the memory of the electronic device, the electronic device may also re-establish a second temporary variable in the memory, so as to restore the obtained relevant parameter to the second temporary variable. In this way, the electronic device can execute the service request according to the execution of the relevant parameter in the second temporary variable, and then the electronic device can obtain an execution result indicating that the execution of the service request is successful or failed. For example, a video APP on the electronic device initiates a payment request, and the electronic device, through execution of relevant parameters of the payment request, may initiate payment through the payment APP on the electronic device and obtain a payment result indicating success or failure of payment.
In this embodiment, after the electronic device obtains the execution result, the electronic device may continue to execute step S400.
Step S400: and when the execution failure of the service request is determined according to the execution result, recording a service log generated according to the relevant parameters and the execution result.
The electronic device may determine whether execution of the service request succeeded or failed based on a return value in the execution result.
If the return value in the obtained execution result is the first preset value, the electronic device may determine, according to the first preset value, that the execution of the service request is successful. Based on the result, the electronic device may delete the second temporary variable to optimize the memory in order to guarantee the performance of the electronic device. Meanwhile, the electronic device can delete both the obtained execution result and the relevant parameters of the service request stored in the Redis, so as to prevent the redundant data from affecting the performance of the device.
If the return value in the obtained execution result is the second preset value, the electronic device may determine that the execution of the service request is an execution failure according to the second preset value. Based on the result, in order to ensure that the operation and maintenance personnel can accurately locate the reason of the execution failure, the electronic device may generate a service log of the service request based on the obtained execution result and the relevant parameters of the service request stored in the Redis. Because the execution result and the related parameters can completely show the complete execution process of the service request, the operation and maintenance personnel can quickly and accurately locate the reason of the execution failure of the service request from the complete execution process based on the service log containing the execution result and the related parameters.
It is to be understood that, in order to ensure the performance of the electronic device, after the service log is generated, the electronic device may also delete the second temporary variable to optimize the memory. Meanwhile, the electronic device can delete both the obtained execution result and the relevant parameters of the service request stored in the Redis, and the influence of the redundant data on the performance of the device is avoided.
Third embodiment
Referring to fig. 3, an embodiment of the present application provides a service processing apparatus 100, which is applied to an electronic device, and the service processing apparatus 100 includes:
an obtaining module 110, configured to obtain a parameter related to the service request.
The processing module 120 is configured to store the relevant parameters and associate the service request into a service execution queue.
The execution module 130 is configured to execute the service request according to the stored relevant parameters when the service execution queue executes the service request, and obtain an execution result of the service request.
A recording module 140, configured to record a service log generated according to the relevant parameter and the execution result when it is determined that the service request is failed to be executed according to the execution result.
A deleting module 150, configured to delete the request parameter and the execution result when it is determined that the service request is successfully executed according to the execution result.
Optionally, the obtaining module 110 is further configured to establish a first temporary variable to store a request parameter of the obtain service request; and calling a relevant port required for executing the service request according to the request parameter, obtaining a port calling result, and storing the port calling result in the first temporary variable.
In detail, the service request may be a request initiated by a user, or the service request may also be a request that needs to be generated by the electronic device or an application program on the electronic device in the running process according to a preset program. For example, when the service request is a request initiated by a user, the service request may be, for example, a payment request, a video acquisition request, or the like; for another example, when the service request is a request generated according to a preset program, the service request may be, for example, a data update request, an image compression request, or the like.
Of course, the obtaining module 110 obtains the request parameter in the service request based on generating the service request, whether the request is initiated by the user or generated according to the operation of the preset program.
Optionally, the request parameters obtained by the obtaining module 110 may include: a path of the service request, a type of the service request, parameters of the service request, a request body of the service request, a header of the service request, and a source of the service request.
Since the obtaining module 110 executes the service request as being executed in the memory of the electronic device, the obtaining module 110 may establish a first temporary variable in the memory, so as to store the obtained request parameter in the temporary variable in the form of an array. The obtaining module 110 may then call the relevant port required for executing the service request according to the request parameter in the first temporary variable, and obtain the port call result. The called relevant port may be a third-party port on the electronic device, for example, a video APP on the electronic device initiates a payment request, and the obtaining module 110 needs to call the relevant port of the payment APP on the electronic device to implement a final payment function when executing the payment request.
Of course, to ensure data integrity, the obtaining module 110 also stores the obtained port call results in an array to the first temporary variable. Thus, the first temporary variable stores the request parameter and the port call result, which can be regarded as the relevant parameters of the service request, i.e. the obtaining module 110 obtains the relevant parameters of the service request including the request parameter and the port call result.
Optionally, the processing module 120 is further configured to store the request parameter stored in the first temporary variable into a storage area corresponding to the service request in the Redis, and establish a Redis service key name associated with the service request in the service execution queue.
In detail, the first temporary variable is located in a memory of the electronic device, and the first temporary variable occupies resources of the memory. In order to optimize the resource utilization rate of the memory, after the obtaining module 110 stores the obtained port call result in the first temporary variable, the processing module 120 may store the relevant parameter in the first temporary variable in a storage area corresponding to a service request in the Redis of the electronic device, and delete the first temporary variable in the memory. Therefore, the relevant parameters of the service request are guaranteed not to be lost by being stored in the storage area, the first temporary variable in the memory is deleted, and the resource utilization rate of the memory is optimized. A
In this embodiment, since the service request is executed asynchronously, the service request needs to be executed in the service execution queue subsequently. Then, while the processing module 120 stores the relevant parameters of the service request in the storage area in the Redis, the processing module 120 may also associate the service request into the service execution queue, so that the service request can be continuously executed through the service execution queue in the following.
As a way of associating the service request with the service execution queue, the processing module 120 may establish a Redis service key name associated with the service request in the service execution queue, where the Redis service key name enables the processing module 120 to execute the service in the service execution queue to the Redis service key name, and the processing module 120 may search a storage area of the Redis for a relevant parameter of the service request according to the Redis service key name. Optionally, the execution module 130 is further configured to obtain the relevant parameter stored in the storage area and associated with the Redis service key name according to the Redis service key name in the service execution queue, and establish a second temporary variable to store the relevant parameter; and executing the service request according to the related parameters in the second temporary variable, and obtaining the execution result of the service request.
As the execution module 130 sequentially executes the services sequentially ordered in the service execution queue, the execution module 130 may execute the service request in the service execution queue at the Redis service key name in the service execution queue. Thus, the execution module 130 can obtain the Redis service key name.
By parsing the key name of the Redis service, the execution module 130 may learn that the key name of the Redis service indicates that the execution module 130 needs to obtain the relevant parameter of the service request. Then, the execution module 130 may find a storage area associated with the Redis service key name from the Redis according to the Redis service key name, so as to obtain the stored relevant parameters of the service request from the storage area.
Also, since execution module 130 executes the service request as being executed in the memory of the electronic device, execution module 130 may also re-establish a second temporary variable in the memory, so as to restore the obtained relevant parameter to the second temporary variable. In this way, the execution module 130 can execute the service request according to the execution of the relevant parameter in the second temporary variable, and the execution module 130 can obtain an execution result indicating that the execution of the service request is successful or failed. For example, a video APP on the electronic device initiates a payment request, and the electronic device, through execution of relevant parameters of the payment request, may initiate payment through the payment APP on the electronic device and obtain a payment result indicating success or failure of payment.
In detail, the recording module 140 and the deleting module 150 may determine whether the execution of the service request is successful or failed according to a return value in the execution result.
If the return value in the execution result is the first preset value, the recording module 140 may determine that the execution of the service request is successful according to the first preset value. Based on the result, the recording module 140 may delete the second temporary variable to optimize the memory in order to guarantee the performance of the electronic device. Meanwhile, the recording module 140 may also delete both the obtained execution result and the relevant parameters of the service request stored in the Redis, so as to prevent the redundant data from affecting the performance of the device.
If the return value in the execution result is the second preset value, the deleting module 150 may determine that the execution of the service request is an execution failure according to the second preset value. Based on the result, in order to ensure that the operation and maintenance staff can accurately locate the reason for the execution failure, the deleting module 150 may generate a service log of the service request based on the obtained execution result and the relevant parameters of the service request stored in the Redis. Because the execution result and the related parameters can completely show the complete execution process of the service request, the operation and maintenance personnel can quickly and accurately locate the reason of the execution failure of the service request from the complete execution process based on the service log containing the execution result and the related parameters.
It is to be understood that, also to ensure the performance of the electronic device, the deletion module 150 may delete the second temporary variable after generating the service log to optimize the memory. Meanwhile, the deleting module 150 may also delete both the obtained execution result and the parameter related to the service request stored in the Redis, and also avoid that these redundant data affect the performance of the device. As will be appreciated by one skilled in the art, embodiments of the present application may be provided as a method, system, or computer program product. Accordingly, embodiments of the present application may take the form of an entirely hardware embodiment, an entirely software embodiment or an embodiment combining software and hardware aspects. Furthermore, embodiments of the present application may take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, and the like) having computer-usable program code embodied therein.
To sum up, the embodiment of the present application provides a method and an apparatus for processing a service. The method comprises the following steps: obtaining relevant parameters of a service request; storing the relevant parameters and associating the service request into a service execution queue; when the service execution queue executes the service request, executing the service request according to the storage related parameters and obtaining an execution result of the service request; and when the execution failure of the service request is determined according to the execution result, recording a service log generated according to the relevant parameters and the execution result.
By storing the relevant parameters of the service request, when the service execution queue asynchronously executes to the service request, the service request can be executed according to the stored relevant parameters, and when the execution of the service request is determined to fail according to the execution result, even if the execution of the service request is asynchronously executed to split the execution of the service request, a service log capable of expressing the complete execution process of the service request can be generated according to the stored relevant parameters and the execution result. The operation and maintenance personnel can know what the whole execution process of the service request is according to the service log, so that the operation and maintenance personnel can conveniently search and locate the problem that the execution of the service request is wrong.
The above description is only a preferred embodiment of the present application and is not intended to limit the present application, and various modifications and changes may be made by those skilled in the art. Any modification, equivalent replacement, improvement and the like made within the spirit and principle of the present application shall be included in the protection scope of the present application. It should be noted that: like reference numbers and letters refer to like items in the following figures, and thus, once an item is defined in one figure, it need not be further defined and explained in subsequent figures.
The above description is only for the specific embodiments of the present application, but the scope of the present application is not limited thereto, and any person skilled in the art can easily conceive of the changes or substitutions within the technical scope of the present application, and shall be covered by the scope of the present application. Therefore, the protection scope of the present application shall be subject to the protection scope of the claims.