Detailed Description
In order to make the objects, technical solutions and advantages of the present invention more apparent, embodiments of the present invention will be described in detail with reference to the accompanying drawings.
Referring to fig. 1A, a schematic diagram of an application scenario provided in an embodiment of the invention is shown. The application scenario may include: aterminal 10 and aserver 20.
Theterminal 10 has a function of interacting with theserver 20. Theterminal 10 may be a mobile phone, a tablet computer, an e-book reader, a multimedia player, a PDA (Personal Digital Assistant), a wearable device, or the like.
Theserver 20 serves to provide services to theterminal 10. Theserver 20 may be a server, a server cluster composed of a plurality of servers, or a cloud computing service center.
Theterminal 10 may establish a communication connection with theserver 20 through a network. The network may be a wireless network or a wired network.
In one example, when theServer 20 is a cluster architecture, as shown in FIG. 1B, theServer 20 may include a Proxy Server (Proxy Server)21 and a traffic Server 22.
Theproxy server 21 is a relay station between theterminal 10 and the service server 22, and has a function of caching data, a function of interacting with theterminal 10, and a function of interacting with the service server 22. Optionally, theproxy server 21 is a Nginx (engine x) server, and the Nginx server is a lightweight Web server/reverse proxy server and an email proxy server, and has the characteristics of small occupied memory, strong concurrency capability, and the like.
The service server 22 has a function of providing services and interacting with theproxy server 21. Optionally, the service server 22 may be an Apache server, which is an open source web server of an Apache software foundation, and may be operated in most computer operating systems, and has the characteristics of multiple platforms, better security performance, and the like.
Theproxy server 21 may establish a communication connection with the service server 22 via a network. The network may be a wireless network or a wired network.
According to the method provided by the embodiment of the invention, when the server provides the service needing to be dynamically loaded to the terminal, the server can determine the environment identifier corresponding to the specified service according to the access address, and acquire the file required by the service processing logic for executing the specified service according to the environment identifier, so that the server can execute the same service processing logic in different operating environments, developers do not need to develop the service processing logic which is adaptive to different operating environments aiming at the same specified service, the development cost and difficulty are reduced, and the development period is shortened.
Referring to fig. 2, a flowchart of a method for task processing according to an embodiment of the present invention is shown. The method may be applied in a server of an application scenario shown in fig. 1A. The method may comprise the steps of:
step 201, receiving a task processing request sent by a terminal.
The task processing request is used for requesting a specified service in a certain task. The designated service refers to a service that needs to be dynamically loaded by the Server, for example, the designated service is a service that needs to be provided to the terminal by executing a dynamic Server page (ASP) script by the Server, which is not limited in the embodiment of the present invention.
The task processing request carries an access address of the specified service and an identifier of the terminal. The access address of the specified service is used for indicating the destination address of the terminal for requesting the specified service from the server. The access address of the specified service may be a domain name of the specified service, and the domain name is used for identifying the location information of the computer during data transmission, and a mapping relation exists between the location information and the IP address. The identity of the terminal may be an Internet Protocol (IP) address of the terminal. Optionally, the task processing request further carries request path information. The request path information is used for indicating the position of the service execution result of the specified service returned by the terminal storage server.
In the embodiment of the invention, the terminal sends the task processing request to the server after receiving the access instruction corresponding to the access address of the specified service.
Step 202, obtaining an environment identifier corresponding to the specified service according to the access address.
The environment identifier corresponding to the specified service is the identifier of the running environment of the general processing logic executing the specified service. The running environment identifier is used for uniquely identifying the running environment, and the running environment can be any one of a development environment, a test environment and an online environment. The environment identifier of the development environment can be represented by level, the environment identifier of the test environment can be represented by testing, and the environment identifier of the online environment can be represented by production.
In the embodiment of the application, the access addresses and the operating environments have a one-to-one correspondence relationship, and different access addresses correspond to different operating environments. Referring to table-1 in conjunction, there is shown a correspondence between access addresses and execution environments.
TABLE-1
| Access address | Operating environment |
| Access address 1 | Development environment |
| Access address 2 | Test environment |
| Access address 3 | On-line environment |
After receiving the task processing request sent by the terminal, the server searches the corresponding relation according to the access address, and accordingly determines the environment identifier corresponding to the designated service.
And step 203, acquiring a basic file of the specified service according to the environment identifier.
The basic file of the specified service is a file required by the server to execute the general processing logic of the specified service in the running environment corresponding to the environment identifier. The base file may be a configuration file or a service file. The configuration file is used for configuring the operating environment of the server for providing the specified service to the terminal. The service file refers to a file obtained by the server executing a specified service method, for example, if the specified service method is a query database service, the service file is a data file queried by the server from the database.
Before executing the general processing logic of the specified service, the server usually obtains the basic file of the specified service, so that the server can smoothly execute the general processing logic of the specified service. For example, if the general processing logic of a specific service needs to be executed in a specific runtime environment, the server needs to obtain a configuration file to deploy the specific runtime environment. For another example, when the server needs to obtain data in the database when executing the general processing logic of the specified service, the server needs to obtain the general processing logic for calling the specified service method to obtain the service file so that the server can smoothly execute the specified service, where the specified service method is a query database service.
In one example, step 203 may include several substeps as follows:
step 203a, searching an environment directory corresponding to the environment identifier under the specified directory;
step 203b, the basic file is obtained from the environment directory.
The designated directory may be actually determined according to the basic file of the designated service, for example, when the basic file of the designated service is the configuration file, the designated directory is the configuration directory, and when the basic file of the designated service is the service file, the designated directory is the service directory. In the embodiment of the present invention, the designated directory includes an environment directory corresponding to each operating environment, and a basic file corresponding to the operating environment is stored in the environment directory of each operating environment, so that the server executes a general processing logic of the same designated service in different operating environments.
And step 204, executing the general processing logic of the specified service based on the basic file to obtain a service execution result of the specified service.
The common processing logic of the designated service refers to a common part of the service processing logic of the designated service adapted to each execution environment, which is usually developed by a developer and configured into a server. In the embodiment of the invention, the server can complete the execution of the specified service in the operating environment corresponding to the basic file according to the basic file and the general processing logic of the specified service, and because the general processing logic of the specified service can be adapted to each operating environment without repeated development, developers do not need to develop the service processing logic adapted to different operating environments aiming at the same specified service, thereby reducing the development cost and difficulty and shortening the development period.
Step 205, sending the task processing result to the terminal, wherein the task processing result carries the service execution result.
Accordingly, the terminal receives the task processing result sent by the server.
In summary, in the method provided in the embodiment of the present invention, when the server provides the service that needs to be dynamically loaded to the terminal, the server may obtain the file required to complete the execution of the specified service in the operating environment corresponding to the environment identifier according to the environment identifier determined by the access address, and complete the execution of the specified service based on the file and the general processing logic of the specified service.
In addition, when the service processing added logic of a certain service needs to run in a newly added running environment, only the basic file corresponding to the newly added running environment needs to be added under the specified directory, and the expansibility is strong; in addition, when the service processing logic of the service needs to be modified and maintained, only one service processing logic needs to be modified and maintained, so that convenience is brought; in addition, when other services are developed, the task processing method provided by the embodiment of the invention can also be adopted, so that the reusability is strong.
Referring to fig. 3A, a flowchart of a task processing method according to another embodiment of the invention is shown. The method may be applied in a server of an application scenario shown in fig. 1A. The method may comprise the steps of:
step 301, receiving a task processing request sent by a terminal.
The task processing request carries an access address of a specified service, and the specified service refers to a service which needs to be dynamically loaded.
Instep 302, the server detects whether the task processing request is for requesting pseudo static resources.
Pseudo static resources are resources that are exposed in the form of static pages in HyperText Markup Language (HTML) format, but are actually processed using dynamic scripts such as ASP. For example, a pseudo-static resource may be a related service that requires real-time display of information; as another example, pseudo-static resources are related services that require dynamic scripting to solve a problem.
If the task processing request is used for requesting pseudo static resources, the service requested by the task processing request is a service needing dynamic loading; and if the task processing request is not used for requesting the pseudo static resource, the task processing request indicates that the service requested by the task processing request is not the service which needs to be dynamically loaded.
In one example, step 302 may include several substeps as follows:
step 302a, determining a file format of a service file requested by a task processing request based on a Regular Expression (RE);
the regular expression is a logic formula for operating on character strings, namely, specific characters defined in advance and a combination of the specific characters are used for forming a 'regular character string', and the 'regular character string' is used for expressing a filtering logic for the character strings. The service file requested by the task processing request is also the service execution result of the specified service requested by the task processing request. The file Format of the service file may be an HTML Format, a Graphics Interchange Format (GIF), and the like, which is not limited in the embodiment of the present invention.
In the embodiment of the invention, the server adopts the regular expression to analyze the domain name corresponding to the task processing request, and further determines the file format of the service file requested by the task processing request. For example, for the domain name https:// bbs. aliyun. com/read/253789.HTML, the server analyzes the domain name https by adopting a regular expression, and the file format of the service file requested by the task processing request is obtained as an HTML format.
Step 302b, if the file format of the service file requested by the task processing request is not the specified format, determining that the task processing request is used for requesting pseudo static resources.
The designated format refers to a format of a corresponding service file when the terminal requests a static resource. In the embodiment of the invention, a server stores a specified format list, after the file format of the service file requested by the task processing request is determined, the server searches whether the file format of the service file requested by the task processing request is included in the specified format list, and if the file format of the service file requested by the task processing request is not included, the file format of the service file requested by the task processing request is not the specified format; and if so, the file format of the service file requested by the task processing request is a specified format.
And if the file format of the service file requested by the task processing request is the specified format, determining that the task processing request is not used for requesting pseudo static resources.
Step 303, if the task processing request is for requesting pseudo static resources, the server determines an environment identifier corresponding to the specified service according to the access address.
The environment identifier corresponding to the specified service is the identifier of the running environment of the service processing logic executing the specified service. And if the task processing request is not used for requesting the pseudo static resource, namely when the task processing request is used for requesting the static resource, the server directly returns the static resource requested by the task processing request to the terminal.
And step 304, searching an environment directory corresponding to the environment identifier under the specified directory.
Optionally, when the basic file that the server needs to obtain is a configuration file,step 304 is implemented specifically as: and searching a first environment directory corresponding to the environment identifier in the configuration directory. The configuration directory refers to a configuration directory of a specific service requested by a task processing request, which can be created by a server when the server is on-line with general processing logic of the specific service. The configuration directory includes configuration files corresponding to the respective operating environments, so that the server can search the environment directory corresponding to the environment identifier from the configuration directory, thereby obtaining the configuration files.
Optionally, when the basic file that the server needs to obtain is a service file,step 304 is implemented specifically as: and searching a second environment directory corresponding to the environment identifier under the service directory. The service directory refers to a service directory of a specified service requested by the task processing request, and can be created by the server when the service processing logic of the specified service is online. The service directory comprises service methods corresponding to the operating environments, so that the server can search the environment directory corresponding to the environment identifier from the service directory and call the related service methods to acquire the service files.
Step 305, obtaining the base file from the environment directory.
When the base files required to be acquired by the server are different, the manner of acquiring the base files from the environment directory is different.
With reference to step 304, when the basic file that the server needs to obtain is a configuration file,step 305 is specifically implemented as: and searching the configuration file in the first environment directory, and reading the configuration file. In the embodiment of the invention, the server directly searches the environment directory corresponding to the environment identifier from the configuration directory of the specified service, and then directly reads the configuration file from the environment directory corresponding to the environment identifier. In addition, when the server does not read the configuration file from the environment directory corresponding to the environment identifier, the server can also read the default configuration file from other directories of the specified service, so that the server can smoothly execute the general processing logic of the specified service.
When the basic file that the server needs to obtain is a service file,step 305 is specifically implemented as: searching a service method corresponding to the service file in the second environment directory; and acquiring a service file based on the service method. The service method is obtained by encapsulating the general processing logic of a certain function, and because the same function can be realized in different operation environments, the general processing logic of the function can be extracted and encapsulated into a corresponding service method and placed under an environment directory of a specified service, and the service method can be directly executed when a subsequent server needs to realize the function without considering the operation environment for realizing the function.
In the embodiment of the invention, the server directly searches the service directory corresponding to the environment identifier from the configuration directory of the specified service, directly reads the service method from the environment directory corresponding to the environment identifier, and then executes the service method to obtain the service file. In addition, when the server does not acquire the service file from the environment directory corresponding to the environment identifier, the server can also acquire the service method from other directories of the specified service and execute the service method to acquire the service file, so that the server can smoothly execute the general processing logic of the specified service.
Referring to fig. 3B in combination, a schematic diagram of a server obtaining an infrastructure file according to an embodiment of the present invention is shown. And a control layer in the server calls a first interface provided by the configuration service class to acquire the configuration file from each environment directory under the configuration directory, and a service layer in the server calls a second interface provided by the configuration service class to search a service method from each environment directory under the service directory to acquire the service file.
Optionally, before searching for the environment directory corresponding to the environment identifier under the specified directory, the server sets the environment directory corresponding to the environment identifier as a priority reading directory, where the priority of the priority reading directory is higher than the priority of other directories under the specified directory. By the method, the server can be prevented from directly acquiring the default configuration file of the specified service requested by the task processing request and the service file acquired by calling the default service method.
And step 306, executing the general processing logic corresponding to the specified service based on the basic file to obtain a service execution result of the specified service.
Step 307, sending a task processing result to the terminal, where the task processing result carries a service execution result.
Accordingly, the terminal receives the task processing result sent by the server.
In summary, in the method provided in the embodiment of the present invention, when the server provides the service that needs to be dynamically loaded to the terminal, the server may obtain the file required to complete the execution of the specified service in the operating environment corresponding to the environment identifier according to the environment identifier determined by the access address, and complete the execution of the specified service based on the file and the general processing logic of the specified service.
In addition, the priority of the environment directory corresponding to the environment identifier is set to be higher than the priority of other directories under the specified directory, so that the server can be prevented from directly acquiring the default configuration file of the specified service requested by the task processing request and the service file acquired by calling the default service method.
Referring to fig. 4A, a flowchart of a task processing method according to another embodiment of the invention is shown. The method may be applied in the application scenario shown in fig. 1B. The method may comprise the steps of:
step 401, the terminal sends a task processing request to the proxy server.
The task processing request carries an access address of a specified service, and the specified service refers to a service which needs to be dynamically loaded.
Accordingly, the proxy server receives the task processing request sent by the terminal.
In step 402, the proxy server detects whether the task processing request is for requesting pseudo static resources.
Step 403, if the task processing request is for requesting pseudo static resources, the proxy server obtains the environment identifier corresponding to the specified service according to the access address.
The environment identifier corresponding to the specified service is the identifier of the running environment of the service processing logic executing the specified service.
Step 404, the proxy server sends a task processing request and an environment identifier corresponding to the specified service to the service server.
Optionally, the proxy server sends the task processing request and the environment identifier corresponding to the specified service to a specified entry file in the service server. The specified entry file is an entry file for the specified service requested by the task processing request. The server starts with the entry file when providing the specified service to the terminal.
Correspondingly, the service server receives the task processing request sent by the proxy server and the environment identifier corresponding to the designated service.
Step 405, the service server searches the environment directory corresponding to the environment identifier under the specified directory.
In step 406, the service server obtains the basic file from the environment directory.
Step 407, the service server executes the general processing logic of the specified service based on the basic file, and obtains the service execution result of the specified service.
And step 408, the service server sends the task processing result to the terminal, and the task processing result carries the service execution result.
Correspondingly, the terminal receives the task processing result sent by the service server.
In addition, the service server can also send the task processing result to the proxy server, and the proxy server sends the task processing result to the terminal.
Referring to fig. 4B, the file loader is initialized first by the specified entry file in the service server, and then reads the environment identifier corresponding to the specified service, and loads the configuration file corresponding to the environment identifier into the configuration service method. In addition, the specified entry file also determines a controller for executing the specified service according to the request path information in the task processing request, and then the controller acquires a configuration file corresponding to the environment identifier in the configuration service method. In addition, when the service processing logic executing the specified service needs a service file, the controller reads the service method from the environment directory corresponding to the environment identifier, the service method returns the service file to the controller after execution, then the controller executes the general processing logic of the specified service based on the configuration file and/or the service file to obtain a service execution result of the specified service, and returns a task processing result carrying the service execution result to the terminal. In addition, the method for determining the control information corresponding to the specified service by the specified entry file is as follows: the server stores the corresponding relation between the designated characters in the request path information and the controller, the designated entry file searches for the corresponding relation, the controller corresponding to the designated service requested by the task processing request is further determined, and then the designated entry file distributes the task processing request sent by the terminal to the determined controller, so that the controller executes the subsequent steps.
The following are embodiments of the apparatus of the present invention that may be used to perform embodiments of the method of the present invention. For details which are not disclosed in the embodiments of the apparatus of the present invention, reference is made to the embodiments of the method of the present invention.
Referring to fig. 5, a block diagram of a task processing device according to an embodiment of the present invention is shown. The apparatus has functions of implementing the above method examples, and the functions may be implemented by hardware or by hardware executing corresponding software. The apparatus may include: arequest receiving module 501, anidentification determining module 502, afile obtaining module 503, aresult obtaining module 504 and aresult sending module 505.
Arequest receiving module 501, configured to receive a task processing request sent by a terminal, where the task processing request carries an access address of a specified service, and the specified service is a service that needs to be dynamically loaded.
Anidentifier determining module 502, configured to obtain, according to the access address, an environment identifier corresponding to the specified service, where the environment identifier corresponding to the specified service is an identifier of an operating environment of a general processing logic that executes the specified service.
Afile obtaining module 503, configured to obtain the basic file of the specified service according to the environment identifier.
Aresult obtaining module 504, configured to execute, based on the basic file, a general processing logic corresponding to the specified service, so as to obtain a service execution result of the specified service.
Aresult sending module 505, configured to send a task processing result to the terminal, where the task processing result carries the service execution result.
In an optional embodiment provided based on the embodiment shown in fig. 5, thefile obtaining module 503 is configured to:
searching an environment directory corresponding to the environment identifier under a specified directory;
and acquiring the basic file from the environment directory.
Optionally, thefile obtaining module 503 is further configured to set the environment directory corresponding to the environment identifier as a priority reading directory, where a priority of the priority reading directory is higher than priorities of other directories under the specified directory.
Optionally, the basic file is a configuration file of an operating environment corresponding to the environment identifier, and thefile obtaining module 503 is configured to:
searching a first environment directory corresponding to the environment identifier under a configuration directory;
and searching the configuration file in the first environment directory, and reading the configuration file.
Optionally, the basic file is a service file required by the service processing logic for executing the specified service, and thefile obtaining module 503 is configured to:
searching a second environment directory corresponding to the environment identifier in a service directory;
searching a service method corresponding to the service file in the second environment directory;
and acquiring the service file based on the service method.
In another alternative embodiment provided based on the embodiment shown in fig. 5, the apparatus further comprises: a resource detection module (not shown).
And the resource detection module is used for detecting whether the task processing request is used for requesting pseudo static resources.
Theidentifier determining module 502 is further configured to, if the task processing request is for requesting the pseudo static resource, perform a step of determining an environment identifier corresponding to the specified service according to the access address.
Optionally, the resource detecting module is configured to:
determining the file format of the service file requested by the task processing request based on a regular expression;
and if the file format of the service file requested by the task processing request is not the specified format, determining that the task processing request is used for requesting the pseudo static resource.
In summary, in the apparatus provided in the embodiment of the present invention, when the server provides the service that needs to be dynamically loaded to the terminal, the server may obtain the file required to complete the execution of the specified service in the operating environment corresponding to the environment identifier according to the environment identifier determined by the access address, and complete the execution of the specified service based on the file and the general processing logic of the specified service.
Referring to fig. 6, a schematic structural diagram of a server according to an embodiment of the present invention is shown. The server may be a server, and the server is configured to implement the service processing method. Specifically, the method comprises the following steps:
theserver 600 includes a Central Processing Unit (CPU)601, asystem memory 604 including a Random Access Memory (RAM)602 and a Read Only Memory (ROM)603, and asystem bus 605 connecting thesystem memory 604 and thecentral processing unit 601. Theserver 600 also includes a basic input/output system (I/O system) 608, which facilitates the transfer of information between devices within the computer, and amass storage device 607, which stores anoperating system 613,application programs 614, and other program modules 615.
The basic input/output system 608 comprises adisplay 606 for displaying information and aninput device 609 such as a mouse, keyboard, etc. for a user to input information. Wherein thedisplay 606 and theinput device 609 are connected to thecentral processing unit 601 through an input output controller 610 connected to thesystem bus 605. The basic input/output system 608 may also include an input/output controller 610 for receiving and processing input from a number of other devices, such as a keyboard, mouse, or electronic stylus. Similarly, input/output controller 610 may also provide output to a display screen, a printer, or other type of output device.
Themass storage device 607 is connected to thecentral processing unit 601 through a mass storage controller (not shown) connected to thesystem bus 605. Themass storage device 607 and its associated computer-readable media provide non-volatile storage for theserver 600. That is, themass storage device 607 may include a computer-readable medium (not shown) such as a hard disk or CD-ROM drive.
Without loss of generality, the computer-readable media may comprise computer storage media and communication media. Computer storage media includes volatile and nonvolatile, removable and non-removable media implemented in any method or technology for storage of information such as computer readable instructions, data structures, program modules or other data. Computer storage media includes RAM, ROM, EPROM, EEPROM, flash memory or other solid state memory technology, CD-ROM, DVD, or other optical storage, magnetic cassettes, magnetic tape, magnetic disk storage or other magnetic storage devices. Of course, those skilled in the art will appreciate that the computer storage media is not limited to the foregoing. Thesystem memory 604 andmass storage device 607 described above may be collectively referred to as memory.
Theserver 600 may also operate as a remote computer connected to a network via a network, such as the internet, in accordance with various embodiments of the present invention. That is, theserver 600 may be connected to thenetwork 612 through thenetwork interface unit 611 connected to thesystem bus 605, or may be connected to other types of networks or remote computer systems (not shown) using thenetwork interface unit 611.
The memory also includes one or more programs stored in the memory and configured to be executed by one or more processors. The one or more programs include instructions for executing the task processing method.
In an exemplary embodiment, a computer readable storage medium is further provided, in which at least one instruction, at least one program, a set of codes, or a set of instructions is stored, which is loaded and executed by a processor of an electronic device to implement the task processing method in the above-described method embodiment.
Alternatively, the computer-readable storage medium may be a ROM, a Random Access Memory (RAM), a CD-ROM, a magnetic tape, a floppy disk, an optical data storage device, and the like.
It should be understood that reference to "a plurality" herein means two or more. "and/or" describes the association relationship of the associated objects, meaning that there may be three relationships, e.g., a and/or B, which may mean: a exists alone, A and B exist simultaneously, and B exists alone. The character "/" generally indicates that the former and latter associated objects are in an "or" relationship. As used herein, the terms "first," "second," and the like, do not denote any order, quantity, or importance, but rather are used to distinguish one element from another.
The above-mentioned serial numbers of the embodiments of the present invention are merely for description and do not represent the merits of the embodiments.
The present invention is not limited to the above exemplary embodiments, and any modifications, equivalent replacements, improvements, etc. within the spirit and principle of the present invention should be included in the protection scope of the present invention.