Delay execution method and device of task, equipment and storage medium

By setting up a priority queue and task sorting mechanism in a distributed environment, the problem of not being able to freely specify the delay time and data loss during delayed task execution is solved, and a balance is achieved between data security and execution efficiency.

CN120743451APending Publication Date: 2025-10-03CHINA PING AN LIFE INSURANCE CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510831836.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-06-19
Publication Date
2025-10-03

AI Technical Summary

Technical Problem

In a distributed environment, it is impossible to freely specify the delay time when delaying task execution and avoid data loss.

Method used

By setting up priority queues in multiple server nodes, tasks are sorted according to their future execution timestamps and executed when the current time reaches the execution timestamp, ensuring that data is not lost when the server crashes, while allowing the delay time to be freely specified.

Benefits of technology

It ensures that data is not lost in a distributed environment while being able to freely specify the delay time, improving the efficiency and flexibility of task execution.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120743451A_ABST
    Figure CN120743451A_ABST
Patent Text Reader

Abstract

The invention belongs to the technical field of big data, is applied to the field of medical treatment and health and the field of financial science and technology, and discloses a task delay execution method, device and equipment and a storage medium, and the task delay execution method comprises the following steps: obtaining a task delay execution request; analyzing the task delay execution request to obtain a task delay parameter in the task delay execution request, and storing the task delay parameter into a database; according to the task delay time, calculating to obtain a future execution timestamp of the delay task; sequentially arranging the delay tasks in a priority queue according to the time sequence of the future execution timestamps of the delay tasks; and checking the delay task at the head of the priority queue, and executing the delay task when the current time reaches the future execution timestamp corresponding to the delay task. According to the invention, the delay time can be freely specified while data loss is avoided.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the field of big data technology and is applied to the fields of medical health and financial technology. In particular, it relates to a method, device, equipment and storage medium for delayed execution of tasks. Background Art

[0002] In certain business scenarios, tasks need to be deferred, and the time for the deferred execution must be freely specified to achieve the expected business results. For example, in life insurance scenarios, customers are required to provide complete health disclosure materials when applying for insurance. If the customer is unable to provide complete health disclosure materials, the underwriting conclusion will be deferred until the information is complete. For another example, in property and casualty insurance scenarios, customers are required to provide complete supporting documents for the insured assets when applying for insurance. If the customer is unable to provide complete supporting documents, the underwriting conclusion will be deferred until the information is complete.

[0003] In the current context, delayed task execution is performed in a stand-alone environment, that is, all processes of delayed task execution are executed by a single server. In this way, when the current server goes down, data loss may occur.

[0004] For this reason, the related art has introduced the delayed execution of tasks in a distributed environment (multiple servers). When one of the multiple servers fails, other servers can take over and execute tasks, thus avoiding data loss to a certain extent. However, due to the large number of servers in a distributed environment, more tasks need to be processed. To freely specify the delay time, a timer must be configured for each delayed task. This consumes too many resources and slows down the execution efficiency of the task. Therefore, the delayed execution time of a task in a distributed environment must be the time specified by the distributed environment. This obviously makes it impossible to freely specify the delay time according to actual needs.

[0005] In summary, the related art cannot guarantee that the delay time can be freely specified while avoiding data loss. Summary of the Invention

[0006] The present invention provides a method, device, equipment and storage medium for delaying the execution of a task, which can solve the technical problem in the prior art of being unable to freely specify a delay time while avoiding data loss.

[0007] In a first aspect, the present invention provides a method for delayed execution of a task, comprising:

[0008] Get task delayed execution request;

[0009] Analyzing the task delay execution request, obtaining a task delay parameter in the task delay execution request, and saving the task delay parameter in a database, wherein the task delay parameter includes a task delay time of the delayed task;

[0010] Calculate the future execution timestamp of the delayed task according to the task delay time;

[0011] Arrange the delayed tasks in a priority queue in sequence according to the time sequence of their future execution timestamps;

[0012] The delayed task at the head of the priority queue is checked, and the delayed task is executed when the current time reaches the future execution timestamp corresponding to the delayed task.

[0013] In a second aspect, the present invention provides a device for delaying execution of a task, comprising:

[0014] Acquisition module, used to obtain task delayed execution request;

[0015] a saving module, configured to analyze the task delay execution request, obtain a task delay parameter in the task delay execution request, and save the task delay parameter to a database, wherein the task delay parameter includes a task delay time of the delayed task;

[0016] A calculation module, configured to calculate a future execution timestamp of the delayed task according to the task delay time;

[0017] An arranging module, configured to arrange the delayed tasks in a priority queue in sequence according to the time sequence of the future execution timestamps of the delayed tasks;

[0018] The execution module is used to check the delayed task at the head of the priority queue, and execute the delayed task when the current time reaches the future execution timestamp corresponding to the delayed task.

[0019] In a third aspect, a computer device is provided, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the steps of the delayed execution method of the above-mentioned task when executing the computer program.

[0020] In a fourth aspect, a computer-readable storage medium is provided, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of the delayed execution method of the above-mentioned task are implemented.

[0021] The solution implemented by the above-mentioned delayed execution method, device, equipment, and storage medium for tasks, because it is applied to multiple server nodes for execution, when a single server node crashes, other server nodes still have information about the relevant delayed tasks, thereby avoiding data loss. In addition, when tasks are executed, they need to be executed by threads. If a priority queue is not set, threads are required to monitor and execute multiple delayed tasks. However, threads are usually located in the memory of the server node. When the server node crashes and restarts, these data will be lost. The threads will lose the monitoring status of the delayed tasks and need to monitor again. However, when a priority queue is set, only the delayed task at the head of the queue needs to be executed. If the server node crashes, only the relevant data of the delayed task at the head of the queue is lost, and the execution order of other delayed tasks in the priority queue is not lost. In addition, setting a priority queue ensures that only the delayed task at the head of the priority queue actually needs a timer to monitor the real-time time. Even if the delay time is freely specified, it will not occupy too many resources, effectively avoiding the problem of not being able to freely specify the delay time when executing delayed tasks in a distributed environment. In summary, the embodiments of the present invention ensure that data is not lost while the delay time can be freely specified. BRIEF DESCRIPTION OF THE DRAWINGS

[0022] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the following briefly introduces the drawings required for use in the description of the embodiments of the present invention. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.

[0023] Figure 1 1 is a flow chart of a method for delayed execution of a task in one embodiment of the present invention;

[0024] Figure 2 is another flowchart of a method for delayed execution of a task in one embodiment of the present invention;

[0025] Figure 3 yes Figure 2 A flow chart of step S110;

[0026] Figure 4 yes Figure 2 Another flow chart of step S110;

[0027] Figure 5 yes Figure 1 A flow chart of step S160;

[0028] Figure 6 yes Figure 1 Another flow chart of step S160;

[0029] Figure 7 1 is a structural diagram of a device for delayed execution of tasks in one embodiment of the present invention;

[0030] Figure 8 is a structural diagram of a computer device in one embodiment of the present invention;

[0031] Figure 9 FIG. 2 is another structural diagram of a computer device according to an embodiment of the present invention. DETAILED DESCRIPTION

[0032] The following will clearly and completely describe the technical solutions in the embodiments of the present invention in conjunction with the accompanying drawings. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of them. All other embodiments obtained by ordinary technicians in this field based on the embodiments of the present invention without making any creative efforts shall fall within the scope of protection of the present invention.

[0033] Figure 1 The flowchart of the method for delaying execution of a task provided by an embodiment of the present invention is as follows: Figure 1 As shown, the delayed execution method of a task provided by an embodiment of the present invention is applied to multiple server nodes and includes the following steps.

[0034] Step S120: Obtain a task delayed execution request.

[0035] Specifically, in this step, the task delay execution request is a request for delaying the execution of a specific task. To enable the server to delay the execution of the task, the task delay execution request may include the information required for successfully delaying the task. For example, the task delay execution request may include a task identifier to facilitate successful locating the corresponding task when delaying the task. The task delay execution request may also include a task delay time so that the server can accurately delay the task based on the task delay time. The task delay execution request may also include a task callback protocol, etc.

[0036] As a specific example, in a life insurance scenario, a delayed task might be that a customer is required to provide complete health disclosure materials when applying for insurance, and the underwriting decision can be postponed until all of this information is complete. Another example is in a property and casualty insurance scenario, where a customer is required to provide complete documentation of the insured assets, and the underwriting decision can be postponed until all of this information is complete.

[0037] It should be noted that the task delay execution request can be sent by any end, for example, it can be sent by a client, and the client can be a mobile terminal or a server.

[0038] It is understandable that, in the embodiment of the present invention, since the embodiment of the present invention is applied to multiple server nodes, the server that obtains the task delayed execution request can be any server node selected as needed.

[0039] In some embodiments of the present invention, Figure 2 As shown, before step S120, the following steps are also included.

[0040] Step S110 : According to the task delayed execution request, each delayed task is evenly distributed to different server nodes according to a preset distribution rule.

[0041] It is understood that when delay requests for multiple delayed tasks are received, in order to reduce the pressure on a single server, the multiple delayed tasks can be evenly distributed to different server nodes to alleviate the pressure on each server node. In order to enable server nodes to execute delayed tasks more efficiently, the server node to which a delayed task belongs can be determined based on the relevant information of the delayed task in the task delay execution request.

[0042] It should be noted that in step S110, evenly distributing the delay tasks to different server nodes may be performed by allocating the same number of delay tasks to each server node, or by ensuring that each server node bears the same service pressure when serving the delay tasks. This is not specifically limited here and can be set according to specific application needs.

[0043] In some embodiments of the present invention, Figure 3 As shown, step S110 includes the following steps.

[0044] Step S1111, analyzing and obtaining the task identifier in the task delayed execution request;

[0045] Step S1112, performing a hash operation on each of the task identifiers to obtain a hash value corresponding to each task identifier;

[0046] Step S1113, taking the modulus of the hash value by the number of server nodes to obtain the server node to which the task identifier is assigned;

[0047] Step S1114: Allocate the delayed task corresponding to the task identifier to the corresponding server node.

[0048] Specifically, a hash operation is based on a hash function. The hash function can map task identifiers of any length to fixed-length hash values, which are evenly distributed across the entire numerical space. Furthermore, when the hash value of the task identifier is modulo the number of server nodes, the hash value can be mapped to 1-the number of server nodes (for example, if the number of server nodes is 9, then 1-9 is used here). This ensures that each task identifier is evenly distributed across each server node, and thus each delayed task is evenly assigned to each server node.

[0049] Specifically, taking the hash value modulo the number of server nodes is the process of dividing the hash value by the number of server nodes to obtain the remainder. For example, if the number of server nodes is 9, the above process is the remainder obtained by dividing the hash value by 9. When the server nodes are numbered 1 to 9, the remainder obtained based on the above process is between 1 and 9, and this remainder can be directly used as the server node number assigned to the task identifier corresponding to the hash value.

[0050] It is understandable that the above method can evenly distribute the delayed tasks to the server nodes, thereby ensuring that the servers can evenly share the execution pressure brought by all delayed tasks and ensuring the execution efficiency of the delayed tasks.

[0051] In some embodiments of the present invention, Figure 4 As shown, step S110 includes the following steps.

[0052] Step S1121, analyzing and obtaining the task delay time in the task postponement request;

[0053] Step S1122, allocating the delayed task to different hierarchical time buckets according to the length of time after the task delay time dynamically changes;

[0054] Step S1123: Allocate the delayed tasks in different level time buckets to different server nodes.

[0055] It can be understood that in step S1122, after the initial analysis obtains the task delay time of the task delay request, the delayed task can be allocated to different levels of time buckets according to the length of the task delay time. For example, when the task delay time is several days, the delayed task can be allocated to a low-level time bucket; when the task delay time is several hours, the delayed task can be allocated to a middle-level time bucket; when the task delay time is several minutes, the delayed task can be allocated to a high-level time bucket.

[0056] Furthermore, while waiting for the delayed task to reach its corresponding execution time, its corresponding task delay time will gradually shorten. During this process, the corresponding hierarchical time bucket can be dynamically updated based on the length of the delayed task's task delay time. For example, if the task delay time of a delayed task increases from one day to 20 hours, it can be updated from the low-level time bucket to the medium-level time bucket.

[0057] In this way, each delayed task in each level of time bucket is assigned to a different server node. Since the time length of the task delay time of the delayed tasks in each level of time bucket is uniform, resources can be effectively saved by processing them through the same server node. For example, the time length corresponding to the task delay time of each delayed task in the high-level time bucket is shorter, and it will reach the execution time quickly. Therefore, the server node corresponding to the high-level time bucket can be used to arrange the delayed tasks in the high-level time bucket in the task execution sequence according to the execution time. The time length corresponding to the task delay time of the delayed task in the middle-level time bucket is in the middle state, then the server node corresponding to the middle-level time bucket can query the task delay time of the delayed task in the middle-level time bucket more frequently, and the time length corresponding to the task delay time of the delayed task in the low-level time bucket is the longest, then the server node corresponding to the low-level time bucket can query the task delay time of the delayed task in the low-level time bucket with a longer period.

[0058] As a specific example, in the field of life insurance, high-value policies require physical examinations, and physical examination reports take a long time. Therefore, the task delay time for insuring high-value policies is usually several days. Therefore, the above delayed task can be assigned to a low-level time bucket; when the beneficiary changes, the identity relationship between the beneficiary and the insured needs to be verified. The task delay time for this insurance task is usually several minutes. Therefore, the above delayed task can be assigned to a high-level time bucket.

[0059] Step S130 : analyzing the task delay execution request, obtaining the task delay parameters in the task delay execution request, and saving the task delay parameters in a database.

[0060] The task delay parameter includes the task delay time of the delayed task.

[0061] It should be noted that when the task delay parameters of the task delayed execution request are stored in the database, when the server node crashes, the task delay parameters in the database will not be lost, and the unexecuted delayed tasks can be re-executed based on the task delay parameters.

[0062] Step S140: Calculate the future execution timestamp of the delayed task according to the task delay time.

[0063] It can be understood that the future execution timestamp of the delayed task is the current timestamp plus the task delay time.

[0064] In step S150 , the delayed tasks are sequentially arranged in a priority queue according to the time sequence of the future execution timestamps of the delayed tasks.

[0065] It can be understood that in this step, the earlier the future execution timestamp of the delayed task, the higher its order in the priority queue, and the later the future execution timestamp of the delayed task, the lower its order in the priority queue.

[0066] Step S160 , checking the delayed task at the head of the priority queue, and executing the delayed task when the current time reaches the future execution timestamp corresponding to the delayed task.

[0067] Thus, it can be understood that in this step, by checking the delayed task at the head of the priority queue, all delayed tasks in the priority queue can be executed according to their corresponding future execution timestamps. This can effectively save resources compared to not setting up a priority queue, as frequent queries on all delayed tasks are required. In addition, when tasks are executed, they need to be executed by threads. If a priority queue is not set up, threads are required to monitor and execute multiple delayed tasks. However, threads are typically located in the memory of the server node. When the server node crashes and restarts, this data will be lost, and the threads will lose the monitoring status of the delayed tasks and need to re-monitor. However, when a priority queue is set up, only the delayed task at the head of the queue needs to be executed. If the server node crashes, only the relevant data of the delayed task at the head of the queue is lost, and the execution order of the other delayed tasks in the priority queue is not lost. In addition, setting up a priority queue ensures that only the delayed task at the head of the priority queue actually requires a timer to monitor the real-time time. Even if a delay time is freely specified, it will not occupy too many resources, effectively avoiding the problem of not being able to freely specify the delay time when executing delayed tasks in a distributed environment. In summary, the embodiments of the present invention ensure that data is not lost while allowing for freely specified delay times.

[0068] In some embodiments of the present invention, Figure 5 As shown, step S160 includes the following steps.

[0069] Step S1611, converting the future execution timestamp into a time offset relative to the start timestamp of a monotonic clock;

[0070] Step S1612: Check the delay task at the head of the priority queue, and execute the delay task when the time elapsed from the monotonic clock reaching the current time matches the time offset.

[0071] It's understandable that the future execution timestamp is the current time plus the task delay time, meaning it's an absolute timestamp relative to the system clock. If the system clock experiences issues, this absolute timestamp can't be guaranteed to be correct. Therefore, converting the future execution timestamp to a time offset relative to the monotonic clock's starting timestamp creates a relative time. Since the time elapsed is objective, when the monotonic clock's elapsed time matches the time offset, the delayed task is executed accurately.

[0072] In some embodiments of the present invention, Figure 6 As shown, step S160 includes the following steps.

[0073] Step S1621, checking the delayed task at the head of the priority queue, and querying the idle threads in the thread pool when the current time reaches the future execution timestamp corresponding to the delayed task;

[0074] Step S1622: Control the idle thread to call back the delayed task.

[0075] It is understandable that there are multiple threads in the thread pool, so when multiple delayed tasks arrive at the future execution timestamp at the same time, multiple delayed tasks can be executed simultaneously, avoiding the congestion caused by a single thread executing multiple delayed tasks.

[0076] In some embodiments of the present invention, the task delay parameter includes a task callback address, and step S160 includes the following steps.

[0077] Step S1631 , checking the delayed task at the head of the priority queue, and when the current time reaches the future execution timestamp corresponding to the delayed task, requesting the task callback address to call back and execute the delayed task.

[0078] It is understandable that when the task delay parameter includes the task callback address, the delayed task can be quickly called back based on the task callback address, thereby preventing the delayed task from being executed on time at the expected time.

[0079] It should be understood that the order of execution of the steps in the above embodiments does not necessarily imply a specific order of execution. The order of execution of each process should be determined by its function and inherent logic, and should not constitute any limitation on the implementation process of the embodiments of the present invention. The software tools or components not provided by our company that appear in the embodiments of this application are merely examples and do not represent actual use.

[0080] In one embodiment, a task delay execution device is provided, which corresponds to the task delay execution method in the above embodiment. Figure 7As shown, the delayed execution device includes an acquisition module 710, a storage module 720, a calculation module 730, an arrangement module 740 and an execution module 750. The functional modules are described in detail as follows:

[0081] An acquisition module 710 is configured to acquire a task delay execution request;

[0082] A saving module 720 is configured to analyze the task delay execution request, obtain a task delay parameter in the task delay execution request, and save the task delay parameter to a database, wherein the task delay parameter includes a task delay time of the delayed task;

[0083] A calculation module 730 is configured to calculate a future execution timestamp of the delayed task based on the task delay time;

[0084] An arranging module 740 is configured to arrange the delayed tasks in a priority queue in sequence according to the time sequence of the future execution timestamps of the delayed tasks;

[0085] The execution module 750 is configured to check the delayed task at the head of the priority queue, and execute the delayed task when the current time reaches the future execution timestamp corresponding to the delayed task.

[0086] In one embodiment, the saving module 720 is further configured to:

[0087] According to the task delay execution request, each delayed task is evenly distributed to different server nodes according to a preset distribution rule.

[0088] In one embodiment, the saving module 720 is further configured to:

[0089] Analyze and obtain the task identifier in the task delayed execution request;

[0090] Performing a hash operation on each of the task identifiers to obtain a hash value corresponding to each task identifier;

[0091] Taking the hash value modulo the number of server nodes to obtain the server node to which the task identifier is assigned;

[0092] Allocate the delayed task corresponding to the task identifier to the corresponding server node.

[0093] In one embodiment, the saving module 720 is further configured to:

[0094] Analyze and obtain the task delay time in the task postponement request;

[0095] Allocate the delayed tasks to different levels of time buckets according to the length of time after the task delay time changes dynamically;

[0096] The delayed tasks in different level time buckets are allocated to different server nodes.

[0097] In one embodiment, the execution module 750 is specifically configured to:

[0098] Converting the future execution timestamp into a time offset relative to a start timestamp of a monotonic clock;

[0099] The delay task at the head of the priority queue is checked, and the delay task is executed when the time elapsed from the monotonic clock to the current time matches the time offset.

[0100] In one embodiment, the execution module 750 is specifically configured to:

[0101] Check the delayed task at the head of the priority queue, and when the current time reaches the future execution timestamp corresponding to the delayed task, query the idle threads in the thread pool;

[0102] Control the idle thread to call back the delayed task.

[0103] In one embodiment, the task delay parameter includes a task callback address; the execution module 750 is specifically configured to:

[0104] The delayed task at the head of the priority queue is checked, and when the current time reaches the future execution timestamp corresponding to the delayed task, the task callback address is requested to execute the delayed task by callback.

[0105] The present invention provides a device for delayed execution of tasks. Since it is applied to multiple server nodes for execution, when a single server node goes down, the other server nodes still have information about the relevant delayed tasks, thereby avoiding data loss. In addition, when a task is executed, it needs to be executed by a thread. If a priority queue is not set, a thread is required to monitor and execute multiple delayed tasks. However, the thread is usually located in the memory of the server node. When the server node goes down and restarts, this data will be lost. The thread will lose the monitoring status of the delayed tasks and need to be re-monitored. However, when a priority queue is set, only the delayed task at the head of the queue needs to be executed. If the server node goes down, only the relevant data of the delayed task at the head of the queue is lost, and the execution order of other delayed tasks in the priority queue will not be lost. In addition, setting a priority queue ensures that only the delayed task at the head of the priority queue actually needs a timer to monitor the real-time time. Even if the delay time is freely specified, it will not occupy too many resources, effectively avoiding the problem of not being able to freely specify the delay time when the delayed task is executed in a distributed environment. In summary, the embodiments of the present invention ensure that data is not lost while the delay time can be freely specified.

[0106] The specific definition of the delayed execution device for a task can be found in the definition of the delayed execution method for a task above, and will not be repeated here. The various modules in the delayed execution device for a task can be implemented in whole or in part by software, hardware, or a combination thereof. The aforementioned modules can be embedded in or independent of the processor in the computer device in hardware form, or can be stored in the memory of the computer device in software form, so that the processor can call and execute the operations corresponding to the aforementioned modules.

[0107] Based on the delayed execution method of the above tasks, such as Figure 8 , an embodiment of the present invention further provides a schematic structural diagram of a device for delaying the execution of a task, the device comprising a processor 81 and a memory 82 coupled to the processor 81. The memory 82 stores a computer program, which, when executed by the processor 81, causes the processor 81 to perform the steps of the method for delaying the execution of a task in the above embodiment.

[0108] For other details about how the processor 81 in the device for the delayed execution step of the above-mentioned task implements the above-mentioned technical solution, please refer to the description of the delayed execution method of the task provided in the above-mentioned embodiment of the invention, which will not be repeated here.

[0109] Among them, the processor 81 can also be called a CPU (Central Processing Unit), and the processor 81 may be an integrated circuit chip with signal processing capabilities; the processor 81 can also be a general-purpose processor, DSP (Digital Signal Process), ASIC (Application Specific Integrated Circuit), FPGA (Field Programmable Gate Array) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, among which the general-purpose processor can be a microprocessor or the processor 81 can also be any conventional processor, etc.

[0110] like Figure 9As shown, an embodiment of the present invention further provides a schematic diagram of the structure of a computer-readable storage medium, on which a readable computer program 91 is stored; wherein, the computer program 91 can be stored in the above-mentioned storage medium in the form of a software product, including a number of instructions for causing a computer device (which can be a personal computer, server, or network device, etc.) or a processor to execute all or part of the steps of the method described in each embodiment of the present invention. The aforementioned storage medium includes: a USB flash drive, a mobile hard disk, a magnetic disk or an optical disk, a ROM (Read-Only Memory), a RAM (Random Access Memory), and other media that can store program code, or a terminal device such as a computer, server, mobile phone, or tablet.

[0111] In the several embodiments provided by the present invention, it should be understood that the disclosed systems, devices and methods can be implemented in other ways. For example, the device embodiments described above are merely illustrative. For example, the division of the modules is merely a logical function division. In actual implementation, there may be other division methods, such as multiple modules or components can be combined or integrated into another system, or some features can be ignored or not executed. In addition, the mutual coupling or direct coupling or communication connection shown or discussed can be an indirect coupling or communication connection through some interface, device or module, which can be electrical, mechanical or other forms.

[0112] The modules described as separate components may or may not be physically separate, and the components shown as modules may or may not be physical modules, that is, they may be located in one place or distributed across multiple network modules. Some or all of the modules may be selected to achieve the purpose of the present embodiment according to actual needs.

[0113] In addition, the functional modules in the various embodiments of the present invention may be integrated into a single processing module, each module may exist physically separately, or two or more modules may be integrated into a single module. The integrated modules may be implemented in the form of hardware or software functional modules. If the integrated modules are implemented in the form of software functional modules and sold or used as independent products, they may be stored in a computer-readable storage medium.

[0114] In the above embodiments, all or part of the embodiments may be implemented by software, hardware, firmware, or any combination thereof. When implemented by software, all or part of the embodiments may be implemented in the form of a computer program product.

[0115] The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, the process or function described in the embodiment of the present invention is generated in whole or in part. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions can be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another computer-readable storage medium. For example, the computer instructions can be transmitted from one website, computer, server or data center to another website, computer, server or data center via a wired (e.g., coaxial cable, optical fiber, digital subscriber line) or wireless (e.g., infrared, wireless, microwave, etc.) method. The computer-readable storage medium can be any available medium that a computer can store or a data storage device such as a server or data center that includes one or more available media integrated. The available medium can be a magnetic medium (e.g., a floppy disk, a hard disk, a tape), an optical medium), or a semiconductor medium (e.g., an SSD (solid state disk)).

[0116] The technical solution provided by the present invention is introduced in detail above. Specific examples are used in the present invention to illustrate the principles and implementation methods of the present invention. The description of the above embodiments is only used to help understand the method of the present invention and its core idea. At the same time, for those skilled in the art, according to the idea of ​​the present invention, there will be changes in the specific implementation methods and application scope. In summary, the content of this specification should not be understood as limiting the present invention.

[0117] It will be understood by those skilled in the art that embodiments of the present invention may be provided as methods, systems, or computer program products. Thus, the present invention may take the form of an entirely hardware embodiment, an entirely software embodiment, or an embodiment combining software and hardware. Furthermore, the present invention may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to magnetic disk storage, optical storage, etc.) containing computer-usable program code.

[0118] The present invention is described with reference to flowcharts and / or block diagrams of methods, devices (systems), and computer program products according to the present invention. It should be understood that each process and / or block in the flowcharts and / or block diagrams, as well as combinations of processes and / or blocks in the flowcharts and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowcharts and / or block diagrams. Figure 1 a process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.

[0119] These computer program instructions may also be stored in a computer readable memory that can direct a computer or other programmable data processing device to work in a specific manner, so that the instructions stored in the computer readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 a process or multiple processes and / or boxes Figure 1 The function specified in one or more boxes.

[0120] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operational steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing the instructions executed on the computer or other programmable device for implementing the process. Figure 1 a process or multiple processes and / or boxes Figure 1 A step that specifies a function in one or more boxes.

[0121] Obviously, those skilled in the art may make various changes and modifications to the present invention without departing from the spirit and scope of the present invention. Thus, if such changes and modifications fall within the scope of the claims and their equivalents, the present invention is intended to include such changes and modifications.

Claims

1. A method for delayed execution of a task, applied to multiple server nodes, characterized in that: The delayed execution method comprises: Get task delayed execution request; Analyzing the task delay execution request, obtaining a task delay parameter in the task delay execution request, and saving the task delay parameter in a database, wherein the task delay parameter includes a task delay time of the delayed task; Calculating a future execution timestamp of the delayed task based on the task delay time; Arrange the delayed tasks in a priority queue in sequence according to the time sequence of their future execution timestamps; The delayed task at the head of the priority queue is checked, and the delayed task is executed when the current time reaches the future execution timestamp corresponding to the delayed task.

2. The method for delayed execution of a task according to claim 1, characterized in that: After acquiring the task delay execution request, analyzing the task delay execution request to obtain the task delay parameter in the task delay execution request, and before saving the task delay parameter in the database, the method further includes: According to the task delay execution request, each delayed task is evenly distributed to different server nodes according to a preset distribution rule.

3. The method for delayed execution of a task according to claim 2, wherein: The step of evenly distributing the delayed tasks to different server nodes according to a preset distribution rule based on the task delayed execution request includes: Analyze and obtain the task identifier in the task delayed execution request; Performing a hash operation on each of the task identifiers to obtain a hash value corresponding to each task identifier; Taking the hash value modulo the number of server nodes to obtain the server node to which the task identifier is assigned; Allocate the delayed task corresponding to the task identifier to the corresponding server node.

4. The method for delayed execution of a task according to claim 2, wherein: The step of evenly distributing the delayed tasks to different server nodes according to a preset distribution rule based on the task delayed execution request includes: Analyze and obtain the task delay time in the task postponement request; Allocate the delayed tasks to different levels of time buckets according to the length of time after the task delay time changes dynamically; The delayed tasks in different level time buckets are allocated to different server nodes.

5. The method for delayed execution of a task according to claim 1, wherein: The checking the delayed task at the head of the priority queue and executing the delayed task when the current time reaches the future execution timestamp corresponding to the delayed task includes: Converting the future execution timestamp into a time offset relative to a start timestamp of a monotonic clock; The delay task at the head of the priority queue is checked, and the delay task is executed when the time elapsed from the monotonic clock to the current time matches the time offset.

6. The method for delayed execution of a task according to claim 1, characterized in that: The checking the delayed task at the head of the priority queue and executing the delayed task when the current time reaches the future execution timestamp corresponding to the delayed task includes: Check the delayed task at the head of the priority queue, and when the current time reaches the future execution timestamp corresponding to the delayed task, query the idle threads in the thread pool; Control the idle thread to call back the delayed task.

7. The method for delayed execution of a task according to claim 1, characterized in that: The task delay parameter includes a task callback address; The checking the delayed task at the head of the priority queue and executing the delayed task when the current time reaches the future execution timestamp corresponding to the delayed task includes: The delayed task at the head of the priority queue is checked, and when the current time reaches the future execution timestamp corresponding to the delayed task, the task callback address is requested to execute the delayed task by callback.

8. A device for delayed execution of a task, characterized in that: Applied to multiple server nodes, the delayed execution method includes: Acquisition module, used to obtain task delayed execution request; a saving module, configured to analyze the task delay execution request, obtain a task delay parameter in the task delay execution request, and save the task delay parameter to a database, wherein the task delay parameter includes a task delay time of the delayed task; A calculation module, configured to calculate a future execution timestamp of the delayed task according to the task delay time; An arranging module, configured to arrange the delayed tasks in a priority queue in sequence according to the time sequence of the future execution timestamps of the delayed tasks; The execution module is used to check the delayed task at the head of the priority queue, and execute the delayed task when the current time reaches the future execution timestamp corresponding to the delayed task.

9. A computer device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein: When the processor executes the computer program, the steps of the method for delayed execution of a task according to any one of claims 1 to 7 are implemented.

10. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the steps of the method for delayed execution of a task according to any one of claims 1 to 7 are implemented.