A method and system for executing tasks at a scheduled time

By determining the task in the scheduled task waiting set and querying the execution parameters in the information table, it is executed independently of the business system, solving the problems of scheduled task execution error and low performance in the existing technology, and realizing efficient and low-pressure scheduled task processing. , suitable for distributed execution frameworks.

CN110837409BActive Publication Date: 2024-10-18BEIJING JINGDONG SHANGKE INFORMATION TECH CO LTD +1
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN201810936158.8
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2018-08-16
Publication Date
2024-10-18
Estimated Expiration
2038-08-16

AI Technical Summary

Technical Problem

The existing scheduled task execution method is mainly implemented through database table scanning, which leads to time errors in scheduled task execution, inefficient performance, and great pressure on the database.

Method used

By determining the current task to be executed in the scheduled task waiting set, and querying the execution parameters in the scheduled task information table, it is executed independently of the business system, reducing database pressure, and using low-complexity high-performance data persistence methods, such as Redis cache. Database to achieve efficient execution of scheduled tasks.

Benefits of technology

It improves the performance and efficiency of scheduled execution tasks, reduces the pressure on business databases, and supports distributed execution framework and horizontal expansion to meet the processing needs of a large number of scheduled tasks.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN110837409B_ABST
    Figure CN110837409B_ABST
Patent Text Reader

Abstract

The present invention discloses a method and system for executing tasks at a scheduled time, and relates to the field of computer technology. A specific implementation of the method includes: determining the scheduled task to be executed currently in a scheduled task waiting set, wherein the task execution time of the scheduled task to be executed currently is before the current time or is the current time; querying the execution parameters of the scheduled task to be executed currently in a scheduled task information table, wherein the scheduled task information table maintains the execution parameters of each scheduled task in the scheduled task waiting set; and sending the execution parameters of the scheduled task to be executed currently to a service end, so that the service end can execute the scheduled task to be executed currently using the execution parameters. This implementation has the advantages of high performance, high efficiency, and can reduce the pressure on the business database.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of computer technology, and in particular to a method and system for timing task execution. Background Art

[0002] In e-commerce business, there are generally some business requirements for scheduled execution of tasks. For example, if an order has not been paid for a period of time, the order needs to be automatically canceled; if the user's order is required to be delivered tomorrow, the order production system needs to upload the order to the warehouse management system for production on time tomorrow; if the user places a catering order, the order production system needs to upload it to the catering system for production on time according to the user's delivery time.

[0003] In the process of implementing the present invention, the inventors found that there are at least the following problems in the prior art: the existing method of executing tasks on a scheduled basis is mainly implemented by scanning the database table, and the orders that need to be executed on a scheduled basis are discovered by scanning the business table in the order database every minute. If the scanning interval is set to be long, it will cause time errors in the execution of scheduled tasks. If the scanning interval is shortened, it will cause great pressure on the database, and the performance and efficiency of the existing scheduled execution tasks are low.

[0004] Therefore, there is an urgent need for a method and system for performing scheduled tasks with high performance and high efficiency and capable of reducing the pressure on business databases. Summary of the invention

[0005] In view of this, an embodiment of the present invention provides a method and system for executing tasks on a scheduled basis, which has the advantages of high performance, high efficiency and the ability to reduce the pressure on a business database.

[0006] To achieve the above object, according to one aspect of an embodiment of the present invention, a method for executing a task at a scheduled time is provided, comprising:

[0007] In the scheduled task waiting set, determine the scheduled task to be executed currently, wherein the task execution time of the scheduled task to be executed currently is before the current time or is the current time;

[0008] In the scheduled task information table, query the execution parameters of the scheduled task to be executed currently, wherein the scheduled task information table maintains the execution parameters of each scheduled task in the scheduled task waiting set;

[0009] The execution parameters of the currently to-be-executed scheduled task are sent to the service end, so that the service end can execute the currently to-be-executed scheduled task using the execution parameters.

[0010] The method for executing tasks at a scheduled time provided by the embodiment of the present invention also includes:

[0011] Receive information about a scheduled task sent by a service end, wherein the information about the scheduled task includes: task execution parameters and task execution time;

[0012] The information of the scheduled task is maintained in the scheduled task information table, and the scheduled task is added to the scheduled task waiting set and associated with its execution time.

[0013] The method for executing tasks at a scheduled time provided by the embodiment of the present invention also includes:

[0014] After receiving the scheduled task information sent by the business end, generate a unique ID for the scheduled task;

[0015] The adding of the scheduled task into the scheduled task waiting set and associating it with the execution time includes:

[0016] Generate a set element of the scheduled task and add it to the scheduled task waiting set, the set element includes: a set key and a corresponding score, the set key is determined according to the unique ID of the scheduled task, and its corresponding score value is determined according to the execution time of the scheduled task, the scheduled task waiting set is an ordered set, and the set elements therein are sorted according to the score value.

[0017] The method for executing tasks at a scheduled time provided by the embodiment of the present invention also includes:

[0018] After determining the currently scheduled task to be executed in the scheduled task waiting set, deleting the currently scheduled task to be executed in the scheduled task waiting set;

[0019] After the execution parameters of the currently to-be-executed scheduled task are sent to the service end, the information of the currently to-be-executed scheduled task is deleted from the scheduled task information table.

[0020] The method for executing tasks at a scheduled time provided by the embodiment of the present invention also includes:

[0021] According to the set cycle, the information of the scheduled tasks in the scheduled task information table is traversed, the scheduled tasks whose execution time is earlier than the set time are determined, and the scheduled tasks are added to the scheduled task waiting set.

[0022] Furthermore, the information of the scheduled task also includes: the communication method and communication address of the task;

[0023] The sending of the execution parameters of the currently scheduled task to be executed to the service end includes: querying the communication mode and communication address of the currently scheduled task to be executed in the scheduled task information table, and sending the execution parameters of the currently scheduled task to be executed to the service end using the communication mode and communication address.

[0024] To achieve the above object, according to another aspect of an embodiment of the present invention, a system for executing tasks on a scheduled basis is provided, comprising: a service end and a scheduled execution cluster, wherein the scheduled execution cluster comprises at least one scheduled execution node;

[0025] The timing execution node includes:

[0026] A task determination module is used to determine a scheduled task to be executed currently in the scheduled task waiting set, wherein the task execution time of the scheduled task to be executed currently is before the current time or is the current time;

[0027] An information acquisition module, used to query the execution parameters of the scheduled task to be executed currently in the scheduled task information table, wherein the scheduled task information table maintains the execution parameters of each scheduled task in the scheduled task waiting set;

[0028] The data sending module is used to send the execution parameters of the currently scheduled task to be executed to the service end, so that the service end can execute the currently scheduled task to be executed using the execution parameters.

[0029] Furthermore, the timing execution node also includes:

[0030] The receiving module is used to receive the information of the scheduled task sent by the service end, and the information of the scheduled task includes: the execution parameters of the task and the execution time of the task;

[0031] The data persistence module is used to maintain the information of the scheduled task in the scheduled task information table, and to add the scheduled task to the scheduled task waiting set and associate it with its execution time.

[0032] Furthermore, the data persistence module is further used to generate a unique ID of the scheduled task after receiving the information of the scheduled task sent by the service end;

[0033] The data persistence module is further used to generate a set element of the scheduled task and add it to the scheduled task waiting set. The set element includes: a set key and a corresponding score. The set key is determined according to the unique ID of the scheduled task, and its corresponding score value is determined according to the execution time of the scheduled task. The scheduled task waiting set is an ordered set, and the set elements are sorted according to the score value.

[0034] Furthermore, the task determination module is further used to delete the currently to-be-executed scheduled task from the scheduled task waiting set after determining the currently to-be-executed scheduled task from the scheduled task waiting set;

[0035] The information acquisition module is further used to delete the information of the currently scheduled task to be executed in the scheduled task information table after sending the execution parameters of the currently scheduled task to be executed to the service end.

[0036] Furthermore, the timing execution node also includes:

[0037] The abnormal task recovery module is used to traverse the information of the scheduled tasks in the scheduled task information table according to the set period, determine the scheduled tasks whose execution time is earlier than the set time, and add the scheduled tasks to the scheduled task waiting set.

[0038] Furthermore, the information of the scheduled task also includes: the communication method and communication address of the task;

[0039] The information acquisition module is further used to query the communication mode and communication address of the currently to-be-executed scheduled task in the scheduled task information table;

[0040] The data sending module is further used to send the execution parameters of the current scheduled task to be executed to the service end by using the communication mode and the communication address.

[0041] To achieve the above object, according to another aspect of an embodiment of the present invention, there is also provided an electronic device for executing tasks at a scheduled time, comprising:

[0042] one or more processors;

[0043] a storage device for storing one or more programs,

[0044] When the one or more programs are executed by the one or more processors, the one or more processors implement the method for timing task execution provided by the embodiment of the present invention.

[0045] To achieve the above objective, according to another aspect of an embodiment of the present invention, a computer-readable medium is provided, on which a computer program is stored, and when the program is executed by a processor, the method for timing task execution provided by an embodiment of the present invention is implemented.

[0046] The method and system for executing tasks on a scheduled basis provided by the above-mentioned embodiment of the present invention separate the process of determining the currently scheduled task to be executed from the business, and execute it independently of the business system, thereby reducing the pressure on the business database of the business system. In addition, in the process of determining the currently scheduled task to be executed, the scheduled task waits for the task to be determined centrally, and then the corresponding information is queried in the scheduled task information table for callback, without traversing the database storing detailed information to determine the task to be executed, thereby improving the efficiency and performance of the scheduled task execution. In addition, the method for executing tasks on a scheduled basis can be applied to a distributed execution framework, and the execution nodes can be horizontally expanded to meet the processing requirements of a large number of scheduled tasks of the business system.

[0047] The further effects of the above-mentioned non-conventional optional manner will be described below in conjunction with the specific implementation manner. BRIEF DESCRIPTION OF THE DRAWINGS

[0048] The accompanying drawings are used to better understand the present invention and do not constitute an improper limitation of the present invention.

[0049] Figure 1 It is a schematic diagram of the main process of the method for executing tasks at a scheduled time provided by an embodiment of the present invention;

[0050] Figure 2 is a schematic diagram of an interactive mode of a method for executing tasks at a scheduled time provided by an embodiment of the present invention;

[0051] Figure 3 is a schematic diagram of the application process of the method for executing tasks at a scheduled time provided by an embodiment of the present invention;

[0052] Figure 4 is a schematic diagram of main modules of a system for executing tasks at a scheduled time provided by an embodiment of the present invention;

[0053] Figure 5 It is a schematic diagram of message sending of a system for executing tasks at a scheduled time provided by an embodiment of the present invention;

[0054] Figure 6 is an application schematic diagram of a timed execution node provided by an embodiment of the present invention;

[0055] Figure 7 is an exemplary system architecture diagram to which embodiments of the present invention may be applied;

[0056] Figure 8 It is a schematic diagram of the structure of a computer system suitable for implementing an electronic device of an embodiment of the present invention. DETAILED DESCRIPTION

[0057] The following is a description of exemplary embodiments of the present invention in conjunction with the accompanying drawings, including various details of the embodiments of the present invention to facilitate understanding, which should be considered as merely exemplary. Therefore, it should be recognized by those of ordinary skill in the art that various changes and modifications may be made to the embodiments described herein without departing from the scope and spirit of the present invention. Similarly, for clarity and conciseness, the description of well-known functions and structures is omitted in the following description.

[0058] The embodiment of the present invention provides a method for executing tasks at a scheduled time, such as Figure 1 As shown, the method includes: step S101, step S102 and step S103. The above steps can be deployed and executed on a timing execution node independent of the business system, and the execution process is separated from the business.

[0059] In step S101, in the scheduled task waiting set, a scheduled task to be executed currently is determined, and the task execution time of the scheduled task to be executed currently is before the current time or is the current time.

[0060] The preconfigured scheduled task waiting set includes all scheduled tasks that need to be executed on a scheduled basis. To use the scheduled task waiting set, you only need to determine the scheduled tasks that need to be executed at the moment. Therefore, in the scheduled task waiting set, the scheduled tasks only need to be associated with their execution time, without any other information. Therefore, the scheduled task waiting set can use a low-complexity high-performance data persistence method, such as the redis cache database.

[0061] Then in step S102, the execution parameters of the scheduled task to be executed are queried in the scheduled task information table. The execution parameters of each scheduled task in the scheduled task waiting set are maintained in the scheduled task information table. The scheduled task information table is used to store detailed information of the scheduled tasks. After the scheduled task to be executed is determined in step S101, the detailed information of the scheduled task can be queried in the scheduled task information table, and then the task is executed through subsequent steps. In one embodiment, the scheduled task information table can be implemented using a mysql database.

[0062] In step S103, the execution parameters of the currently scheduled task to be executed are sent to the business end, so that the business end can execute the currently scheduled task to be executed using the execution parameters. In one embodiment, in this step, the execution parameters of the scheduled task are used to call back the scheduled task target method of the business system to execute the scheduled task, and the execution parameters are the input parameters of the target method.

[0063] In one embodiment of the present invention, the above steps can be executed according to a set period. Since the scheduled task waiting set adopts a high-performance data persistence method with lower complexity, the set period can be 1 second or shorter, thereby reducing the time error of the scheduled task execution.

[0064] The scheduled execution nodes that execute the above steps can be deployed in a distributed manner and have strong scalability. As the amount of scheduled tasks in the business system increases, the efficiency of scheduled execution tasks can be improved by adding scheduled execution nodes.

[0065] The method for scheduled task execution provided by the above embodiment of the present invention separates the process of determining the currently scheduled task to be executed from the business and is executed independently of the business system, thereby reducing the pressure on the business database of the business system. In addition, in the process of determining the currently scheduled task to be executed, the scheduled task waits for the task to be determined centrally, and then the corresponding information is queried in the scheduled task information table for callback, without traversing the database storing detailed information to determine the task to be executed, thereby improving the efficiency and performance of the scheduled task execution. In addition, the method for scheduled task execution can be applied to a distributed execution framework, and the execution nodes can be horizontally expanded to meet the processing requirements of a large number of scheduled tasks of the business system.

[0066] In one embodiment, the method for executing a scheduled task provided by the present invention also includes the following process of receiving information and persisting: First, the information of the scheduled task sent by the business end is received, and the information of the scheduled task includes: the execution parameters of the task and the execution time of the task. The execution time is the time when the business system needs to execute the task. The information of the scheduled task is then maintained in the scheduled task information table, and the scheduled task is added to the scheduled task waiting set and associated with its execution time. The execution time of each scheduled task can be used to determine the scheduled task to be executed, that is, the task whose execution time is before the current time or is the current time.

[0067] The business end can send information about the scheduled tasks of the business system (for example, automatic cancellation of overdue payment orders, on-time order transmission, etc.) to the scheduled execution node through messages through the configured interactive protocol.

[0068] In one embodiment of the invention, the method for executing a scheduled task provided by the present invention also includes the following process: after receiving the information of the scheduled task sent by the service end, a unique ID of the scheduled task is generated. Then, in the process of adding the scheduled task to the scheduled task waiting set and associating it with its execution time, a set element of the scheduled task is generated and added to the scheduled task waiting set. The set element includes: a set key and a corresponding score. The set key is determined according to the unique ID of the scheduled task, and its corresponding score value is determined according to the execution time of the scheduled task. The scheduled task waiting set is an ordered set, and the set elements are sorted according to the score value. In the ordered set, by executing the corresponding search command according to the current time and returning the elements in the specified interval in the ordered set, the tasks whose task execution time is before the current time or is the current time can be obtained.

[0069] In one embodiment of the invention, the method for executing tasks on a scheduled basis provided by the present invention also includes the following process: after determining the currently scheduled task to be executed in the scheduled task waiting set, deleting the currently scheduled task to be executed in the scheduled task waiting set to ensure that the scheduled task will not be executed repeatedly. After the execution parameters of the currently scheduled task to be executed are sent to the service end, the information of the currently scheduled task to be executed is deleted in the scheduled task information table. After the parameters are successfully sent, the corresponding records in the scheduled task information table will be deleted, and they will not be deleted if they are not successfully sent, thereby ensuring the security of the data and preventing data loss.

[0070] In extreme cases, the data in the scheduled task waiting set may be deleted, but the scheduled task execution parameters may not be sent successfully, and the data that failed to execute needs to be restored to the scheduled task waiting set. Therefore, in one embodiment of the invention, the method for executing scheduled tasks provided by the present invention also includes the following data recovery process: according to the set period, the information of the scheduled tasks in the scheduled task information table is traversed, and the scheduled tasks whose execution time is earlier than the set time are determined, and the scheduled tasks are added to the scheduled task waiting set. In one embodiment, the above-mentioned set time can be the current time, that is, if there is a scheduled task in the scheduled task information table whose execution time is before the current time, it means that the scheduled task has been determined and deleted in the scheduled task waiting set, but has not been sent successfully, so it is still retained in the scheduled task information table. Therefore, the scheduled task is added to the scheduled task waiting set to restore the data and wait for subsequent execution.

[0071] In one embodiment of the present invention, the information of the scheduled task also includes: the communication mode and communication address of the task. This information is stored in the scheduled task information table. In step S103, the process of sending the execution parameters of the scheduled task to be executed to the service end is specifically: in the scheduled task information table, query the communication mode and communication address of the scheduled task to be executed, and use the communication mode and communication address to send the execution parameters of the scheduled task to be executed to the service end. In the present invention, the communication mode of the callback business system can be, for example, through an interface interface, or a message queue mq, etc.

[0072] The method for executing tasks on a scheduled basis provided by the present invention is further described below through a specific implementation. In this implementation, the method is executed by a scheduled execution cluster composed of a plurality of scheduled execution nodes deployed in a distributed manner. The scheduled execution nodes in the scheduled execution cluster can be dynamically expanded.

[0073] like Figure 2 As shown, the business system sends a scheduled task with an execution time to the scheduled execution node, and the scheduled execution node regularly calls back the business system target method according to the execution time.

[0074] The business system sends out information about scheduled tasks (businesses) through messages according to the interactive protocol. The information includes: application name namespace, business type biz_type, communication method execute_type, target interface name execute_target (i.e. communication address), business ID: execute_id, execution parameter execute_context, and execution time execute_time.

[0075] The gateway of the scheduled execution cluster determines which scheduled execution node to route the business scheduled task to based on the application namespace and business type bizType.

[0076] In this embodiment, the scheduled execution node is deployed with a mysql database, and the scheduled task information table is deployed in the mysql database. The scheduled task information table contains the following fields: self-increment primary key ID, generated unique ID: sys_key, business system application name namespace, business type biz_type, communication method execute_type, target interface name execute_target, business ID: execute_id, execution parameter execute_context, execution time execute_time, creation time created_datetime, modification time modified_datetime. The mysql database can be divided into multiple tables according to the amount of data.

[0077] In this implementation, for high availability considerations, the MySQL database used in this solution can be configured with at least two sets of isolated databases, which the system will automatically allocate into a primary database and a backup database. If the primary database connection is abnormal, the data will be stored in the backup database.

[0078] In this embodiment, the scheduled execution node is deployed with a redis cache database, and the scheduled task waiting set is deployed in the redis cache database. In the redis cache database, the scheduled task waiting set uses the sortedset based on the redis skip list. Each element contains a unique key key in the set and a corresponding dobule type score score. The elements are sorted by the value of the score score, for example:

[0079] [[key:score], [key2:score2], [key3:score3]]. The key cannot be repeated, but the score can be repeated. The key corresponds to the unique ID in the MySQL table: sys_key, and the score corresponds to the execution time execute_time in the MySQL table;

[0080] The redis cache database can generate multiple sortedsets according to the amount of data, and determine which sortedset to store the data in by performing hash calculation based on the unique ID: sys_key.

[0081] The scheduled execution node receives the scheduled tasks passed by the gateway and persists them. Since the underlying database uses sub-libraries and sub-tables, a unique ID is generated for each business message, which is the sys_key of the storage layer. This implementation method uses the ID high-concurrency generation algorithm snowflake to generate a unique ID.

[0082] Then convert the message content into an object used by the storage layer and fill it with the generated unique ID. Because the MySQL of the data storage layer is divided into databases and tables, the rules of database and table division will be pre-configured in the routing layer. The number of Redis sorted sets will also be pre-configured in the routing layer. Before the business message is persisted, the unique ID: sys_key will be used to calculate which table and a sorted set in Redis to store it in.

[0083] Then the business message is stored in the database and in redis. If one party fails, the final data is kept consistent through asynchronous messages. After the above steps are completed, the business system task is returned successfully.

[0084] The scheduled execution node consumes the elements in the redis ordered set through multithreading. In this implementation, the redis ordered set is sorted from small to large according to the time when the task needs to be executed, so all scheduled tasks only need to scan the data in front of the sorting. If the score of the data at the head of the queue is greater than or equal to the current time, the data will be consumed quickly.

[0085] like Figure 3 As shown, the specific steps are as follows:

[0086] Step 1: The scheduled execution node obtains the current time and initializes it to the variable endtime.

[0087] Step 2: Execute the zrangbyscore command of redis to return the list of members in the specified score range in the ordered set, that is, obtain the elements before endtime to obtain an element list list.

[0088] Step 3, traverse the elements in the list list, and execute the redis zrem command for each element to remove one or more members in the ordered set. Non-existent members will be ignored, that is, delete the element. If the deletion is successful, execute step 4, otherwise delete the next element. The redis zrem command can only be successfully executed once, so the task will not be executed repeatedly.

[0089] Step 4: Map the key of each element in the list to the unique ID of the MySQL database: sys_key, and obtain the data of the scheduled task through the key.

[0090] Step 5. Find the target interface that the business system needs to execute based on the acquired communication method execute_type and the target interface name execute_target, and pass the execution parameter execute_context to the target method for execution. By obtaining the communication method field from the MySQL database, it is determined whether the business system wants to call back through mq or the interface. After determining the method, the input parameter is the content in the execution parameter field.

[0091] Step 6: If the data is transferred successfully, delete the corresponding record in the MySQL database.

[0092] The embodiment of the present invention also provides a system for executing tasks at a fixed time, such as Figure 4 As shown, it includes: a service end 401 and a timed execution cluster 402 , and the timed execution cluster 402 includes at least one timed execution node 403 .

[0093] The scheduled execution node 403 includes: a task determination module 4031 , an information acquisition module 4032 and a data sending module 4033 .

[0094] The task determination module 4031 is used to determine the scheduled task to be executed currently in the scheduled task waiting set, and the task execution time of the scheduled task to be executed currently is before the current time or is the current time;

[0095] The information acquisition module 4032 is used to query the execution parameters of the scheduled task to be executed in the scheduled task information table. The scheduled task information table maintains the execution parameters of each scheduled task in the scheduled task waiting set.

[0096] The data sending module 4033 is used to send the execution parameters of the currently scheduled task to be executed to the service end, so that the service end can execute the currently scheduled task to be executed using the execution parameters.

[0097] In the present invention, the timing execution node also includes: a receiving module and a data persistence module.

[0098] The receiving module is used to receive the information of the scheduled task sent by the business end. The information of the scheduled task includes: the execution parameters of the task and the execution time of the task.

[0099] The data persistence module is used to maintain the information of the scheduled task in the scheduled task information table, and to add the scheduled task to the scheduled task waiting set and associate it with its execution time.

[0100] In the present invention, Figure 5 As shown, the business end sends the scheduled task message of the business application to the scheduled execution cluster gateway through a preset communication method. The scheduled execution cluster gateway determines which scheduled execution node to route the scheduled task message to based on the application name namespace and business type bizType in the scheduled task message.

[0101] In the present invention, the data persistence module is further used to generate a unique ID of the scheduled task after receiving the information of the scheduled task sent by the service end.

[0102] The data persistence module is further used to generate a collection element of the scheduled task and add it to the scheduled task waiting set. The collection element includes: a collection key and a corresponding score value. The collection key is determined according to the unique ID of the scheduled task, and its corresponding score value is determined according to the execution time of the scheduled task. The scheduled task waiting set is an ordered set, and the collection elements are sorted according to the score value.

[0103] In the present invention, the task determination module is further configured to delete the currently to-be-executed scheduled task from the scheduled task waiting set after determining the currently to-be-executed scheduled task from the scheduled task waiting set.

[0104] The information acquisition module is further used to delete the information of the scheduled task to be executed currently in the scheduled task information table after sending the execution parameters of the scheduled task to be executed currently to the service end.

[0105] In the present invention, the scheduled execution node further includes: an abnormal task recovery module. The abnormal task recovery module is used to traverse the information of the scheduled tasks in the scheduled task information table according to the set period, determine the scheduled tasks whose execution time is earlier than the set time, and add the scheduled tasks to the scheduled task waiting set.

[0106] In the present invention, the information of the scheduled task also includes: the communication method and communication address of the task.

[0107] The information acquisition module is further used to query the communication mode and communication address of the currently executed scheduled task in the scheduled task information table.

[0108] The data sending module is further used to send the execution parameters of the current scheduled task to be executed to the service end by using the communication mode and the communication address.

[0109] like Figure 6 As shown, in a specific embodiment of the present invention, the data persistence module includes: a submodule for generating a unique ID, which is used to generate a unique universal unique identification code uuid for each business message. A conversion and translation submodule, which is used to convert the message content into an object used by the storage layer and fill in the uuid. A routing module, which is used to calculate which table of the mysql database and which ordered set of the redis cache database the task is stored in based on the generated unique ID. A transaction module, which is used to store business messages in the mysql database and in the redis cache database. If one party fails, the final data is kept consistent by means of asynchronous messages. After the above steps are completed, the data persistence module returns a successful receipt to the client.

[0110] The MySQL database used in this solution can be configured with at least two sets of isolated databases, which are automatically allocated by the system into a master database and a backup database. If the master database connection is abnormal, the data will be stored in the backup database. Correspondingly, the redis cache database generates an ordered set-master and an ordered set-backup. The scheduled task execution unit includes a task determination module, an information acquisition module, and a data sending module, which will not be repeated here. The abnormal task recovery module includes: a master recovery module and a backup recovery module. The master recovery module performs data recovery between the database master database and the ordered set-master, and the backup recovery module performs data recovery between the database backup database and the ordered set-backup.

[0111] The method and system for scheduled task execution provided by the embodiment of the present invention separate the process of determining the currently scheduled task to be executed from the business and execute it independently of the business system, thereby reducing the pressure on the business database of the business system. In addition, in the process of determining the currently scheduled task to be executed, the scheduled task waits for the task to be determined centrally, and then the corresponding information is queried in the scheduled task information table for callback, without traversing the database storing detailed information to determine the task to be executed, thereby improving the efficiency and performance of the scheduled task execution. In addition, the method for scheduled task execution can be applied to a distributed execution framework, and the execution nodes can be horizontally expanded to meet the processing requirements of a large number of scheduled tasks of the business system.

[0112] Figure 7An exemplary system architecture 700 is shown to which the method for executing tasks at a scheduled time or the system for executing tasks at a scheduled time according to the embodiments of the present invention may be applied.

[0113] like Figure 7 As shown, system architecture 700 may include terminal devices 701, 702, 703, network 704 and server 705. Network 704 is used to provide a medium for communication links between terminal devices 701, 702, 703 and server 705. Network 704 may include various connection types, such as wired, wireless communication links or optical fiber cables, etc.

[0114] The user can use the terminal devices 701, 702, 703 to interact with the server 705 through the network 704 to receive or send messages, etc. Various communication client applications can be installed on the terminal devices 701, 702, 703.

[0115] The terminal devices 701 , 702 , and 703 may be various electronic devices having a display screen and supporting web browsing, including but not limited to smart phones, tablet computers, laptop computers, and desktop computers.

[0116] Server 705 can be a server that provides various services, such as determining the scheduled task to be executed currently, and sending the execution parameters of the scheduled task to be executed currently to the business end, so that the business end can use the execution parameters to execute the background management server of the scheduled task to be executed currently.

[0117] It should be noted that the method for executing tasks at a scheduled time provided in the embodiment of the present invention is generally executed by the server 705 , and accordingly, the scheduled execution node is generally set in the server 705 .

[0118] It should be understood that Figure 7 The number of terminal devices, networks and servers in the embodiment is only for illustration. Any number of terminal devices, networks and servers may be provided according to implementation requirements.

[0119] Reference below Figure 8 , which shows a schematic diagram of the structure of a computer system 800 of a terminal device suitable for implementing an embodiment of the present invention. Figure 8 The terminal device shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present invention.

[0120] like Figure 8As shown, the computer system 800 includes a central processing unit (CPU) 801, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 802 or a program loaded from a storage part 808 into a random access memory (RAM) 803. In the RAM 803, various programs and data required for the operation of the system 800 are also stored. The CPU 801, the ROM 802, and the RAM 803 are connected to each other via a bus 804. An input / output (I / O) interface 805 is also connected to the bus 804.

[0121] The following components are connected to the I / O interface 805: an input section 806 including a keyboard, a mouse, etc.; an output section 807 including a cathode ray tube (CRT), a liquid crystal display (LCD), etc., and a speaker, etc.; a storage section 808 including a hard disk, etc.; and a communication section 809 including a network interface card such as a LAN card, a modem, etc. 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 needed. A removable medium 811, such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc., is installed on the drive 810 as needed, so that a computer program read therefrom is installed into the storage section 808 as needed.

[0122] In particular, according to the embodiments disclosed in the present invention, the process described above with reference to the flowchart can be implemented as a computer software program. For example, the embodiments disclosed in the present invention include a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program includes a program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from the network through the communication part 809, and / or installed from the removable medium 811. When the computer program is executed by the central processing unit (CPU) 801, the above-mentioned functions defined in the system of the present invention are executed.

[0123] It should be noted that the computer-readable medium shown in the present invention may be a computer-readable signal medium or a computer-readable storage medium or any combination of the above two. The computer-readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, 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 disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present invention, a computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in combination with an instruction execution system, device or device. In the present invention, a computer-readable signal medium may include a data signal propagated in a baseband or as part of a carrier wave, which carries a computer-readable program code. This propagated data signal may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. Computer-readable signal media may also be any computer-readable medium other than computer-readable storage media, which may send, propagate or transmit a program for use by or in conjunction with an instruction execution system, apparatus or device. The program code contained on the computer-readable medium may be transmitted using any appropriate medium, including but not limited to: wireless, wire, optical cable, RF, etc., or any suitable combination of the above.

[0124] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, function and operation of the system, method and computer program product according to various embodiments of the present invention. In this regard, each box in the flow chart or block diagram can represent a module, a program segment, or a part of a code, and the above-mentioned module, program segment, or a part of a code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a different order from the order marked in the accompanying drawings. For example, two boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram or flow chart, and the combination of the boxes in the block diagram or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.

[0125] The modules involved in the embodiments of the present invention may be implemented by software or hardware. The modules described may also be set in a processor. For example, it may be described as follows: a processor includes a task determination module, an information acquisition module, and a data transmission module. The names of these modules do not, in some cases, constitute limitations on the modules themselves.

[0126] As another aspect, the present invention further provides a computer-readable medium, which may be included in the device described in the above embodiment; or may exist independently without being assembled into the device. The above computer-readable medium carries one or more programs, and when the above one or more programs are executed by a device, the device includes:

[0127] In the scheduled task waiting set, determine the scheduled task to be executed currently, wherein the task execution time of the scheduled task to be executed currently is before the current time or is the current time;

[0128] In the scheduled task information table, query the execution parameters of the scheduled task to be executed currently, wherein the scheduled task information table maintains the execution parameters of each scheduled task in the scheduled task waiting set;

[0129] The execution parameters of the currently to-be-executed scheduled task are sent to the service end, so that the service end can execute the currently to-be-executed scheduled task using the execution parameters.

[0130] The above specific implementations do not constitute a limitation on the protection scope of the present invention. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions may occur depending on design requirements and other factors. Any modification, equivalent substitution and improvement made within the spirit and principle of the present invention shall be included in the protection scope of the present invention.

Claims

1. A method for executing tasks at a scheduled time, characterized in that: A timed execution cluster composed of multiple timed execution nodes in distributed deployment is applied, and the method includes: Receive the scheduled task information sent by the service end, and generate a unique ID for the scheduled task, wherein the scheduled task information includes the execution parameters and the execution time of the task; Maintain the information of the scheduled task in the scheduled task information table, add the scheduled task to the scheduled task waiting set and associate it with its execution time; the scheduled task information table is deployed in the MySQL database and allocated into a primary database and a backup database; the scheduled task waiting set is deployed in the redis cache database, and the redis cache database generates an ordered set-primary and an ordered set-backup; In the scheduled task waiting set, determine the scheduled task to be executed currently, wherein the task execution time of the scheduled task to be executed currently is before the current time or is the current time; In the scheduled task information table, query the execution parameters of the scheduled task to be executed currently, wherein the scheduled task information table maintains the execution parameters of each scheduled task in the scheduled task waiting set; Sending the execution parameters of the currently scheduled task to be executed to the service end, so that the service end can execute the currently scheduled task to be executed using the execution parameters; The step of adding the scheduled task to the scheduled task waiting set and associating it with its execution time includes: generating a set element of the scheduled task and adding it to the scheduled task waiting set, the set element including: a set key and a corresponding score, the set key is determined according to the unique ID of the scheduled task, and the corresponding score value is determined according to the execution time of the scheduled task, the scheduled task waiting set is an ordered set, and the set elements are sorted according to the score values.

2. The method according to claim 1, characterized in that Also includes: After determining the currently scheduled task to be executed in the scheduled task waiting set, deleting the currently scheduled task to be executed in the scheduled task waiting set; After the execution parameters of the currently to-be-executed scheduled task are sent to the service end, the information of the currently to-be-executed scheduled task is deleted from the scheduled task information table.

3. The method according to claim 2, characterized in that Also includes: According to the set cycle, the information of the scheduled tasks in the scheduled task information table is traversed, the scheduled tasks whose execution time is earlier than the set time are determined, and the scheduled tasks are added to the scheduled task waiting set.

4. The method according to claim 1, characterized in that: The information of the scheduled task also includes: the communication method and communication address of the task; The sending of the execution parameters of the currently scheduled task to be executed to the service end includes: querying the communication mode and communication address of the currently scheduled task to be executed in the scheduled task information table, and sending the execution parameters of the currently scheduled task to be executed to the service end using the communication mode and communication address.

5. A system for executing tasks at a fixed time, characterized in that: A timed execution cluster composed of multiple timed execution nodes applied to distributed deployment, the system comprises: a service end and a timed execution cluster, the timed execution cluster comprises at least one timed execution node; The timing execution node includes: The receiving module is used to receive the information of the scheduled task sent by the service end, wherein the information of the scheduled task includes the execution parameters of the task and the execution time of the task; The data persistence module is used to maintain the information of the scheduled task in the scheduled task information table, and add the scheduled task to the scheduled task waiting set and associate it with its execution time; the scheduled task information table is deployed in the MySQL database and is divided into a primary database and a backup database; the scheduled task waiting set is deployed in the redis cache database, and the redis cache database generates an ordered set-primary and an ordered set-backup; A task determination module is used to determine a scheduled task to be executed currently in the scheduled task waiting set, wherein the task execution time of the scheduled task to be executed currently is before the current time or is the current time; An information acquisition module, used to query the execution parameters of the scheduled task to be executed currently in the scheduled task information table, wherein the scheduled task information table maintains the execution parameters of each scheduled task in the scheduled task waiting set; A data sending module, used for sending the execution parameters of the currently to-be-executed scheduled task to the service end, so that the service end can execute the currently to-be-executed scheduled task using the execution parameters; The data persistence module is further used to generate a unique ID of the scheduled task after receiving the information of the scheduled task sent by the business end; and generate a set element of the scheduled task and add it to the scheduled task waiting set, the set element includes: a set key and a corresponding score, the set key is determined according to the unique ID of the scheduled task, and its corresponding score value is determined according to the execution time of the scheduled task, the scheduled task waiting set is an ordered set, and the set elements are sorted according to the score value.

6. The system according to claim 5, characterized in that The task determination module is further used to delete the currently to-be-executed scheduled task from the scheduled task waiting set after determining the currently to-be-executed scheduled task from the scheduled task waiting set; The information acquisition module is further used to delete the information of the currently scheduled task to be executed in the scheduled task information table after sending the execution parameters of the currently scheduled task to be executed to the service end.

7. The system according to claim 6, characterized in that The timing execution node also includes: The abnormal task recovery module is used to traverse the information of the scheduled tasks in the scheduled task information table according to the set period, determine the scheduled tasks whose execution time is earlier than the set time, and add the scheduled tasks to the scheduled task waiting set.

8. The system according to claim 6, characterized in that The information of the scheduled task also includes: the communication method and communication address of the task; The information acquisition module is further used to query the communication mode and communication address of the currently to-be-executed scheduled task in the scheduled task information table; The data sending module is further used to send the execution parameters of the current scheduled task to be executed to the service end by using the communication mode and the communication address.

9. An electronic device for executing tasks at a fixed time, characterized in that: include: 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 according to any one of claims 1 to 4.

10. A computer readable medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the method according to any one of claims 1 to 4 is implemented.

Citation Information

Patent Citations

  • Timed-task scheduling method, device and system

    CN106815066A

  • Timed task cluster and execution method thereof

    CN108182108A