CN110837409A - Method and system for executing task regularly - Google Patents

Method and system for executing task regularly Download PDF

Info

Publication number
CN110837409A
CN110837409A CN201810936158.8A CN201810936158A CN110837409A CN 110837409 A CN110837409 A CN 110837409A CN 201810936158 A CN201810936158 A CN 201810936158A CN 110837409 A CN110837409 A CN 110837409A
Authority
CN
China
Prior art keywords
timing task
task
timing
executed
execution
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN201810936158.8A
Other languages
Chinese (zh)
Inventor
冯军
王彪
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Beijing Jingdong Century Trading Co Ltd
Beijing Jingdong Shangke Information Technology Co Ltd
Original Assignee
Beijing Jingdong Century Trading Co Ltd
Beijing Jingdong Shangke Information Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Beijing Jingdong Century Trading Co Ltd, Beijing Jingdong Shangke Information Technology Co Ltd filed Critical Beijing Jingdong Century Trading Co Ltd
Priority to CN201810936158.8A priority Critical patent/CN110837409A/en
Publication of CN110837409A publication Critical patent/CN110837409A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/466Transaction processing
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/54Interprogram communication
    • G06F9/546Message passing systems or structures, e.g. queues

Abstract

The invention discloses a method and a system for executing tasks at fixed time, and relates to the technical field of computers. One embodiment of the method comprises: in the timing task waiting set, determining a timing task to be executed currently, wherein the task execution time of the timing task to be executed currently is before the current time or the current time; inquiring the execution parameters of the timing task to be executed currently in a timing task information table, wherein the execution parameters of each timing task in the timing task waiting set are maintained in the timing task information table; and sending the execution parameters of the timing task to be executed to a service end so that the service end can execute the timing task to be executed by using the execution parameters. The implementation mode has the advantages of high performance, high efficiency and capability of reducing the pressure of the business database.

Description

Method and system for executing task regularly
Technical Field
The invention relates to the technical field of computers, in particular to a method and a system for executing tasks at fixed time.
Background
In the electric business, there are some common business requirements for performing tasks at regular time, such as: if the order is not paid for a period of time, the order needs to be automatically cancelled; the order of the user is required to be delivered in the open air, and the order production system needs to place the order to the warehouse management system for production in the open air; the order production system needs to download the catering orders to the catering system according to the receiving time of the user.
In the process of implementing the invention, the inventor finds that at least the following problems exist in the prior art: the existing method for executing tasks at fixed time is mainly realized by scanning a table through a database, and an order which needs to be executed at fixed time is found by scanning a service table through an order database every minute. If the scanning interval is set to be longer, time error of the execution of the timing task is caused, if the scanning interval is shortened, great pressure is caused on a database, and the performance and the efficiency of the existing timing execution task are lower.
Therefore, a need exists for a method and system for performing tasks at a high performance, high efficiency, and timed rate that reduces traffic database pressure.
Disclosure of Invention
In view of this, embodiments of the present invention provide a method and a system for executing tasks at regular time, which have the advantages of high performance, high efficiency, and capability of reducing the pressure on a service database.
To achieve the above object, according to an aspect of an embodiment of the present invention, there is provided a method for executing tasks periodically, including:
in the timing task waiting set, determining a timing task to be executed currently, wherein the task execution time of the timing task to be executed currently is before the current time or the current time;
inquiring the execution parameters of the timing task to be executed currently in a timing task information table, wherein the execution parameters of each timing task in the timing task waiting set are maintained in the timing task information table;
and sending the execution parameters of the timing task to be executed to a service end so that the service end can execute the timing task to be executed by using the execution parameters.
The method for executing the task at the fixed time provided by the embodiment of the invention also comprises the following steps:
receiving information of a timing task sent by a service end, wherein the information of the timing task comprises an execution parameter of the task and an execution time of the task;
and maintaining the information of the timing task in the timing task information table, and adding the timing task into the timing task waiting set and associating the timing task with the execution time of the timing task waiting set.
The method for executing the task at the fixed time provided by the embodiment of the invention also comprises the following steps:
after receiving the information of the timing task sent by the service end, generating a unique ID of the timing task;
the adding the timing task into the timing task waiting set and associating with the execution time thereof comprises:
generating a set element of the timing task and adding the set element into the timing task waiting set, wherein the set element comprises: the timing task waiting set comprises a set key and corresponding scores, wherein the set key is determined according to the unique ID of the timing task, the corresponding score value is determined according to the execution time of the timing task, the timing task waiting set is an ordered set, and set elements are ordered according to the score values.
The method for executing the task at the fixed time provided by the embodiment of the invention also comprises the following steps:
after the timing task to be executed currently is determined in the timing task waiting set, deleting the timing task to be executed currently in the timing task waiting set;
and after the execution parameters of the timing task to be executed currently are sent to the service end, deleting the information of the timing task to be executed currently in the timing task information table.
The method for executing the task at the fixed time provided by the embodiment of the invention also comprises the following steps:
and traversing the information of the timing task in the timing task information table according to a set period, determining the timing task with the execution time being earlier than the set time, and adding the timing task into the timing task waiting set.
Further, the information of the timing task further includes: the communication mode and the communication address of the task;
the sending the execution parameters of the timing task to be executed to the service end comprises: and inquiring the communication mode and the communication address of the timing task to be executed currently in the timing task information table, and sending the execution parameters of the timing task to be executed currently to the service terminal by using the communication mode and the communication address.
In order to achieve the above object, according to another aspect of the embodiments of the present invention, there is also provided a system for executing tasks periodically, including: the timing execution cluster comprises at least one timing execution node;
the timing execution node includes:
the task determining module is used for determining a timing task to be executed currently in the timing task waiting set, wherein the task execution time of the timing task to be executed currently is before the current time or is the current time;
an information acquisition module, configured to query, in a timing task information table, execution parameters of the current timing task to be executed, where the timing task information table maintains the execution parameters of each timing task in the timing task waiting set;
and the data sending module is used for sending the execution parameters of the timing task to be executed to a service end so that the service end can execute the timing task to be executed currently by using the execution parameters.
Further, the timing execution node further includes:
the receiving module is used for receiving the information of the timing task sent by the service end, wherein the information of the timing task comprises the execution parameters of the task and the execution time of the task;
and the data persistence module is used for maintaining the information of the timing task into the timing task information table, adding the timing task into the timing task waiting set and associating the timing task with the execution time of the timing task waiting set.
Further, the data persistence module is further configured to generate a unique ID of the timing task after receiving information of the timing task sent by the service end;
the data persistence module is further configured to generate an assembly element of the timing task and add the assembly element to the timing task waiting set, where the assembly element includes: the timing task waiting set comprises a set key and corresponding scores, wherein the set key is determined according to the unique ID of the timing task, the corresponding score value is determined according to the execution time of the timing task, the timing task waiting set is an ordered set, and set elements are ordered according to the score values.
Further, the task determining module is further configured to delete the currently to-be-executed timing task in the timing task waiting set after the currently to-be-executed timing task is determined in the timing task waiting set;
the information acquisition module is further configured to delete the information of the current timing task to be executed in the timing task information table after sending the execution parameter of the current timing task to be executed to the service end.
Further, the timing execution node further includes:
and the abnormal task recovery module is used for traversing the information of the timing task in the timing task information table according to a set period, determining the timing task with the execution time being earlier than the set time, and adding the timing task into the timing task waiting set.
Further, the information of the timing task further includes: the communication mode and the communication address of the task;
the information acquisition module is further used for inquiring the communication mode and the communication address of the timing task to be executed currently in the timing task information table;
the data sending module is further used for sending the execution parameters of the timing task to be executed to the service end by using the communication mode and the communication address.
In order to achieve the above object, according to another aspect of the embodiments of the present invention, there is also provided an electronic device for executing tasks at regular time, including:
one or more processors;
a storage device for storing one or more programs,
when the one or more programs are executed by the one or more processors, the one or more processors implement the method for executing tasks at fixed time provided by the embodiment of the invention.
To achieve the above object, according to another aspect of the embodiments of the present invention, there is also provided a computer readable medium, on which a computer program is stored, which when executed by a processor, implements the method for timing execution of tasks provided by the embodiments of the present invention.
The method and the system for executing the task at the fixed time provided by the embodiment of the invention have the advantages that the process of determining the current to-be-executed fixed time task is separated from the service, the execution is independent of the service system, the pressure of the service database of the service system is reduced, in the process of determining the current to-be-executed fixed time task, the task is determined in the waiting set of the fixed time task, then the corresponding information is inquired in the information table of the fixed time task for callback, the to-be-executed task is determined without traversing the database for storing detailed information, and the efficiency and the performance of the fixed time task are improved. In addition, the method for executing the tasks at the fixed time can be applied to a distributed execution framework, and the execution nodes can be expanded transversely so as to meet the processing requirements of a large number of fixed time tasks of a service system.
Further effects of the above-mentioned non-conventional alternatives will be described below in connection with the embodiments.
Drawings
The drawings are included to provide a better understanding of the invention and are not to be construed as unduly limiting the invention. Wherein:
fig. 1 is a schematic diagram of a main flow of a method for executing tasks at fixed time according to an embodiment of the present invention;
FIG. 2 is a schematic diagram of an interaction manner of a method for executing tasks at fixed time according to an embodiment of the present invention;
FIG. 3 is a schematic diagram of an application flow of a method for executing tasks at regular time according to an embodiment of the present invention;
FIG. 4 is a schematic diagram of the main modules of a system for timed task execution according to an embodiment of the present invention;
FIG. 5 is a diagram illustrating message transmission of a system for performing tasks periodically according to an embodiment of the present invention;
fig. 6 is an application diagram of a timing execution node according to an embodiment of the present invention;
FIG. 7 is an exemplary system architecture diagram in which embodiments of the present invention may be employed;
FIG. 8 is a schematic block diagram of a computer system suitable for use with the electronic device to implement an embodiment of the invention.
Detailed Description
Exemplary embodiments of the present invention are described below with reference to the accompanying drawings, in which various details of embodiments of the invention are included to assist understanding, and which are to be considered as merely exemplary. Accordingly, those of ordinary skill in the art will recognize that various changes and modifications of the embodiments described herein can be made without departing from the scope and spirit of the invention. Also, descriptions of well-known functions and constructions are omitted in the following description for clarity and conciseness.
An embodiment of the present invention provides a method for executing a task at regular time, as shown in fig. 1, the method includes: step S101, step S102, and step S103. The steps can be deployed in a timing execution node independent of a service system to be executed, and the execution process is separated from the service.
In step S101, in the timed task waiting set, a timed task to be executed currently is determined, and the task execution time of the timed task to be executed currently is before or at the current time.
The pre-configured timing task waiting set comprises all timing tasks needing to be executed regularly, and only the timing tasks needing to be executed currently need to be determined by utilizing the timing task waiting set. Therefore, in the timed task waiting set, the timed task only needs to be associated with the execution time of the timed task, and does not need to be associated with other information, so that the timed task waiting set can adopt a high-performance data persistence mode with low complexity, such as a redis cache database.
Then, in step S102, the execution parameters of the current timing task to be executed are queried in the timing task information table, where the execution parameters of each timing task in the timing task waiting set are maintained in the timing task information table. The timed task information table is used to store detailed information of the timed task, and after the current timed task to be executed is determined in step S101, the detailed information of the timed task can be queried in the timed task information table, and the task is executed through subsequent steps. In one embodiment, the timed task information table may be implemented using a mysql database.
In step S103, the execution parameter of the timing task to be executed currently is sent to the service end, so that the service end can execute the timing task to be executed currently by using the execution parameter. In one embodiment, the timed task is executed in this step by calling back the timed task target method of the business system using the execution parameter of the timed task, and the execution parameter is the entry of the target method.
In an embodiment of the present invention, the above steps may be performed according to a set period, and since the timed task waiting collection adopts a high-performance data persistence mode with low complexity, the set period may be 1 second or less, thereby reducing a time error of the timed task execution.
The timing execution nodes for executing the steps can be distributed and deployed, have strong expansibility, and can improve the efficiency of executing the tasks at regular time by increasing the timing execution nodes along with the increase of the timing task amount of the service system.
The method for executing the task at the fixed time provided by the embodiment of the invention has the advantages that the process of determining the current to-be-executed fixed time task is separated from the service, the method is independent of the service system execution, the pressure of the service database of the service system is reduced, in the process of determining the current to-be-executed fixed time task, the task is determined in the fixed time task waiting set, then the corresponding information is inquired in the fixed time task information table for callback, the to-be-executed task is determined without traversing the database storing detailed information, and the efficiency and the performance of the fixed time task execution are improved. In addition, the method for executing the tasks at the fixed time can be applied to a distributed execution framework, and the execution nodes can be expanded transversely so as to meet the processing requirements of a large number of fixed time tasks of a service system.
In one embodiment, the method for executing tasks in a timed mode further comprises the following processes of receiving information and persisting: firstly, receiving timing task information sent by a service end, wherein the timing task information comprises: an execution parameter of the task and an execution time of the task. The execution time is the time that the business system needs to execute the task. Then, the information of the timing task is maintained in a timing task information table, the timing task is added into a timing task waiting set and is associated with the execution time of the timing task, and the current timing task to be executed, namely the task of which the execution time is before the current time or is the current time, can be determined through the execution time of each timing task.
The service end can send the information of the timing task (for example, payment order is cancelled automatically when time is out, order is downloaded on time, etc.) of the service system to the timing execution node through the configured interactive protocol and the message.
In an embodiment of the present invention, the method for executing a task at fixed time further includes a process of generating a unique ID of the task at fixed time after receiving information of the task at fixed time sent by the service end. Then, in the process of adding the timing task into the timing task waiting set and associating the timing task with the execution time of the timing task waiting set, generating a set element of the timing task and adding the set element into the timing task waiting set, wherein the set element comprises: the timing task waiting set comprises a set key and corresponding scores, wherein the set key is determined according to the unique ID of the timing task, the corresponding score value is determined according to the execution time of the timing task, the timing task waiting set is an ordered set, and set elements are ordered according to the score values. In the ordered set, the corresponding search command is executed according to the current time, elements in the interval are specified, and then the task with the task execution time before or as the current time can be obtained.
In an embodiment of the present invention, the method for executing tasks periodically provided by the present invention further includes the following processes: after the timing task to be executed currently is determined in the timing task waiting set, the timing task to be executed currently is deleted in the timing task waiting set so as to ensure that the timing task cannot be executed repeatedly. And after the execution parameters of the timing task to be executed currently are sent to the service end, deleting the information of the timing task to be executed currently in the timing task information table. After the parameters are successfully sent, the corresponding records in the timing task information table are deleted, and the records cannot be deleted if the parameters are not successfully sent, so that the safety of data is ensured, and the data cannot be lost.
In an extreme case, data in the timed task waiting set is deleted, but the timed task execution parameter is not successfully transmitted, and the data which fails to be executed needs to be restored into the timed task waiting set. Therefore, in an embodiment of the present invention, the method for executing tasks periodically provided by the present invention further includes the following data reply process: and traversing the information of the timing task in the timing task information table according to a set period, determining the timing task of which the execution time is earlier than the set time, and adding the timing task into a timing task waiting set. In one embodiment, the set time may be the current time, that is, if there is a timed task whose execution time is before the current time in the timed task information table, it indicates that the timed task has been determined and deleted in the timed task waiting set, but has not been successfully transmitted, and therefore remains in the timed task information table, so that the timed task is added to the timed task waiting set to recover data, and is to be executed again later.
In one embodiment of the invention, the information of the timing task further comprises a communication mode and a communication address of the task. This information is stored in the timed task information table. In step S103, the process of sending the execution parameter of the timing task to be executed to the service end specifically includes: and inquiring the communication mode and the communication address of the timing task to be executed currently in the timing task information table, and sending the execution parameters of the timing task to be executed currently to the service terminal by using the communication mode and the communication address. In the present invention, the communication mode of the callback service system may be, for example, interface, or message queue mq.
The method for executing tasks in a timed manner according to the present invention is further described below with reference to a specific embodiment. In this embodiment, the method is performed by a timing execution cluster composed of a plurality of timing execution nodes deployed in a distributed manner. The timing execution nodes in the timing execution cluster can be dynamically expanded.
As shown in fig. 2, the service system sends a timing task with execution time to the timing execution node, and the timing execution node periodically calls back the service system target method according to the execution time.
The service system sends out the information of the timing task (service) through the message according to the interactive protocol, and the information comprises: application name namespace, service type biz _ type, communication mode execute _ type, target interface name execute _ target (i.e., communication address), service ID: execute _ id, execution parameter execute _ context, execution time execute _ time.
And the gateway of the timing execution cluster determines to which timing execution node the service timing task is routed according to the application name namespace and the service type bizType.
In the embodiment, a mysql database is deployed at the timing execution node, a timing task information table is deployed in the mysql database, and the timing task information table includes the following fields: autonomy key ID, generated unique ID: sys _ key, business system application name namespace, business type biz _ type, communication mode execute _ type, target interface name execute _ target, and business ID: execute _ id, execution parameter execute _ context, execution time execute _ time, created time created _ datatime, modified time modified _ datatime. The mysql database can be divided into a plurality of tables according to the data quantity.
In the embodiment, for high availability, the mysql database adopted in the scheme can be configured with at least two sets of databases isolated from each other, and the system can be automatically allocated into the main database and the standby database. If the connection of the main library is abnormal, the data can be stored in the standby library.
In the embodiment, the timing execution node is deployed with a redis cache database, and the timing task waiting set is deployed in the redis cache database. In the redis cache database, the timed task waiting set uses the ordered set sortedset based on the skip list of the redis. Each element contains a key unique in the set and a score of the corresponding dobush type, the elements being ordered by the size of the value of the score, for example:
[ [ key: score ], [ key2: score2], [ key3: score3] ]. Keys cannot be repeated, but score can be repeated. key corresponds to unique ID in mysql table: sys _ key, score corresponds to execution time execute _ time in mysql table;
the redis cache database can generate a plurality of ordered sets sortedset according to the data volume, and according to the unique ID: sys _ key performs hash calculation to determine which sorted set sortedset is stored.
And the timing execution node receives the timing task transmitted by the gateway and carries out persistence. Because the database at the bottom layer adopts the sub-database and sub-table, a unique ID is generated for each service message, namely sys _ key of the storage layer. In the embodiment, the unique ID is generated by adopting an ID large concurrency generation algorithm snowfall.
The message content is then converted into an object for storage tier usage and the generated unique ID is filled in. Because the mysql of the data storage layer is partitioned, the rules of partitioning the database and the table are configured earlier in the routing layer. The number of sorted sets for Redis is also pre-configured at the routing layer. The service message is persisted before according to the unique ID: sys _ key calculates in which table and certain ordered set of redis sortedset is stored.
And then storing the service message in a database and storing the service message in redis, and if one party fails, keeping the final data consistent in an asynchronous message mode. And after the steps are completed, the task of the service system is returned to be successfully received.
And the timed execution node consumes the elements in the redis ordered set through multithreading. In this embodiment, the ordered set of redis is ordered from small to large according to the time that the task needs to be executed, so that only all timed tasks are needed to scan the data at the front of the ordering, and if the score of the data at the head of the queue is found to be greater than or equal to the current time, the data can be consumed quickly.
As shown in fig. 3, the specific steps are as follows:
step 1, the timing execution node acquires the current time and initializes the current time to variable endtime.
And step 2, executing a zrangbyscore command of redis, and returning a member list of the specified fraction interval in the ordered set, namely acquiring an element before the endtime to obtain an element list.
And 3, traversing the elements in the list, executing a zrem command of redis on each element, removing one or more members in the ordered set, wherein the members which do not exist are ignored, namely deleting the elements, and executing the step 4 if the deletion is successful, otherwise, deleting the next element. The zrem command of redis can be successfully executed only once, so the task is not repeatedly executed.
Step 4, the key of each element in the list and the unique ID of the mysql database: and mapping sys _ key, and acquiring data of the timing task through the key.
And step 5, finding a target interface which needs to be executed by the service system according to the acquired communication mode execute _ type and the target interface name execute _ target, and transmitting an execution parameter execute _ context to a target method for execution. And judging whether the service system hopes to call back in an mq or interface mode through a communication mode field acquired from the mysql database, and after the mode is determined, entering the reference is the content in the execution parameter field.
And 6, if the data transmission is successful, deleting the corresponding record of the mysql database.
An embodiment of the present invention further provides a system for executing a task at regular time, as shown in fig. 4, including: a service end 401 and a timing execution cluster 402, wherein the timing execution cluster 402 comprises at least one timing execution node 403.
The timing execution node 403 includes: a task determination module 4031, an information acquisition module 4032 and a data transmission module 4033.
The task determining module 4031 is configured to determine, in the timed task waiting set, a currently-to-be-executed timed task, where a task execution time of the currently-to-be-executed timed task is before or at a current time;
the information obtaining module 4032 is configured to query, in a timing task information table, an execution parameter of a timing task to be currently executed, where the execution parameter of each timing task in a timing task waiting set is maintained in the timing task information table;
the data sending module 4033 is configured to send an execution parameter of the timing task to be currently executed to the service end, so that the service end can execute the timing task to be currently executed by using the execution parameter.
In the present invention, the timing execution node further includes: the device comprises a receiving module and a data persistence module.
The receiving module is used for receiving the information of the timing task sent by the service end, wherein the information of the timing task comprises the execution parameters of the task and the execution time of the task.
The data persistence module is used for maintaining the information of the timing task in a timing task information table, adding the timing task into a timing task waiting set and associating the timing task with the execution time of the timing task waiting set.
In the present invention, as shown in fig. 5, a service end sends a timed task message of a service application to a timed execution trunking gateway through a preset communication mode, and the timed execution trunking gateway determines to which timed execution node the timed task message is routed according to an application name namespace and a service type bizType in the timed task message.
In the invention, the data persistence module is further used for generating the unique ID of the timing task after receiving the information of the timing task sent by the service terminal.
The data persistence module is further configured to generate an aggregate element of the timed task and join the aggregate element into a timed task waiting set, the aggregate element including: the timing task waiting set comprises an aggregation key and a corresponding score value, wherein the aggregation key is determined according to the unique ID of the timing task, the corresponding score value is determined according to the execution time of the timing task, the timing task waiting set is an ordered set, and aggregation elements are ordered according to the score value.
In the present invention, the task determining module is further configured to delete the currently to-be-executed timing task in the timing task waiting set after determining the currently to-be-executed timing task in the timing task waiting set.
The information acquisition module is further used for deleting the information of the timing task to be executed currently in the timing task information table after the execution parameter of the timing task to be executed currently is sent to the service end.
In the present invention, the timing execution node further includes: and an abnormal task recovery module. And the abnormal task recovery module is used for traversing the information of the timing task in the timing task information table according to the set period, determining the timing task of which the execution time is earlier than the set time, and adding the timing task into the timing task waiting set.
In the present invention, the information of the timing task further includes: the communication mode and the communication address of the task.
The information acquisition module is further used for inquiring the communication mode and the communication address of the timing task to be executed currently in the timing task information table.
The data sending module is further used for sending the execution parameters of the timing task to be executed to the service end by using the communication mode and the communication address.
As shown in FIG. 6, in one embodiment of the present invention, the data persistence module comprises: and the unique ID generation submodule is used for generating a unique universal unique identification code uuid for each service message. And the conversion translation submodule is used for converting the message content into an object used by the storage layer and filling the uuid in the object. And the routing module is used for calculating which table of the mysql database and which ordered set of the redis cache database the task is stored in according to the generated unique ID. And the transaction module is used for storing the service message in the mysql database and storing the service message in the redis cache database, and if one party fails, the final data consistency is kept in an asynchronous message mode. After the steps are completed, the data persistence module returns successful receiving to the client.
The mysql database adopted by the scheme can be configured with at least two mutually isolated databases, and the system can be automatically distributed into a main database and a standby database. If the connection of the main library is abnormal, the data can be stored in the standby library. Correspondingly, the redis cache database generates ordered sets-primary and ordered sets-backup. The timing task execution unit includes a task determination module, an information acquisition module, and a data transmission module, which are not described herein again. The abnormal task recovery module comprises: the system comprises a main recovery module and a standby recovery module, wherein the main recovery module performs data recovery between a database main library and an ordered set-main, and the standby recovery module performs data recovery between the database standby library and an ordered set-standby.
The method and the system for executing the task at the fixed time provided by the embodiment of the invention have the advantages that the process of determining the current to-be-executed fixed time task is separated from the service, the process is independent of the execution of the service system, the pressure of the service database of the service system is reduced, in the process of determining the current to-be-executed fixed time task, the task is determined in the fixed time task waiting set, then the corresponding information is inquired in the fixed time task information table for callback, the to-be-executed task is determined without traversing the database for storing detailed information, and the efficiency and the performance of the fixed time task are improved. In addition, the method for executing the tasks at the fixed time can be applied to a distributed execution framework, and the execution nodes can be expanded transversely so as to meet the processing requirements of a large number of fixed time tasks of a service system.
Fig. 7 shows an exemplary system architecture 700 to which the method for regularly performing tasks or the system for regularly performing tasks of the embodiments of the present invention may be applied.
As shown in fig. 7, the system architecture 700 may include terminal devices 701, 702, 703, a network 704, and a server 705. The network 704 serves to provide a medium for communication links between the terminal devices 701, 702, 703 and the server 705. Network 704 may include various connection types, such as wired, wireless communication links, or fiber optic cables, to name a few.
A user may use the terminal devices 701, 702, 703 to interact with a server 705 over a network 704, to receive or send messages or the like. Various communication client applications may be installed on the terminal devices 701, 702, 703.
The terminal devices 701, 702, 703 may be various electronic devices having a display screen and supporting web browsing, including but not limited to smart phones, tablet computers, laptop portable computers, desktop computers, and the like.
The server 705 may be a server providing various services, for example, a background management server determining a timing task to be currently executed, and sending an execution parameter of the timing task to be currently executed to a service end, so that the service end can execute the timing task to be currently executed by using the execution parameter.
It should be noted that the method for executing tasks at regular time provided by the embodiment of the present invention is generally executed by the server 705, and accordingly, the timing execution node is generally disposed in the server 705.
It should be understood that the number of terminal devices, networks, and servers in fig. 7 is merely illustrative. There may be any number of terminal devices, networks, and servers, as desired for implementation.
Referring now to FIG. 8, shown is a block diagram of a computer system 800 suitable for use with a terminal device implementing an embodiment of the present invention. The terminal device shown in fig. 8 is only an example, and should not bring any limitation to the functions and the scope of use of the embodiments of the present invention.
As shown in fig. 8, the computer system 800 includes a Central Processing Unit (CPU)801 that can perform various appropriate actions and processes in accordance with a program stored in a Read Only Memory (ROM)802 or a program loaded from a storage section 808 into a Random Access Memory (RAM) 803. In the RAM 803, various programs and data necessary for the operation of the system 800 are also stored. The CPU 801, ROM 802, and RAM 803 are connected to each other via a bus 804. An input/output (I/O) interface 805 is also connected to bus 804.
The following components are connected to the I/O interface 805: an input portion 806 including a keyboard, a mouse, and the like; an output section 807 including a signal such as a Cathode Ray Tube (CRT), a Liquid Crystal Display (LCD), and the like, and a speaker; a storage portion 808 including a hard disk and the like; and a communication section 809 including a network interface card such as a LAN card, a modem, or the like. The communication section 809 performs communication processing via a network such as the internet. A drive 810 is also connected to the I/O interface 805 as necessary. A removable medium 811 such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, or the like is mounted on the drive 810 as necessary, so that a computer program read out therefrom is mounted on the storage section 808 as necessary.
In particular, according to the embodiments of the present disclosure, the processes described above with reference to the flowcharts may be implemented as computer software programs. For example, embodiments of the present disclosure include a computer program product comprising a computer program embodied on a computer readable medium, the computer program comprising program code for performing the method illustrated in the flow chart. In such an embodiment, the computer program can be downloaded and installed from a network through the communication section 809 and/or installed from the removable medium 811. The computer program executes the above-described functions defined in the system of the present invention when executed by the Central Processing Unit (CPU) 801.
It should be noted that the computer readable medium shown in the present invention can be a computer readable signal medium or a computer readable storage medium or any combination of the two. A computer readable storage medium may be, for example, but not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination of the foregoing. More specific examples of the computer readable storage medium may include, but are not limited to: an electrical connection having one or more wires, a portable computer diskette, a hard disk, a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing. In the present invention, a computer readable storage medium may be any tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device. In the present invention, however, a computer readable signal medium may include a propagated data signal with computer readable program code embodied therein, for example, in baseband or as part of a carrier wave. Such a propagated data signal may take many forms, including, but not limited to, electro-magnetic, optical, or any suitable combination thereof. A computer readable signal medium may also be any computer readable medium that is not a computer readable storage medium and that can communicate, propagate, or transport a program for use by or in connection with an instruction execution system, apparatus, or device. Program code embodied on a computer readable medium may be transmitted using any appropriate medium, including but not limited to: wireless, wire, fiber optic cable, RF, etc., or any suitable combination of the foregoing.
The flowchart and block diagrams in the figures illustrate the architecture, functionality, and operation of possible implementations of systems, methods and computer program products according to various embodiments of the present invention. In this regard, each block in the flowchart or block diagrams may represent a module, segment, or portion of code, which comprises one or more executable instructions for implementing the specified logical function(s). It should also be noted that, in some alternative implementations, the functions noted in the block may occur out of the order noted in the figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently, or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved. It will also be noted that each block of the block diagrams or flowchart illustration, and combinations of blocks in the block diagrams or flowchart illustration, can be implemented by special purpose hardware-based systems which perform the specified functions or acts, or combinations of special purpose hardware and computer instructions.
The modules described in the embodiments of the present invention may be implemented by software or hardware. The described modules may also be provided in a processor, which may be described as: a processor includes a task determination module, an information acquisition module, and a data transmission module. Wherein the names of the modules do not in some cases constitute a limitation of the module itself.
As another aspect, the present invention also provides a computer-readable medium that may be contained in the apparatus described in the above embodiments; or may be separate and not incorporated into the device. The computer readable medium carries one or more programs which, when executed by a device, cause the device to comprise:
in the timing task waiting set, determining a timing task to be executed currently, wherein the task execution time of the timing task to be executed currently is before the current time or the current time;
inquiring the execution parameters of the timing task to be executed currently in a timing task information table, wherein the execution parameters of each timing task in the timing task waiting set are maintained in the timing task information table;
and sending the execution parameters of the timing task to be executed to a service end so that the service end can execute the timing task to be executed by using the execution parameters.
The above-described embodiments should not be construed as limiting the scope of the invention. Those skilled in the art will appreciate that various modifications, combinations, sub-combinations, and substitutions can occur, depending on design requirements and other factors. Any modification, equivalent replacement, and improvement made within the spirit and principle of the present invention should be included in the protection scope of the present invention.

Claims (14)

1. A method for timing execution of tasks, comprising:
in the timing task waiting set, determining a timing task to be executed currently, wherein the task execution time of the timing task to be executed currently is before the current time or the current time;
inquiring the execution parameters of the timing task to be executed currently in a timing task information table, wherein the execution parameters of each timing task in the timing task waiting set are maintained in the timing task information table;
and sending the execution parameters of the timing task to be executed to a service end so that the service end can execute the timing task to be executed by using the execution parameters.
2. The method of claim 1, further comprising:
receiving information of a timing task sent by a service end, wherein the information of the timing task comprises an execution parameter of the task and an execution time of the task;
and maintaining the information of the timing task in the timing task information table, and adding the timing task into the timing task waiting set and associating the timing task with the execution time of the timing task waiting set.
3. The method of claim 2, further comprising:
after receiving the information of the timing task sent by the service end, generating a unique ID of the timing task;
the adding the timing task into the timing task waiting set and associating with the execution time thereof comprises:
generating a set element of the timing task and adding the set element into the timing task waiting set, wherein the set element comprises: the timing task waiting set comprises a set key and corresponding scores, wherein the set key is determined according to the unique ID of the timing task, the corresponding score value is determined according to the execution time of the timing task, the timing task waiting set is an ordered set, and set elements are ordered according to the score values.
4. The method of claim 2, further comprising:
after the timing task to be executed currently is determined in the timing task waiting set, deleting the timing task to be executed currently in the timing task waiting set;
and after the execution parameters of the timing task to be executed currently are sent to the service end, deleting the information of the timing task to be executed currently in the timing task information table.
5. The method of claim 4, further comprising:
and traversing the information of the timing task in the timing task information table according to a set period, determining the timing task with the execution time being earlier than the set time, and adding the timing task into the timing task waiting set.
6. The method of claim 2, wherein the information of the timing task further comprises: the communication mode and the communication address of the task;
the sending the execution parameters of the timing task to be executed to the service end comprises: and inquiring the communication mode and the communication address of the timing task to be executed currently in the timing task information table, and sending the execution parameters of the timing task to be executed currently to the service terminal by using the communication mode and the communication address.
7. A system for timing tasks, comprising: the timing execution cluster comprises at least one timing execution node;
the timing execution node includes:
the task determining module is used for determining a timing task to be executed currently in the timing task waiting set, wherein the task execution time of the timing task to be executed currently is before the current time or is the current time;
an information acquisition module, configured to query, in a timing task information table, execution parameters of the current timing task to be executed, where the timing task information table maintains the execution parameters of each timing task in the timing task waiting set;
and the data sending module is used for sending the execution parameters of the timing task to be executed to a service end so that the service end can execute the timing task to be executed currently by using the execution parameters.
8. The system of claim 7, wherein the timing enforcement node further comprises:
the receiving module is used for receiving the information of the timing task sent by the service end, wherein the information of the timing task comprises the execution parameters of the task and the execution time of the task;
and the data persistence module is used for maintaining the information of the timing task into the timing task information table, adding the timing task into the timing task waiting set and associating the timing task with the execution time of the timing task waiting set.
9. The system of claim 8, wherein the data persistence module is further configured to generate a unique ID of the timing task after receiving information of the timing task sent by the service end;
the data persistence module is further configured to generate an assembly element of the timing task and add the assembly element to the timing task waiting set, where the assembly element includes: the timing task waiting set comprises a set key and corresponding scores, wherein the set key is determined according to the unique ID of the timing task, the corresponding score value is determined according to the execution time of the timing task, the timing task waiting set is an ordered set, and set elements are ordered according to the score values.
10. The system according to claim 8, wherein the task determining module is further configured to delete the currently to-be-executed timed task in the timed task waiting set after determining the currently to-be-executed timed task in the timed task waiting set;
the information acquisition module is further configured to delete the information of the current timing task to be executed in the timing task information table after sending the execution parameter of the current timing task to be executed to the service end.
11. The system of claim 10, wherein the timing enforcement node further comprises:
and the abnormal task recovery module is used for traversing the information of the timing task in the timing task information table according to a set period, determining the timing task with the execution time being earlier than the set time, and adding the timing task into the timing task waiting set.
12. The system of claim 8, wherein the information of the timing task further comprises: the communication mode and the communication address of the task;
the information acquisition module is further used for inquiring the communication mode and the communication address of the timing task to be executed currently in the timing task information table;
the data sending module is further used for sending the execution parameters of the timing task to be executed to the service end by using the communication mode and the communication address.
13. An electronic device for performing tasks at regular intervals, comprising:
one or more processors;
a storage device for storing one or more programs,
when executed by the one or more processors, cause the one or more processors to implement the method of any one of claims 1-6.
14. A computer-readable medium, on which a computer program is stored, which, when being executed by a processor, carries out the method according to any one of claims 1-6.
CN201810936158.8A 2018-08-16 2018-08-16 Method and system for executing task regularly Pending CN110837409A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201810936158.8A CN110837409A (en) 2018-08-16 2018-08-16 Method and system for executing task regularly

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201810936158.8A CN110837409A (en) 2018-08-16 2018-08-16 Method and system for executing task regularly

Publications (1)

Publication Number Publication Date
CN110837409A true CN110837409A (en) 2020-02-25

Family

ID=69573323

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201810936158.8A Pending CN110837409A (en) 2018-08-16 2018-08-16 Method and system for executing task regularly

Country Status (1)

Country Link
CN (1) CN110837409A (en)

Cited By (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111738728A (en) * 2020-05-15 2020-10-02 苏宁金融科技(南京)有限公司 Transaction compensation method and device
CN112463318A (en) * 2020-11-17 2021-03-09 深圳市优必选科技股份有限公司 Timed task processing method, device and system
CN112666849A (en) * 2020-12-31 2021-04-16 新奥数能科技有限公司 Method and device for automatically controlling equipment by using timing control strategy
CN112817710A (en) * 2021-01-22 2021-05-18 平安养老保险股份有限公司 Timed task processing method, timed task processing system, computer equipment and computer storage medium
CN113806046A (en) * 2021-09-15 2021-12-17 武汉虹信技术服务有限责任公司 Task scheduling system based on thread pool
CN114238309A (en) * 2021-10-26 2022-03-25 浙江菜鸟供应链管理有限公司 Logistics single performance detection method and delayed task processing method
CN115391052A (en) * 2022-10-26 2022-11-25 上海擎朗智能科技有限公司 Robot task processing method and device, electronic equipment and storage medium

Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN105677536A (en) * 2016-01-08 2016-06-15 上海斐讯数据通信技术有限公司 Implementing method for task messages and task system for implementing task messages
CN106815066A (en) * 2015-11-30 2017-06-09 阿里巴巴集团控股有限公司 A kind of timed task dispatching method, apparatus and system
CN107894919A (en) * 2017-11-30 2018-04-10 中国平安财产保险股份有限公司 Timed task triggering method, device, equipment and readable storage medium storing program for executing
WO2018095298A1 (en) * 2016-11-23 2018-05-31 腾讯科技(深圳)有限公司 Information processing method and device and computer storage medium
CN108132833A (en) * 2017-12-08 2018-06-08 广州视源电子科技股份有限公司 A kind of distributed timing method for scheduling task and device based on zookeeper technologies
CN108182108A (en) * 2017-12-19 2018-06-19 山东浪潮商用系统有限公司 A kind of timed task cluster and its execution method

Patent Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN106815066A (en) * 2015-11-30 2017-06-09 阿里巴巴集团控股有限公司 A kind of timed task dispatching method, apparatus and system
CN105677536A (en) * 2016-01-08 2016-06-15 上海斐讯数据通信技术有限公司 Implementing method for task messages and task system for implementing task messages
WO2018095298A1 (en) * 2016-11-23 2018-05-31 腾讯科技(深圳)有限公司 Information processing method and device and computer storage medium
CN107894919A (en) * 2017-11-30 2018-04-10 中国平安财产保险股份有限公司 Timed task triggering method, device, equipment and readable storage medium storing program for executing
CN108132833A (en) * 2017-12-08 2018-06-08 广州视源电子科技股份有限公司 A kind of distributed timing method for scheduling task and device based on zookeeper technologies
CN108182108A (en) * 2017-12-19 2018-06-19 山东浪潮商用系统有限公司 A kind of timed task cluster and its execution method

Cited By (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111738728A (en) * 2020-05-15 2020-10-02 苏宁金融科技(南京)有限公司 Transaction compensation method and device
CN112463318A (en) * 2020-11-17 2021-03-09 深圳市优必选科技股份有限公司 Timed task processing method, device and system
CN112666849A (en) * 2020-12-31 2021-04-16 新奥数能科技有限公司 Method and device for automatically controlling equipment by using timing control strategy
CN112817710A (en) * 2021-01-22 2021-05-18 平安养老保险股份有限公司 Timed task processing method, timed task processing system, computer equipment and computer storage medium
CN113806046A (en) * 2021-09-15 2021-12-17 武汉虹信技术服务有限责任公司 Task scheduling system based on thread pool
CN114238309A (en) * 2021-10-26 2022-03-25 浙江菜鸟供应链管理有限公司 Logistics single performance detection method and delayed task processing method
CN115391052A (en) * 2022-10-26 2022-11-25 上海擎朗智能科技有限公司 Robot task processing method and device, electronic equipment and storage medium

Similar Documents

Publication Publication Date Title
CN110837409A (en) Method and system for executing task regularly
CN111797091A (en) Method and device for querying data in database, electronic equipment and storage medium
CN111478781B (en) Message broadcasting method and device
CN111241189A (en) Method and device for synchronizing data
CN110321252B (en) Skill service resource scheduling method and device
CN112948498A (en) Method and device for generating global identification of distributed system
CN115629909A (en) Service data processing method and device, electronic equipment and storage medium
CN115277707A (en) Service processing method, device, electronic equipment and storage medium
CN112783914B (en) Method and device for optimizing sentences
CN113742376A (en) Data synchronization method, first server and data synchronization system
CN110019671B (en) Method and system for processing real-time message
CN112988857A (en) Service data processing method and device
CN112711572A (en) Online capacity expansion method and device suitable for sub-warehouse and sub-meter
CN112214500A (en) Data comparison method and device, electronic equipment and storage medium
CN117478535B (en) Log storage method and device
CN114979308B (en) Message processing method and device
CN112311833B (en) Data updating method and device
CN110120958B (en) Task pushing method and device based on crowdsourcing mode
CN113722548A (en) Method and device for processing reference relationship in business system
CN115695451A (en) Business service triggering method and device
CN113760967A (en) Data query method and device
CN117478535A (en) Log storage method and device
CN117499396A (en) Data processing method and device based on cloud native platform system
CN115080229A (en) Resource object management method and device
CN112541025A (en) Service data interaction method and device

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination