Disclosure of Invention
The invention aims to provide a method, a device, equipment and a storage medium for executing the same timing task by multiple libraries.
In order to solve the problems, the technical scheme of the invention is as follows:
a method for multiple libraries to perform the same timed task, comprising:
creating a front-end page for configuring a timing task, wherein the front-end page at least comprises a task name, a task description, a code entry for task execution, a task execution time, a task execution period and a brand library for executing the task; the brand library is a data item which can be selected by multiple items;
the server receives the configuration data of the front-end page timing task, carries out validity verification on the configuration data, and stores the configuration data in a database after the verification is passed;
searching a database by adopting a task scheduler, acquiring timing task data configured by a front-end page, and splicing the command front of the acquired timing task data into pim (cron) to obtain a task scheduling command;
and the task scheduler circularly executes the timing task data, executes a task scheduling command when the task execution time is reached, and calls codes required to be executed by the timing task to realize that the multi-brand library executes the same timing task.
According to an embodiment of the present invention, the code that needs to be executed to call the timing task further includes:
the method comprises the steps of obtaining timing task data in a task scheduling command, retrieving a database to obtain a brand library needing to execute the timing task, retrieving the brand library, and executing the timing task.
According to an embodiment of the present invention, the retrieving the brand library required to execute the timing task from the database further includes:
and if the timing task is not configured with the brand library, the timing task is executed by all the brand libraries by default.
According to an embodiment of the present invention, the creating a front-end page for configuring the timing task further includes:
acquiring a development requirement of a front-end page, wherein the development requirement comprises a task name, a task description, a code entry for task execution, a task execution time, a task execution period and a brand library for executing tasks, and the brand library is a data item capable of being selected in multiple items;
confirming a required target page component and a target data mark of required data based on the development requirement of the front-end page;
inquiring a target data source and an acquisition mode corresponding to the target data mark according to a pre-configured configuration file, and acquiring target data through the target data source and the acquisition mode, wherein the configuration file stores the data source and the acquisition mode corresponding to each data mark in advance;
packaging the target data according to a format required by the target page component;
and rendering the target page component by using the packaged target data to obtain the target page component with corresponding functions.
According to an embodiment of the present invention, the verifying the validity of the configuration data further includes:
judging whether a keyword code exists in the configuration data;
judging whether a null value exists in the configuration data;
and judging the code format corresponding to the configuration data.
According to an embodiment of the present invention, the retrieving the database using the task scheduler further includes:
and (3) retrieving the database by calling a cron _ config method under the Crontabservice by adopting a task scheduler of the laravel.
An apparatus for multiple libraries to perform the same timed task, comprising:
the system comprises a configuration page creating module, a timing task executing module and a timing task executing module, wherein the configuration page creating module is used for creating a front-end page for configuring a timing task, and the front-end page at least comprises a task name, a task description, a code entry for task execution, task execution time, a task execution period and a brand library for task execution; the brand library is a data item which can be selected by multiple items;
the task data processing module is used for receiving the configuration data of the front-end page timing task by the server, verifying the validity of the configuration data, and storing the configuration data in the database after the verification is passed;
the task scheduling module is used for retrieving a database by adopting a task scheduler, acquiring timing task data configured through a front-end page, and splicing the front sides of the commands of the acquired timing task data into a pim (cron) to obtain a task scheduling command;
and the task execution module circularly executes the timing task data by adopting the task scheduler, executes the task scheduling command when the task execution time is reached, and calls codes required to be executed by the timing task to realize that the multi-brand library executes the same timing task.
The device for executing the same timing task by multiple libraries comprises a memory and a processor, wherein computer readable instructions are stored in the memory, and when the processor executes the computer readable instructions, the method for executing the same timing task by multiple libraries in one embodiment of the invention is realized.
A computer readable medium storing a computer program which, when executed by one or more processors, implements a method of multiple libraries performing the same timed task in an embodiment of the invention.
Due to the adoption of the technical scheme, compared with the prior art, the invention has the following advantages and positive effects:
the method for executing the same timing task by multiple libraries in the embodiment of the invention aims at the problem that the configuration and maintenance of the timing task are complex because developers need to compile Cron items for task scheduling in the traditional timing task, and the configuration of the timing task is paged by creating the front-end page for configuring the timing task, so that a user can complete the configuration of the timing task by himself without compiling codes by the developers, and the difficulty in maintaining the timing task is reduced.
Detailed Description
The method, apparatus, device and storage medium for executing a same timing task by multiple libraries according to the present invention are described in further detail with reference to the accompanying drawings and the embodiments. Advantages and features of the present invention will become apparent from the following description and from the claims.
Example one
The embodiment provides a method for executing the same timing task by multiple libraries aiming at the problems that the conventional timing task needs developers to write Cron entries for task scheduling and the configuration and maintenance of the timing task are complex.
Referring to fig. 1, the method for executing the same timing task by multiple libraries includes:
s1: creating a front-end page for configuring a timing task, wherein the front-end page at least comprises a task name, a task description, a code entry for task execution, a task execution time, a task execution period and a brand library for executing the task; the brand library is a data item which can be selected by multiple items;
s2: the server receives the configuration data of the front-end page timing task, carries out validity verification on the configuration data, and stores the configuration data in a database after the verification is passed;
s3: searching a database by adopting a task scheduler, acquiring timing task data configured by a front-end page, and splicing the command front of the acquired timing task data into pim (cron) to obtain a task scheduling command;
s4: and the task scheduler circularly executes the timing task data, executes a task scheduling command when the task execution time is reached, and calls codes required to be executed by the timing task to realize that the multi-brand library executes the same timing task.
In step S1, creating a front end page for configuring the timing task further includes:
s11: acquiring a development requirement of a front-end page, wherein the development requirement comprises a task name, a task description, a code entry for task execution, a task execution time, a task execution period and a brand library for executing tasks, and the brand library is a data item capable of being selected in multiple items;
s12: confirming a required target page component and a target data mark of required data based on the development requirement of a front-end page;
s13: inquiring a target data source and an acquisition mode corresponding to the target data mark according to a pre-configured configuration file, acquiring target data through the target data source and the acquisition mode, and pre-storing the data source and the acquisition mode corresponding to each data mark by the configuration file;
s14: packaging the target data according to a format required by the target page component;
s15: and rendering the target page component by using the packaged target data to obtain the target page component with the corresponding function.
In step S11, the development requirement of the front page is acquired. Specifically, the developer can input corresponding front-end development requirements according to the requirements, wherein the front-end development requirements comprise required components, data, events and other information. Referring to fig. 2, for the configuration of the timed task, the page at least includes a task name, a task description, a code entry for task execution, a task execution time, a task execution period (task type), a brand library for executing the task, and whether to send an email. Wherein the brand library is a multi-item selectable data item (also referred to as a page component). The brand library is specifically a product library of each merchant under a product information management system (PIM).
In step S12, the required target page components and the target data flags of the required data are confirmed based on the front-end development requirements.
Specifically, the front-end page development framework includes a plurality of page components, where a page component corresponds to a certain visualization object on a page, such as a button, an input box, a drop-down box, a multi-selection box, a radio box, and the like, and the page component is configured to present data obtained from a back end on the page, where the presentation mode may be to directly present content of the data, or to present a certain state of the visualization object determined according to the data. In the embodiment, when a front-end page for configuring the timing task is created, an input box, a drop-down box, a radio box and a multiple selection box are adopted as page components.
The data flag is a flag of data required for realizing a corresponding function based on a front-end development requirement, for example, when a task execution time drop-down frame component needs to be developed, a target page component required in the front-end development requirement is a drop-down frame page component, and a target data flag of the required data is time. It should be noted that the correspondence between the data and the data flag is defined in advance by a developer, for example: and the data mark corresponding to the task execution time data is a time point, and the data mark corresponding to the task code data is a code name.
In step S13, the target data source and the obtaining method corresponding to the target data flag are queried according to the pre-configured configuration file, and the target data is obtained through the target data source and the obtaining method, where the configuration file pre-stores the data source and the obtaining method corresponding to each data flag.
Specifically, the configuration file is configured in advance, wherein the corresponding relation between the data mark and the data source and the acquisition mode is stored, the target data source and the acquisition mode corresponding to the target data mark can be obtained through query by the target data mark, and then the target data is acquired according to the target data source and the acquisition mode.
In step S14, the target data is packaged in the format required by the target page component. Specifically, after the target data is obtained, the target data is further required to be packaged according to a format required by the target page, for example, the target data required by selecting the drop-down box component in the task execution period is required to be packaged in a list form, and if the drop-down box cannot display all the data, a drop-down bar is further required to be set in the drop-down box.
In step S15, the packaged target data is used to render the target page component, and a target page component with corresponding functions is obtained. Specifically, the target data and the target page component are automatically converted into format data capable of being rendered by the act, so that page rendering is realized by the act, and the target page component with the corresponding function is finally obtained.
In the embodiment, by presetting the configuration file, when a developer performs front-end development, only the target data mark needs to be transmitted, then the configuration file is used for inquiring the target data source and the acquisition mode corresponding to the target data mark, the corresponding target data is acquired through the target data source and the acquisition mode, and the developer does not need to write the logic of requesting the target data in the code of each page component, so that the code developed by the front-end page is simplified, the code logic is clearer, the efficiency of the front-end page development is improved, and in the subsequent maintenance process, if the code logic of acquiring the target data changes, only the code logic of the data source and/or the acquisition mode needs to be modified, the codes in the page components do not need to be modified one by one, and the maintenance difficulty is reduced.
In step S2, the server receives the configuration data of the front-end page timing task, verifies the validity of the configuration data, and stores the configuration data in the database after the verification is passed.
Referring to fig. 3, after the user creates a timing task on the front-end page, configuration data such as an execution code, an execution time, and a brand library specified by the timing task are newly added to the database through the server. The server receives the configuration data of the front-end page timing task at first and carries out validity verification on the configuration data. The validity verification includes: judging whether a keyword code exists in the configuration data; judging whether a null value exists in the configuration data; and judging the code format corresponding to the configuration data. And storing the configuration data passing the verification in a database.
In step S3, the task scheduler is used to search the database, obtain the timing task data configured by the front-end page, and concatenate the command front of the obtained timing task data with pim:: cron, to obtain the task scheduling command.
Referring to fig. 4, in the present embodiment, a task scheduler of laravel is adopted, and a cron _ config method under the CrontabService is called to retrieve a database, so as to obtain all timing task data configured by a front-end page.
Then, the result of the database retrieval is processed, please refer to fig. 5, and the sum:: cron is spliced in front of the command of the acquired timed task data to obtain a task scheduling command, such as sum:: cron class @ method.
In step S4, the task scheduler executes the timed task data circularly, and when the task execution time is reached, executes the task scheduling command, and calls the code that needs to be executed by the timed task, so as to implement the multi-brand library to execute the same timed task.
Referring to fig. 6, the task scheduler circularly executes the timed task data, and transmits the execution data of each timed task to the Schedule class, which is executed once every minute, and when the time for executing the timed task reaches, a php artisannim command is executed, and a code required to be executed by the timed task is called.
Specifically, the code to be executed for invoking the timing task includes: the method comprises the steps of obtaining timing task data in a task scheduling command, retrieving a database to obtain a brand library needing to execute the timing task, retrieving the brand library, and executing the timing task. Referring to fig. 6, first, a parameter, i.e., pim, transmitted by task scheduling is obtained, i.e., a parameter class @ method after cron, where class is a class and method is a method in the class, then a database is searched to find a brand library that needs to execute the timing task, if no brand library is set, all brand libraries are defaulted to be executed, and finally, the brand libraries are circulated to execute the timing task respectively, so that the purpose of executing the same timing task by different brand libraries is finally achieved.
Example two
Referring to fig. 7, the apparatus for executing a same timing task by multiple libraries includes:
the system comprises a configurationpage creating module 1, a timing task executing module and a timing task executing module, wherein the configuration page creating module is used for creating a front-end page for configuring a timing task, and the front-end page at least comprises a task name, a task description, a code entry for task execution, a task execution time, a task execution period and a brand library for task execution; the brand library is a data item which can be selected by multiple items;
the task data processing module 2 is used for receiving the configuration data of the front-end page timing task by the server, verifying the validity of the configuration data, and storing the configuration data in a database after the verification is passed;
the task scheduling module 3 is used for retrieving a database by adopting a task scheduler, acquiring timing task data configured through a front-end page, and splicing the front sides of the commands of the acquired timing task data into a pim (cron) to obtain a task scheduling command;
and the task execution module 4 circularly executes the timing task data by adopting a task scheduler, executes a task scheduling command when the task execution time is reached, and calls codes required to be executed by the timing task to realize that the multi-brand library executes the same timing task.
The functions and implementation methods of the configurationpage creation module 1, the task data processing module 2, the task scheduling module 3, and the task execution module 4 are all as described in the above embodiment one, and are not described herein again.
EXAMPLE III
In the second embodiment, the apparatus for executing the same timing task by multiple libraries of the present invention is described from the perspective of the modular functional entity, and the following describes in detail the apparatus for executing the same timing task by multiple libraries of the present invention from the perspective of hardware processing.
Referring to fig. 8, theapparatuses 500 for executing the same timing task by multiple libraries may have relatively large differences due to different configurations or performances, and may include one or more processors (CPUs) 510 (e.g., one or more processors) and amemory 520, one or more storage media 530 (e.g., one or more mass storage devices) for storingapplications 533 ordata 532.Memory 520 andstorage media 530 may be, among other things, transient or persistent storage. The program stored on thestorage medium 530 may include one or more modules (not shown), each of which may include a series of instruction operations in thedevice 500 that perform the same timed task on multiple libraries.
Further, theprocessor 510 may be configured to communicate with thestorage medium 530 to execute a series of instruction operations in thestorage medium 530 on thedevice 500 that performs the same timed task across multiple libraries.
Thedevice 500 for multiple libraries performing the same timed task may also include one ormore power supplies 540, one or more wired or wireless network interfaces 550, one or more input-output interfaces 560, and/or one ormore operating systems 531, such as Windows Server, Vista, and the like.
Those skilled in the art will appreciate that the configuration of devices shown in fig. 8 for multiple libraries to perform the same timed task does not constitute a limitation of devices for multiple libraries to perform the same timed task and may include more or fewer components than those shown, or some components in combination, or a different arrangement of components.
The present invention also provides a computer-readable storage medium, which may be a non-volatile computer-readable storage medium, and which may also be a volatile computer-readable storage medium. The computer readable storage medium has stored therein instructions which, when run on a computer, cause the computer to perform the steps of the method of the first embodiment in which multiple libraries perform the same timed task.
The modules in the second embodiment, if implemented in the form of software functional modules and sold or used as independent products, may be stored in a computer-readable storage medium. Based on such understanding, the technical solution of the present invention may be substantially or partially implemented in software, which is stored in a storage medium and includes instructions for causing a computer device (which may be a personal computer, a server, or a network device) to execute all or part of the steps of the method according to the embodiments of the present invention. And the aforementioned storage medium includes: a U-disk, a removable hard disk, a Read-only memory (ROM), a Random Access Memory (RAM), a magnetic disk or an optical disk, and other various media capable of storing program codes.
It can be clearly understood by those skilled in the art that, for convenience and brevity of description, the specific working processes of the above-described apparatuses and devices may refer to the corresponding processes in the foregoing method embodiments, and are not described herein again.
The embodiments of the present invention have been described in detail with reference to the accompanying drawings, but the present invention is not limited to the above embodiments. Even if various changes are made to the present invention, it is still within the scope of the present invention if they fall within the scope of the claims of the present invention and their equivalents.