Scheduled task processing method and device, system, electronic device and storage medium
Through the polling and execution queue mechanism of the scheduled task hash table, the persistence and multi-type task scheduling problems of scheduled task management in the existing technology are solved, achieving highly flexible and lightweight task management, reducing costs and risk.
Patent Information
- Application Number
- CN202010415060.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-05-15
- Publication Date
- 2024-10-18
- Estimated Expiration
- 2040-05-15
AI Technical Summary
The existing scheduled task management method cannot achieve persistence, cannot meet the scheduling of multiple types of tasks, and is costly and risky.
By obtaining the task hash table of the scheduled task, storing the task node according to the delay parameter and preconfigured time accuracy, using the target pointer to poll the task hash table, pushing the task to be executed to the task execution queue and executing it, realizing dynamic monitoring of the task and persistent storage.
It meets the scheduling requirements of multiple types of tasks, provides highly flexible scheduled task management, avoids foreign key dependencies, and achieves lightweight task management and persistence of task data.
Smart Images

Figure CN113672358B_ABST
Abstract
Description
Background Art
[0002] A business system can generally be composed of multiple business modules, which are encapsulated into independently deployed applications and maintained independently. In these business modules, a scheduled task manager is usually used to manage the tasks of each module, and each scheduled task manager needs to rely on its own business data and logic.
[0003] If each module implements its own timing management, it may cause the timing function to be coupled with the business logic. Therefore, the timing task management center needs to achieve unified management of these timing tasks distributed in various business modules.
[0004] There are many ways to implement the existing timed task management technology. Currently, the commonly used implementation methods include: implementation through the function class that comes with the object-oriented programming language (Java language), implementation through the existing open source Quartz framework, implementation through the Spring framework's timed task management, etc.
[0005] It should be noted that the information disclosed in the above background technology section is only used to enhance the understanding of the background of the present disclosure, and therefore may include information that does not constitute the prior art known to ordinary technicians in the field. Summary of the invention
[0006] The purpose of the present disclosure is to provide a scheduled task processing method, a scheduled task processing device, an electronic device and a computer-readable storage medium, thereby at least to a certain extent overcoming the problems of existing scheduled task management methods that cannot achieve persistence, cannot meet the scheduling of multiple types of tasks, have high usage costs and high risks.
[0007] Other features and advantages of the present disclosure will become apparent from the following detailed description, or may be learned in part by the practice of the present invention.
[0008] According to a first aspect of the present disclosure, a method for processing a scheduled task is provided, comprising: obtaining a task hash table including a plurality of scheduled tasks; wherein the scheduled tasks are stored in a task node in the task hash table according to the delay parameters of the scheduled tasks and a preconfigured time precision; determining a node address of a task node currently pointed to by a target pointer, and obtaining a target task in the task node corresponding to the node address; wherein the target pointer is used to poll the task hash table; parsing the target task and obtaining a parsing result, and judging whether the target task is in a pending state according to the parsing result; if the target task is in a pending state, pushing the target task to a task execution queue to generate a pending task, and executing the pending task.
[0009] Optionally, before obtaining a task hash table including multiple scheduled tasks, the above method also includes: obtaining a first delay parameter of the first scheduled task, and determining a first task address of the first scheduled task in the task hash table according to the first delay parameter; taking the node address currently traversed by the target pointer as the current node address; judging whether the current node address is the same as the first task address; if the current node address is the same as the first task address, pushing the first scheduled task to the task execution queue to generate a task to be executed; if the current node address is different from the first task address, storing the first scheduled task in the first task node corresponding to the first task address.
[0010] Optionally, storing the first scheduled task in the first task node corresponding to the task address includes: acquiring a write lock of the first scheduled task; storing the first scheduled task in the first task node through the write lock; and releasing the write lock in response to an execution end instruction of the storage operation of the first scheduled task.
[0011] Optionally, storing the first scheduled task in a first task node corresponding to the first task address includes: obtaining time precision, determining the first task address and the first polling number of the first scheduled task according to the first delay parameter and the time precision; storing the first scheduled task and the first polling number in the first task node; wherein, determining the first task address and the first polling number of the first scheduled task according to the first delay parameter and the time precision includes: performing an integer division operation on the first delay parameter and the time precision to determine the first task address; performing a remainder operation on the first delay parameter and the time precision to determine the first polling number.
[0012] Optionally, the above method also includes: determining a second scheduled task having the same task address as the first scheduled task, and determining a second polling number of the second scheduled task; constructing a task set based on the second scheduled task and the second polling number; determining the address of the predecessor node of the first task node as the first node address, and determining the address of the successor node of the first task node as the second node address; storing the first node address, the second node address and the task set in the first task node.
[0013] Optionally, executing the task to be executed includes: obtaining a consumption lock of the task to be executed, and obtaining the task to be executed from the task execution queue through the consumption lock; executing the task to be executed and obtaining the execution result, and determining whether the execution result is successful; if the execution result is successful, releasing the consumption lock.
[0014] Optionally, the above method also includes: if the execution result is execution failure, pushing the task to be executed to the task execution queue, and obtaining the number of execution failures of the task to be executed; if the number of execution failures is greater than the retry count threshold, determining the task to be executed as a failed execution task, and pushing the failed execution task to the failed task queue.
[0015] According to a second aspect of the present disclosure, a scheduled task processing device is provided, including: a hash table acquisition module, used to obtain a task hash table including multiple scheduled tasks; wherein the scheduled tasks are stored in the task nodes of the task hash table according to the delay parameters of the scheduled tasks and the preconfigured time accuracy; a task acquisition module, used to determine the node address of the task node currently pointed to by the target pointer, and obtain the target task in the task node corresponding to the node address; wherein the target pointer is used to poll the task hash table; a judgment module, used to parse the target task and obtain the parsing result, and judge whether the target task is in a pending state according to the parsing result; a task execution module, used to push the target task to the task execution queue to generate a pending task if the target task is in a pending state, and execute the pending task.
[0016] Optionally, the scheduled task processing device also includes a first task storage module, which is used to obtain a first delay parameter of the first scheduled task, and determine the first task address of the first scheduled task in the task hash table according to the first delay parameter; use the node address currently traversed by the target pointer as the current node address; determine whether the current node address is the same as the first task address; if the current node address is the same as the first task address, push the first scheduled task to the task execution queue to generate a task to be executed; if the current node address is different from the first task address, store the first scheduled task in the first task node corresponding to the first task address.
[0017] Optionally, the first task storage module includes a first task storage unit, which is used to obtain a write lock of the first scheduled task; store the first scheduled task in the first task node through the write lock; and release the write lock in response to an execution end instruction of the storage operation of the first scheduled task.
[0018] Optionally, the first task storage module includes a second task storage unit, which is used to obtain time precision, determine the first task address and the first polling number of the first scheduled task according to the first delay parameter and the time precision; store the first scheduled task and the first polling number in the first task node; wherein, determining the first task address and the first polling number of the first scheduled task according to the first delay parameter and the time precision includes: performing an integer division operation on the first delay parameter and the time precision to determine the first task address; performing a remainder operation on the first delay parameter and the time precision to determine the first polling number.
[0019] Optionally, the scheduled task processing device also includes a second task storage module, which is used to determine a second scheduled task having the same task address as the first scheduled task, and determine a second polling number of the second scheduled task; construct a task set based on the second scheduled task and the second polling number; determine the address of the predecessor node of the first task node as the first node address, and determine the address of the successor node of the first task node as the second node address; store the first node address, the second node address and the task set in the first task node.
[0020] Optionally, the task execution module includes a task execution unit, which is used to obtain a consumption lock of the task to be executed, and obtain the task to be executed from the task execution queue through the consumption lock; execute the task to be executed and obtain the execution result, and determine whether the execution result is successful; if the execution result is successful, release the consumption lock.
[0021] Optionally, the scheduled task processing device also includes a task classification module, which is used to push the task to be executed to the task execution queue and obtain the number of execution failures of the task to be executed if the execution result is execution failure; if the number of execution failures is greater than the retry count threshold, the task to be executed is determined as a failed execution task, and the failed execution task is pushed to the failed task queue.
[0022] According to a third aspect of the present disclosure, a scheduled task processing system is provided, comprising: a task publishing device, used to determine the task address of the scheduled task in a task hash table according to the delay parameters of the scheduled task and the preconfigured time accuracy, and store the scheduled task in the task node corresponding to the task address; wherein the task hash table includes multiple task nodes; a hash table polling device, used to poll the task nodes in the task hash table, and push the to-be-executed tasks in the task nodes to the task execution queue; a task processing device, used to obtain and execute the to-be-executed tasks from the task execution queue, and determine the number of execution failures of the to-be-executed tasks according to the execution results of the to-be-executed tasks; if the number of execution failures is greater than a retry count threshold, the to-be-executed task is determined as a failed execution task, and the failed execution task is pushed to a failed task queue; a failed task management device, used to store the failed execution tasks to restore the failed execution tasks.
[0023] According to a fourth aspect of the present disclosure, an electronic device is provided, comprising: a processor; and a memory, wherein the memory stores computer-readable instructions, and when the computer-readable instructions are executed by the processor, the scheduled task processing method according to any one of the above items is implemented.
[0024] According to a fifth aspect of the present disclosure, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the scheduled task processing method according to any one of the above items is implemented.
[0025] The technical solution provided by the present disclosure may have the following beneficial effects:
[0026] The timed task processing method in the exemplary embodiment of the present disclosure obtains a task hash table including multiple timed tasks; wherein the timed task is stored in the task node of the task hash table according to the delay parameter and pre-configured time precision of the timed task; determines the node address of the task node currently pointed to by the target pointer, and obtains the target task in the task node corresponding to the node address; wherein the target pointer is used to poll the task hash table; parses the target task and obtains the parsing result, and judges whether the target task is in a pending state according to the parsing result; if the target task is in a pending state, the target task is pushed to the task execution queue to generate a pending task, and executes the pending task. Through the timed task processing method disclosed in the present disclosure, on the one hand, the timed task can be hashed and stored in the task hash table according to the delay parameter and pre-configured time precision of the timed task, which can meet the scheduling requirements of multiple types of tasks, has a wide range of applications and high flexibility. On the other hand, by polling the task hash table through the target pointer, the execution frequency of the timed task in the dynamic monitoring task hash table has high flexibility, and the storage structure of the task hash table is simple, there is no foreign key dependency, and a lightweight timed task management can be provided. On the other hand, pushing the target task to the task execution queue for storage can persist the task data of the task to be executed.
[0027] It is to be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the present disclosure. BRIEF DESCRIPTION OF THE DRAWINGS
[0028] The drawings herein are incorporated into the specification and constitute a part of the specification, showing embodiments consistent with the present disclosure, and together with the specification, are used to explain the principles of the present disclosure. Obviously, the drawings described below are only some embodiments of the present disclosure, and for ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work. In the drawings:
[0029] Figure 1 A flowchart of a method for processing a scheduled task according to an exemplary embodiment of the present disclosure is schematically shown;
[0030] Figure 2 Schematically shows a data structure diagram of a task hash table according to an exemplary embodiment of the present disclosure;
[0031] Figure 3 A flowchart of publishing a scheduled task according to an exemplary embodiment of the present disclosure is schematically shown;
[0032] Figure 4A flowchart of a polling task hash table according to an exemplary embodiment of the present disclosure is schematically shown;
[0033] Figure 5 A flowchart for executing a task to be executed according to an exemplary embodiment of the present disclosure is schematically shown;
[0034] Figure 6 A block diagram schematically shows a timed task processing device according to an exemplary embodiment of the present disclosure;
[0035] Figure 7 A block diagram of a timed task processing system according to an exemplary embodiment of the present disclosure is schematically shown;
[0036] Figure 8 A block diagram schematically shows an electronic device according to an exemplary embodiment of the present disclosure;
[0037] Fig. 9 A schematic diagram of a computer-readable storage medium according to an exemplary embodiment of the present disclosure is schematically shown. DETAILED DESCRIPTION
[0038] Example embodiments will now be described more fully with reference to the accompanying drawings. However, example embodiments can be implemented in many forms and should not be construed as limited to the embodiments set forth herein; rather, these embodiments are provided so that this disclosure will be comprehensive and complete and will fully convey the concepts of the example embodiments to those skilled in the art. The same reference numerals in the figures represent the same or similar parts, and thus their repeated description will be omitted.
[0039] In addition, the described features, structures or characteristics may be combined in one or more embodiments in any suitable manner. In the following description, many specific details are provided to provide a full understanding of the embodiments of the present disclosure. However, those skilled in the art will appreciate that the technical solutions of the present disclosure may be practiced without one or more of the specific details, or other methods, components, devices, steps, etc. may be adopted. In other cases, known structures, methods, devices, implementations, materials or operations are not shown or described in detail to avoid blurring the various aspects of the present disclosure.
[0040] The block diagrams shown in the accompanying drawings are merely functional entities and do not necessarily correspond to physically independent entities. That is, these functional entities may be implemented in software form, or these functional entities or parts of functional entities may be implemented in one or more software hardened modules, or these functional entities may be implemented in different networks and / or processor devices and / or microcontroller devices.
[0041] In a business system composed of multiple business modules, each business module is usually encapsulated and split into independently deployed applications and maintained independently. If each module implements its own timing management, it often leads to the inability to centrally manage tasks, resulting in the coupling of timing functions with business logic. Therefore, what the timing task management center needs to do is to uniformly manage these timing tasks scattered in various business modules. Existing timing management task technology implementation methods usually include: Java's own functional class, the existing open source Quartz framework, and Spring's own timing task management.
[0042] When using the Java Timer class to implement it, Timer allows scheduling a java.util.TimerTask task. This method allows the program in the business module to execute at a certain frequency. However, the Timer class implementation has the following shortcomings: (1) There is only one thread that executes the task, so if the execution time of a task is too long, it will destroy the timing accuracy of other tasks; (2) If an exception is thrown during the execution of a task, the execution thread will terminate, causing other tasks to no longer be executed; (3) The Timer class uses absolute time, and its execution depends on the system time. If the system time is modified, the task may not be executed, and the task cannot run at the specified time, which has poor flexibility.
[0043] The ScheduledExecutorService class that comes with the Java language software development kit (JDK) is a timed task class designed based on a thread pool. This memory-based timing method has no persistent tasks. If the program is restarted or crashes, the executing task cannot be restored.
[0044] The Quartz timer implementation method uses a system that is highly invasive. The table structure needs to use the underlying design of Quartz and has foreign key dependencies, which is risky and costly to use.
[0045] Spring's built-in task scheduling implementation makes it more complicated to delete and modify tasks, and this method cannot dynamically modify the execution frequency of tasks. If modification is required, the service can only be restarted.
[0046] Based on this, in this example embodiment, a scheduled task processing method is first provided. The scheduled task processing method of the present disclosure can be implemented using a server, or the method described in the present disclosure can be implemented using a terminal device, wherein the terminal described in the present disclosure may include mobile terminals such as mobile phones, tablet computers, laptops, PDAs, personal digital assistants (PDAs), and fixed terminals such as desktop computers. Figure 1 The following is a schematic diagram showing the flow of a method for processing a scheduled task according to some embodiments of the present disclosure. Figure 1 The scheduled task processing method may include the following steps:
[0047] Step S110, obtaining a task hash table including a plurality of scheduled tasks; wherein the scheduled tasks are stored in task nodes in the task hash table according to the delay parameters of the scheduled tasks and the preconfigured time precision.
[0048] Step S120, determining the node address of the task node currently pointed to by the target pointer, and obtaining the target task in the task node corresponding to the node address; wherein the target pointer is used to poll the task hash table.
[0049] Step S130, analyzing the target task and obtaining the analysis result, and determining whether the target task is in a pending state according to the analysis result.
[0050] Step S140: If the target task is in a pending state, the target task is pushed to a task execution queue to generate a pending task, and the pending task is executed.
[0051] According to the scheduled task processing method in this example embodiment, on the one hand, the scheduled task can be hashed and distributed and stored in the task hash table according to the delay parameters and pre-configured time accuracy of the scheduled task, which can meet the scheduling requirements of various types of tasks, has a wide range of applications and high flexibility. On the other hand, by polling the task hash table through the target pointer, the execution frequency of the scheduled tasks in the task hash table is dynamically monitored with high flexibility, and the storage structure of the task hash table is simple, there is no foreign key dependency, and a lightweight scheduled task management can be provided. On the other hand, the target task is pushed to the task execution queue for storage, and the task data of the task to be executed can be persisted.
[0052] The scheduled task processing method in this exemplary embodiment will be further described below.
[0053] In step S110, a task hash table including a plurality of scheduled tasks is obtained; wherein the scheduled tasks are stored in task nodes of the task hash table according to the delay parameters of the scheduled tasks and the preconfigured time precision.
[0054] In some exemplary embodiments of the present disclosure, a scheduled task may be a pre-configured system task that needs to be executed at a certain time point in the future, and a scheduled task may be a task that has been processed by task release and stored in a task hash table. A scheduled task may be a periodic scheduled task or a one-time scheduled task. For example, a scheduled task may include a pre-set task corresponding to a scheduled shutdown, a memo reminder task, a scheduled reset data task, etc. A task hash table may be a hash table for storing scheduled tasks, and the task nodes in the task hash table store the scheduled tasks that need to be executed. A delay parameter may represent a time parameter from the current moment to the triggering time point of the scheduled task. For example, if a certain alarm clock scheduled task needs to be triggered after three minutes, the delay parameter of the scheduled task is 3 minutes. The time accuracy may be the time accuracy defined according to the triggering time of the scheduled task. For example, the time accuracy of the scheduled task may be set to the "second" level. In other exemplary embodiments, the time accuracy may be determined according to the relevant characteristics of the delay parameter of the scheduled task. For example, the time accuracy may be determined to be "minutes", "microseconds", "milliseconds", etc. The present disclosure does not make any special restrictions on the accuracy level of the time accuracy. A task node may be a node in the task hash table for storing scheduled tasks.
[0055] In the process of implementing the management of scheduled tasks, a task hash table for storing scheduled tasks can be obtained. For each scheduled task, a hash calculation can be performed based on its own delay parameters and pre-configured time accuracy to determine the specific task node where the scheduled task is stored in the task hash table, and store the scheduled task in the task node so that the scheduled task can be triggered and executed later.
[0056] refer to Figure 2 , Figure 2 The data structure diagram of the task hash table according to the exemplary embodiment of the present disclosure is schematically shown. In some exemplary embodiments of the present disclosure, the time precision can be set to the "second" level, so the length of the task hash table can be 60, that is, the task hash table is composed of 60 task nodes, such as task node 210 (node 1), task node 220 (node 2), task node 230 (node 3), until task node 240 (node 60). The task hash table can adopt a double linked list structure, that is, a ring is formed between the task nodes in the task hash table so that the target pointer performs a polling operation of the task hash table.
[0057] According to some exemplary embodiments of the present disclosure, a first delay parameter of a first scheduled task is obtained, and a first task address of the first scheduled task in a task hash table is determined according to the first delay parameter; the node address currently traversed by the target pointer is used as the current node address; it is determined whether the current node address is the same as the first task address; if the current node address is the same as the first task address, the first scheduled task is pushed to a task execution queue to generate a task to be executed; if the current node address is different from the first task address, the first scheduled task is stored in a first task node corresponding to the first task address. The first scheduled task may be a scheduled task to be released in the system. The number of first scheduled tasks may be multiple, and may be scheduled tasks of various different types. The first task address may be the address of a task node in the task hash table where the first scheduled task is located. The target pointer may be a predefined pointer for polling the task hash table. The current node address may be the address of the task node currently pointed to by the target pointer. The task execution queue may be a queue for storing tasks to be executed, and the task execution queue may be implemented by a database that can provide persistent data services, for example, the task execution queue may be implemented by a remote dictionary server (Redis) database. The task to be executed may be a scheduled task that satisfies the execution trigger condition.
[0058] refer to Figure 3 , Figure 3The flowchart of publishing the scheduled task according to the exemplary embodiment of the present disclosure is schematically shown. The present disclosure will take the processing process of the first scheduled task as an example to illustrate the publishing processing process of the scheduled task. For the first scheduled task, the first task address of the first scheduled task in the task hash table can be determined. Specifically, in step S301, the first delay parameter of the first scheduled task can be obtained, and according to the first delay parameter and the pre-set calculation rule, the first delay parameter is calculated according to the calculation rule to determine the first task address of the first scheduled task in the task hash table. In step S302, the node address currently pointed to by the target pointer in the process of traversing the task hash table can be obtained, and the node address is used as the current node address. In step S303, after obtaining the current node address, it can be determined whether the current node address is the same as the calculated first task address. In step S304, if the current node address is the same as the first task address, it means that the scheduled task has reached the execution trigger time, that is, the first scheduled task can be triggered for execution, and therefore, the first scheduled task can be pushed to the task execution queue to execute the first scheduled task. In step S305, if the current node address is different from the first task address, the first scheduled task is stored in the first task node in the task hash table, and the first task node corresponding to the first scheduled task may be the first task node corresponding to the calculated first task address.
[0059] According to another exemplary embodiment of the present disclosure, a write lock of a first scheduled task is acquired; the first scheduled task is stored in a first task node through the write lock; and in response to an execution end instruction of the storage operation of the first scheduled task, the write lock is released. A write lock may be a mechanism used to ensure that a writer performs a write operation on a resource. In the present disclosure, multiple threads may be used to implement the storage of scheduled tasks in a task hash table, and for each scheduled task, only one thread may acquire the write lock of the scheduled task at a time to implement multi-threaded processing. The execution end instruction may be an instruction triggered after the operation of storing the scheduled task in the task hash table is completed.
[0060] The specific process of storing the first scheduled task to the task node is as follows. Figure 3In step S306, before storing the first scheduled task in the first task node in the task hash table, the write lock of the first scheduled task can be acquired by the operation thread. In step S307, it can be determined whether the operation thread has acquired the write lock of the first scheduled task. In step S308, if the operation thread has not acquired the write lock of the first scheduled task, it returns. In step S309, when it is determined that the operation thread has acquired the write lock of the first scheduled task, the first scheduled task can be stored in the first task node corresponding to the first task address in the task hash table. When the storage operation of the first scheduled task is completed, an execution end instruction of the storage operation can be generated. In response to the execution end instruction, the write lock of the first scheduled task can be released.
[0061] According to another exemplary embodiment of the present disclosure, the time precision is obtained, and the first task address and the first polling number of the first scheduled task are determined according to the first delay parameter and the time precision; the first scheduled task and the first polling number are stored in the first task node; wherein, the first task address and the first polling number of the first scheduled task are determined according to the first delay parameter and the time precision, including: performing an integer division operation on the first delay parameter and the time precision to determine the first task address; performing a remainder operation on the first delay parameter and the time precision to determine the first polling number. The first polling number can be the number of times the first scheduled task is taken out from the task hash table and judged whether to trigger execution before triggering execution.
[0062] After obtaining the pre-configured time precision, the first task address and the first polling number of the first scheduled task in the task hash table can be determined according to the first delay parameter and time precision of the first scheduled task. In the present disclosure, the table structure of the task hash table can be a fixed-length array structure. For example, the time precision can be pre-configured to the second level, then the time precision of each hash array can be determined to be 1 second, and the array length of the task hash table can be 60, i.e. 1 minute. Therefore, the task hash table can be composed of 60 task nodes. After obtaining the first delay parameter of the first scheduled task, the first task address and the first polling number corresponding to the first scheduled task can be determined by calculating the first delay parameter and the time precision. For example, the first delay parameter of the first scheduled task can be converted to the second level, the first delay parameter can be represented by Time, the task address can be represented by b, and the number of polling can be represented by n. The first task address of the first scheduled task can be determined by performing an integer division operation on the first delay parameter and the time precision, and the calculation formula of the first task address is Time / 60=n; the first polling number of the first scheduled task can be determined by performing a modulo operation on the first delay parameter and the time precision, and the calculation formula of the first polling number can be Time%60=b. After determining the task address of the first scheduled task, the first scheduled task and the calculated first polling number of the first scheduled task can be stored in the first task node corresponding to the first task address.
[0063] In the present disclosure, the process of determining the task address of the first scheduled task in the task hash table according to the first delay parameter and time accuracy of the first scheduled task, and storing it in the first task node corresponding to the first task address in the task hash table is called a task publishing process. During the task publishing process, multiple operation threads can be started simultaneously, and the task addresses of different scheduled tasks can be determined at the same time, and the scheduled tasks can be stored in the task nodes corresponding to the task addresses. In an exemplary embodiment of the present disclosure, the number of threads of task publishing management can be adjusted according to the number of scheduled tasks, so that the scheduled tasks can be stored in the task hash table in a timely manner.
[0064] According to another exemplary embodiment of the present disclosure, a second scheduled task having the same task address as the first scheduled task is determined, and a second polling number of the second scheduled task is determined; a task set is constructed according to the second scheduled task and the second polling number; the address of the predecessor node of the first task node is determined as the first node address, and the address of the successor node of the first task node is determined as the second node address; the first node address, the second node address and the task set are stored in the first task node. The second scheduled task may be another scheduled task having the same task address as the first scheduled task, that is, the second scheduled task and the first scheduled task are stored in the first task node of the task hash table. The second scheduled task is also a scheduled task to be released. The task address corresponding to the second scheduled task may be referred to as the second task address. The second polling number may be the polling number corresponding to the second scheduled task. The task set may be a set composed of the first scheduled task and the second scheduled task, and the task set stores the first scheduled task and the second scheduled task and the task information of each task, such as the second polling number and the second task address. The first node address may be the address of the predecessor node (previous node) of the first task node where the first scheduled task is located. The second node address may be the address of a successor node (a subsequent node) of the first task node where the first scheduled task is located.
[0065] Since there can be multiple scheduled tasks, the task addresses of each scheduled task can be different. The process of determining the task address corresponding to each scheduled task in the task hash table is as follows. Taking the first scheduled task (scheduled task A) as an example, other scheduled tasks with the same task address as scheduled task A can be determined as second scheduled tasks, and the second scheduled task has the same task address as scheduled task A. After obtaining the delay parameters of these second scheduled tasks, the second polling number of each second scheduled task can be calculated, and the second polling number can be stored together with the second scheduled task as the task information of the second scheduled task, so as to form a task set. The task set can store scheduled tasks with different polling numbers, and these task sets consisting of multiple scheduled tasks with different polling numbers and the same task address can be stored in the same task node. Reference Figure 2 , Figure 2The scheduled tasks 211, 212 and 213 in the task node 1 can form a task set stored in the task node 1, and the task set can be stored in the task node 1. Since the second scheduled task has the same task address as the scheduled task A, the task set can be stored in the task node of the task hash table where the scheduled task A is located. In order to realize the polling of the task hash table, the task hash table can adopt a double linked list structure, and each task node of the task hash table stores the address of the predecessor task node corresponding to the task node and the address of the successor task node. For example, the task addresses corresponding to task node 1 and task node 3 can be stored in task node 2. The task hash table adopts a double linked list structure to improve the deletion speed of the task nodes in the task hash table, and supports the realization of circular polling. Through the above-mentioned task publishing method, the scheduled tasks can be distributed and stored in the task nodes corresponding to the task hash table, so that the scheduled tasks in the task hash table are processed by polling the task hash table.
[0066] In step S120, the node address of the task node currently pointed to by the target pointer is determined, and the target task in the task node corresponding to the node address is obtained; wherein the target pointer is used to poll the task hash table.
[0067] In some exemplary embodiments of the present disclosure, the node address may be the address of the task node currently pointed to by the target pointer during the process of polling the task hash table. The target task may be a scheduled task obtained from the task node corresponding to the node address according to the node address.
[0068] refer to Figure 4 , Figure 4 The flowchart of the polling task hash table according to the exemplary embodiment of the present disclosure is schematically shown. In step S401, after the task hash table is obtained, the node address of the task node currently pointed to by the target pointer in the task hash table can be determined, that is, the current location of the target pointer in the hash task table, and the target task is obtained from the task node according to the node address to process the target task. Specifically, the specific process of obtaining the target task from the task node according to the node address can be that, since there are multiple threads in the present disclosure to perform read and write operations on the scheduled task, in order to ensure the correct operation of multiple threads, therefore, in step S402, before obtaining the target task, the operating thread can first obtain the read lock of the task node, in step S403, it can be determined whether the operating thread has obtained the read lock, and in step S404, if the operating thread has not obtained the read lock for reading the task node, the current operation is terminated. In step S405, when it is determined that the operation thread obtains the read lock for reading the task node, the target task can be obtained from the task node. After obtaining the target task, the read lock is released so that other operation threads can obtain the scheduled task from the task node again in the subsequent process.
[0069] In the process of polling the task hash table through the target pointer, the present disclosure can start only one operation thread to perform the polling operation of the task hash table, without the need for multiple operation threads to monitor the scheduled tasks in real time, which can greatly reduce the waste of thread resources.
[0070] In step S130, the target task is analyzed and the analysis result is obtained, and it is determined whether the target task is in a pending state according to the analysis result.
[0071] In some exemplary embodiments of the present disclosure, parsing the target task may be a parsing operation on the target task. The parsing result may be a result obtained after the parsing operation is performed on the target task. The pending state may be a corresponding state of the target task. When the target task is in the pending state, it indicates that the target task can be triggered for execution. Figure 4 In step S406, after the target task is obtained, the target task can be parsed and the parsing result of the target task can be obtained. In step S407, the task status of the target task is determined according to the parsing result, whether the target task is in a pending state, and the execution of the target task is triggered.
[0072] Specifically, the target task analysis process is as follows: determine whether the value of the target task's polling times is 0. If the value of the target task's polling times is 0, the target task can be considered to be in a pending state. If the value of the target task's polling times is not 0, it is considered that the target task has not yet reached the trigger execution time, and the target task is temporarily not executed.
[0073] In step S140 , if the target task is in a pending state, the target task is pushed to a task execution queue to generate a pending task, and the pending task is executed.
[0074] In some exemplary embodiments of the present disclosure, the task execution queue may be a queue for storing tasks to be executed, and the task execution queue may be implemented based on Redis database technology. The tasks to be executed may be target tasks that have reached the trigger execution time and can be triggered for execution, that is, target tasks in a state to be executed. Figure 4In step S408, if the target task is in a pending state, the target task can be pushed to the task execution queue. When the target task is pushed to the task execution queue, the corresponding pending task will be generated, and the pending task in the task execution queue will be executed. In step S409, if the target task is not in a pending state, that is, the target task is not triggered to be executed, the number of polling times of the target task is reduced by 1, that is, n-1, the number of polling times of the target task is updated, and the updated target task is put back into the task node to wait for the next polling. Through the task processing process in steps S401 to S409, the target task obtained from the task node when polling the task hash table can be processed. In step S410, after the processing of the target task is completed, the target pointer will move to the next node in the task hash table, and the polling operation of the hash task table will continue.
[0075] According to some exemplary embodiments of the present disclosure, a consumption lock of a task to be executed is obtained, and the task to be executed is obtained from a task execution queue through the consumption lock; the task to be executed is executed and the execution result is obtained, and it is determined whether the execution result is successful; if the execution result is successful, the consumption lock is released. The consumption lock can be a mechanism used in a multi-threaded environment to avoid repeated execution of tasks to be executed. The execution result can be a result determined after the execution of the task to be executed is triggered and completed. Releasing the consumption lock can be an operation in which an operating thread releases the consumption lock that triggers the execution of the task to be executed. The release of the consumption lock by the operating thread can enable other operating threads to continue to seize the consumption lock to execute the task to be executed.
[0076] refer to Figure 5 , Figure 5 A flowchart for executing a task to be executed according to an exemplary embodiment of the present disclosure is schematically shown. In step S501, a consumption lock for triggering the execution of the task to be executed is obtained. In step S502, it can be determined whether the operating thread has obtained the consumption lock. In step S503, if the operating thread has not obtained the consumption lock, the current operation is stopped and returned. In step S504, if the operating thread obtains the consumption lock, the task to be executed can be obtained from the task execution queue. In step S505, the task to be executed is executed or the execution result of the task to be executed is obtained. In step S506, it is determined whether the task to be executed is successfully executed. In step S507, if the execution result of the task to be executed is successful, the operating thread can release the consumption lock and return, so that other operating threads can execute other tasks to be executed in the task execution queue through the consumption lock.
[0077] According to some exemplary embodiments of the present disclosure, if the execution result is an execution failure, the task to be executed is pushed to the task execution queue, and the number of execution failures of the task to be executed is obtained; if the number of execution failures is greater than the retry number threshold, the task to be executed is determined to be a failed execution task, and the failed execution task is pushed to the failed task queue. The number of execution failures may be the number of times the task to be executed is not successfully executed. If the execution result of the task to be executed is an execution failure, the number of execution failures of the task to be executed is automatically increased by 1. The retry number threshold may be a pre-configured threshold for counting the number of re-executions of the task to be executed. The failed execution task may be a task to be executed whose number of execution failures is greater than the retry number threshold. The failed task queue may be a queue for storing failed execution tasks, and the failed task queue may be implemented based on a Redis database to achieve the purpose of persistent data.
[0078] refer to Figure 5 In step S508, if the execution result of the task to be executed is execution failure, the task to be executed can be pushed to the task execution queue, and the number of execution failures of the task to be executed can be obtained. The number of execution failures can be updated after each task execution. In step S509, the obtained number of execution failures is compared with the retry number threshold to determine whether the number of execution failures reaches the upper limit of the retry number threshold. In step S510, if the number of execution failures is greater than the retry number threshold, the task to be executed can be determined as a failed execution task and pushed to the failed task queue, so that the failed execution task can be managed through the failed task queue and wait for the failed execution task to be resumed.
[0079] It should be noted that the terms "first", "second", etc. used in the present disclosure are only to distinguish different scheduled tasks. The delay parameters, task nodes, task addresses and polling times corresponding to different scheduled tasks, and different node addresses should not impose any limitations on the present disclosure.
[0080] In summary, a task hash table including multiple timed tasks is obtained; wherein the timed tasks are stored in the task nodes of the task hash table according to the delay parameters and pre-configured time precision of the timed tasks; the node address of the task node currently pointed to by the target pointer is determined, and the target task in the task node corresponding to the node address is obtained; wherein the target pointer is used to poll the task hash table; the target task is parsed and the parsing result is obtained, and the target task is judged whether it is in a pending state according to the parsing result; if the target task is in a pending state, the target task is pushed to the task execution queue to generate a pending task, and the pending task is executed. Through the timed task processing method disclosed in the present invention, on the one hand, the timed tasks can be hashed and distributed and stored in the nodes of the task hash table according to the delay parameters and time precision, which can meet the scheduling requirements of various types of tasks, has a wide range of applications and high flexibility. On the other hand, by polling the task hash table through the target pointer, the execution frequency of the timed tasks in the dynamic monitoring task hash table has high flexibility, and the storage structure of the task hash table is simple, there is no foreign key dependency, and a lightweight timed task management can be provided. On the other hand, the target task is pushed to the task execution queue for storage, and the task data of the pending task can be persisted. On the other hand, by storing and managing failed tasks in a failed task queue, unexecuted failed tasks can be persisted to prevent the inability to restore scheduled tasks due to program restart or downtime.
[0081] It should be noted that, although the steps of the method of the present invention are described in a specific order in the drawings, this does not require or imply that the steps must be performed in this specific order, or that all the steps shown must be performed to achieve the desired results. Additionally or alternatively, some steps may be omitted, multiple steps may be combined into one step, and / or one step may be decomposed into multiple steps, etc.
[0082] In addition, in this exemplary embodiment, a timed task processing device is also provided. Figure 6 The scheduled task processing device 600 may include: a hash table acquisition module 610, a task acquisition module 620, a judgment module 630 and a task execution module 640.
[0083] Specifically, the hash table acquisition module 610 can be used to obtain a task hash table including multiple scheduled tasks; wherein the scheduled tasks are stored in the task node of the task hash table according to the delay parameters of the scheduled tasks and the preconfigured time accuracy; the task acquisition module 620 can be used to determine the node address of the task node currently pointed to by the target pointer, and obtain the target task in the task node corresponding to the node address; wherein the target pointer is used to poll the task hash table; the judgment module 630 can be used to parse the target task and obtain the parsing result, and judge whether the target task is in a pending state according to the parsing result; the task execution module 640 can be used to push the target task to the task execution queue to generate a pending task if the target task is in a pending state, and execute the pending task.
[0084] The scheduled task processing device 600 stores the scheduled tasks in a task hash table according to the delay parameters and pre-configured time accuracy of the scheduled tasks, which can meet the scheduling requirements of various types of tasks, has a wide range of applications, and is highly flexible. The storage structure of the task hash table is simple, and there is no foreign key dependency, which can provide a lightweight scheduled task management. By polling the task nodes in the task hash table through the target pointer, the scheduled tasks in the task hash table can be dynamically monitored, so that the execution frequency of the scheduled tasks has high flexibility. By storing the scheduled tasks in the task execution queue, the task data of the scheduled tasks can be persisted. It can achieve high-performance, high-flexibility, low-complexity and persistent task timing processing, and is an effective scheduled task processing device.
[0085] In an exemplary embodiment of the present disclosure, the scheduled task processing device also includes a first task storage module, which is used to obtain a first delay parameter of the first scheduled task, determine the first task address of the first scheduled task in the task hash table according to the first delay parameter; use the node address currently traversed by the target pointer as the current node address; determine whether the current node address is the same as the first task address; if the current node address is the same as the first task address, push the first scheduled task to the task execution queue to generate a task to be executed; if the current node address is different from the first task address, store the first scheduled task in the first task node corresponding to the first task address.
[0086] In an exemplary embodiment of the present disclosure, the first task storage module includes a first task storage unit, which is used to obtain a write lock of a first scheduled task; store the first scheduled task in a first task node through the write lock; and release the write lock in response to an execution end instruction of the storage operation of the first scheduled task.
[0087] In an exemplary embodiment of the present disclosure, the first task storage module includes a second task storage unit, which is used to obtain time precision, determine the first task address and the first polling number of the first scheduled task according to the first delay parameter and the time precision; store the first scheduled task and the first polling number in the first task node; wherein, determining the first task address and the first polling number of the first scheduled task according to the first delay parameter and the time precision includes: performing an integer division operation on the first delay parameter and the time precision to determine the first task address; performing a remainder operation on the first delay parameter and the time precision to determine the first polling number.
[0088] In an exemplary embodiment of the present disclosure, the scheduled task processing device also includes a second task storage module, which is used to determine a second scheduled task having the same task address as the first scheduled task, and determine a second polling number for the second scheduled task; construct a task set based on the second scheduled task and the second polling number; determine the address of the predecessor node of the first task node as the first node address, and determine the address of the successor node of the first task node as the second node address; store the first node address, the second node address and the task set in the first task node.
[0089] In an exemplary embodiment of the present disclosure, the task execution module includes a task execution unit, which is used to obtain a consumption lock of a task to be executed, and obtain the task to be executed from a task execution queue through the consumption lock; execute the task to be executed and obtain the execution result, and determine whether the execution result is successful; if the execution result is successful, release the consumption lock.
[0090] In an exemplary embodiment of the present disclosure, the scheduled task processing device also includes a task classification module, which is used to push the task to be executed to a task execution queue and obtain the number of execution failures of the task to be executed if the execution result is an execution failure; if the number of execution failures is greater than a retry count threshold, the task to be executed is determined as a failed execution task, and the failed execution task is pushed to a failed task queue.
[0091] The specific details of the virtual modules of the above-mentioned scheduled task processing devices have been described in detail in the corresponding scheduled task processing methods, so they will not be repeated here.
[0092] It should be noted that although several modules or units of the timing task processing device are mentioned in the above detailed description, this division is not mandatory. In fact, according to the embodiments of the present disclosure, the features and functions of two or more modules or units described above can be concretized in one module or unit. Conversely, the features and functions of one module or unit described above can be further divided into multiple modules or units to be concretized.
[0093] Furthermore, in another exemplary embodiment, a scheduled task processing system is provided. Figure 7 The scheduled task processing system 700 may include: a task issuing device 710, a hash table polling device 720, a task processing device 730 and a failed task management device 740.
[0094] Specifically, the task publishing device 710 can be used to determine the task address of the scheduled task in the task hash table according to the delay parameters of the scheduled task and the preconfigured time accuracy, and store the scheduled task in the task node corresponding to the task address; wherein the task hash table includes multiple task nodes; the hash table polling device 720 can be used to poll the task nodes in the task hash table, and push the tasks to be executed in the task nodes to the task execution queue; the task processing device 730 can be used to obtain and execute the tasks to be executed from the task execution queue, and determine the number of execution failures of the tasks to be executed according to the execution results of the tasks to be executed; if the number of execution failures is greater than the retry count threshold, the task to be executed is determined as a failed execution task, and the failed execution task is pushed to the failed task queue; the failed task management device 740 can be used to store failed execution tasks to restore the failed execution tasks.
[0095] The scheduled task processing system 700 can determine the task address of the scheduled task in the task hash table according to the delay parameters of the scheduled task in the task publishing queue 701 through the task publishing device, and store the scheduled task in the task hash table; through the hash table polling device, it can poll the task node in the task hash table, and obtain the scheduled task in the task node, and push the scheduled task to the task execution queue 702. After the task processing device completes the processing of the scheduled task, it can determine whether the scheduled task is an execution failure task. If it is an execution failure task, the failed task will be pushed to the failed task queue so that the failed task management device can manage the execution failure task.
[0096] In addition, in an exemplary embodiment of the present disclosure, an electronic device capable of implementing the above method is also provided.
[0097] It will be appreciated by those skilled in the art that various aspects of the present invention may be implemented as systems, methods or program products. Therefore, various aspects of the present invention may be specifically implemented in the following forms, namely: complete hardware embodiments, complete software embodiments (including firmware, microcode, etc.), or embodiments combining hardware and software aspects, which may be collectively referred to herein as "circuits", "modules" or "systems".
[0098] Reference below Figure 8 An electronic device 800 according to such an embodiment of the present invention is described. Figure 8The electronic device 800 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.
[0099] like Figure 8 As shown, the electronic device 800 is in the form of a general computing device. The components of the electronic device 800 may include, but are not limited to: the at least one processing unit 810, the at least one storage unit 820, a bus 830 connecting different system components (including the storage unit 820 and the processing unit 810), and a display unit 840.
[0100] The storage unit stores program codes, which can be executed by the processing unit 810, so that the processing unit 810 executes the steps according to various exemplary embodiments of the present invention described in the above “Exemplary Method” section of this specification.
[0101] The storage unit 820 may include a readable medium in the form of a volatile storage unit, such as a random access memory unit (RAM) 821 and / or a cache memory unit 822 , and may further include a read-only memory unit (ROM) 823 .
[0102] The storage unit 820 may include a program / utility 824 having a set (at least one) of program modules 825, such program modules 825 including but not limited to: an operating system, one or more application programs, other program modules, and program data, each of which or some combination may include an implementation of a network environment.
[0103] Bus 830 may represent one or more of several types of bus structures, including a memory unit bus or memory unit controller, a peripheral bus, an accelerated graphics port, a processing unit, or a local bus using any of a variety of bus architectures.
[0104] The electronic device 800 may also communicate with one or more external devices 870 (e.g., keyboards, pointing devices, Bluetooth devices, etc.), may also communicate with one or more devices that enable a user to interact with the electronic device 800, and / or communicate with any device that enables the electronic device 800 to communicate with one or more other computing devices (e.g., routers, modems, etc.). Such communication may be performed via an input / output (I / O) interface 850. Furthermore, the electronic device 800 may also communicate with one or more networks (e.g., local area networks (LANs), wide area networks (WANs), and / or public networks, such as the Internet) via a network adapter 860. As shown, the network adapter 860 communicates with other modules of the electronic device 800 via a bus 830. It should be understood that, although not shown in the figure, other hardware and / or software modules may be used in conjunction with the electronic device 800, including but not limited to: microcode, device drivers, redundant processing units, external disk drive arrays, RAID systems, tape drives, and data backup storage systems, etc.
[0105] Through the description of the above embodiments, it is easy for those skilled in the art to understand that the example embodiments described here can be implemented by software, or by software combined with necessary hardware. Therefore, the technical solution according to the embodiment of the present disclosure can be embodied in the form of a software product, which can be stored in a non-volatile storage medium (which can be a CD-ROM, a USB flash drive, a mobile hard disk, etc.) or on a network, and includes several instructions to enable a computing device (which can be a personal computer, a server, a terminal device, or a network device, etc.) to execute the method according to the embodiment of the present disclosure.
[0106] In an exemplary embodiment of the present disclosure, a computer-readable storage medium is also provided, on which a program product capable of implementing the above method of the present specification is stored. In some possible embodiments, various aspects of the present invention can also be implemented in the form of a program product, which includes a program code, and when the program product is run on a terminal device, the program code is used to enable the terminal device to perform the steps according to various exemplary embodiments of the present invention described in the above "Exemplary Method" section of the present specification.
[0107] refer to Fig. 9 As shown, a program product 900 for implementing the above method according to an embodiment of the present invention is described, which can adopt a portable compact disk read-only memory (CD-ROM) and include program code, and can be run on a terminal device, such as a personal computer. However, the program product of the present invention is not limited thereto. In this document, a readable storage medium can be any tangible medium containing or storing a program, which can be used by or in combination with an instruction execution system, an apparatus or a device.
[0108] The program product may use any combination of one or more readable media. The readable medium may be a readable signal medium or a readable storage medium. The 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 (non-exhaustive list) of readable storage media include: an electrical connection with one or more wires, a portable 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.
[0109] Computer readable signal media may include data signals propagated in baseband or as part of a carrier wave, in which readable program code is carried. Such propagated data signals may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. Readable signal media may also be any readable medium other than a readable storage medium, which may send, propagate, or transmit a program for use by or in conjunction with an instruction execution system, apparatus, or device.
[0110] The program code embodied on the readable medium may be transmitted using any appropriate medium, including but not limited to wireless, wired, optical cable, RF, etc., or any suitable combination of the foregoing.
[0111] Program code for performing the operations of the present invention may be written in any combination of one or more programming languages, including object-oriented programming languages such as Java, C++, etc., and conventional procedural programming languages such as "C" or similar programming languages. The program code may be executed entirely on the user computing device, partially on the user device, as a separate software package, partially on the user computing device and partially on a remote computing device, or entirely on a remote computing device or server. In cases involving a remote computing device, the remote computing device may be connected to the user computing device through any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computing device (e.g., through the Internet using an Internet service provider).
[0112] In addition, the above-mentioned figures are only schematic illustrations of the processes included in the method according to an exemplary embodiment of the present invention, and are not intended to be limiting. It is easy to understand that the processes shown in the above-mentioned figures do not indicate or limit the time sequence of these processes. In addition, it is also easy to understand that these processes can be performed synchronously or asynchronously, for example, in multiple modules.
[0113] Those skilled in the art will readily appreciate other embodiments of the present disclosure after considering the specification and practicing the invention disclosed herein. This application is intended to cover any variations, uses, or adaptations of the present disclosure that follow the general principles of the present disclosure and include common knowledge or customary technical means in the art that are not disclosed in the present disclosure. The specification and examples are to be considered as exemplary only, and the true scope and spirit of the present disclosure are indicated by the claims.
[0114] It should be understood that the present disclosure is not limited to the exact structures that have been described above and shown in the drawings, and that various modifications and changes may be made without departing from the scope thereof. The scope of the present disclosure is limited only by the appended claims.
Claims
1. A method for processing a scheduled task, characterized in that: include: Obtain a task hash table including multiple scheduled tasks; wherein the scheduled tasks are stored in the task nodes of the task hash table after hashing the delay parameters of the scheduled tasks and the preconfigured time precision, and the delay parameters are the time length parameters from the current moment to the triggering time point of the scheduled tasks; Determine the node address of the task node currently pointed to by the target pointer, and obtain the target task in the task node corresponding to the node address; wherein the target pointer is used to poll the task hash table; Analyze the target task and obtain the analysis result, and determine whether the target task is in a pending execution state according to the analysis result; If the target task is in a pending state, the target task is pushed to a task execution queue to generate a pending task, and the pending task is executed; The step of parsing the target task and obtaining a parsing result, and judging whether the target task is in a pending execution state according to the parsing result, includes: determining a value of a polling number of the target task, and judging whether the target task is in a pending execution state according to the value of the polling number of the target task.
2. The method for processing scheduled tasks according to claim 1, characterized in that: Before obtaining the task hash table including a plurality of scheduled tasks, the method further includes: Obtain a first delay parameter of a first scheduled task, and determine a first task address of the first scheduled task in the task hash table according to the first delay parameter; Taking the node address currently traversed by the target pointer as the current node address; Determine whether the current node address is the same as the first task address; If the current node address is the same as the first task address, pushing the first scheduled task to the task execution queue to generate the task to be executed; If the current node address is different from the first task address, the first scheduled task is stored in a first task node corresponding to the first task address.
3. The method for processing scheduled tasks according to claim 2, characterized in that: The storing the first scheduled task in the first task node corresponding to the first task address includes: Acquire the write lock of the first scheduled task; The first scheduled task is stored in the first task node through the write lock; In response to an execution end instruction of the storage operation of the first timed task, the write lock is released.
4. The method for processing scheduled tasks according to claim 2, characterized in that: The storing the first scheduled task in the first task node corresponding to the first task address includes: Acquire the time accuracy, and determine the first task address and the first polling number of the first scheduled task according to the first delay parameter and the time accuracy; Storing the first scheduled task and the first polling number in the first task node; The determining of the first task address and the first polling number of the first scheduled task according to the first delay parameter and the time accuracy includes: Performing an integer division operation on the first delay parameter and the time precision to determine the first task address; A modulo operation is performed on the first delay parameter and the time precision to determine the first polling number.
5. The method for processing scheduled tasks according to claim 2, characterized in that: The method further comprises: Determine a second scheduled task having the same task address as the first scheduled task, and determine a second polling number of the second scheduled task; Constructing a task set according to the second scheduled task and the second polling number; Determine the address of the predecessor node of the first task node as the first node address, and determine the address of the successor node of the first task node as the second node address; The first node address, the second node address, and the task set are stored in the first task node.
6. The method for processing scheduled tasks according to claim 1, characterized in that: The executing the task to be executed includes: Acquire the consumption lock of the task to be executed, and acquire the task to be executed from the task execution queue through the consumption lock; Execute the task to be executed and obtain the execution result, and determine whether the execution result is successful; If the execution result is successful, the consumption lock is released.
7. The method for processing scheduled tasks according to claim 6, characterized in that: The method further comprises: If the execution result is execution failure, the task to be executed is pushed to the task execution queue, and the number of execution failures of the task to be executed is obtained; If the number of execution failures is greater than the retry number threshold, the task to be executed is determined as a failed execution task, and the failed execution task is pushed to a failed task queue.
8. A timed task processing device, characterized in that: include: A hash table acquisition module, used to acquire a task hash table including a plurality of scheduled tasks; wherein the scheduled tasks are stored in the task nodes of the task hash table after hash calculation of the delay parameter of the scheduled tasks and the preconfigured time precision, wherein the delay parameter is a time parameter from the current moment to the triggering time point of the scheduled tasks; A task acquisition module, used to determine the node address of the task node currently pointed to by the target pointer, and acquire the target task in the task node corresponding to the node address; wherein the target pointer is used to poll the task hash table; A judgment module, used to analyze the target task and obtain the analysis result, and judge whether the target task is in a pending state according to the analysis result; A task execution module, for pushing the target task to a task execution queue to generate a task to be executed if the target task is in a pending state, and executing the task to be executed; The judgment module is further used to determine the value of the polling number of the target task, and judge whether the target task is in a pending execution state according to the value of the polling number of the target task.
9. A scheduled task processing system, characterized in that: include: A task issuing device, used to determine the task address of the scheduled task in the task hash table according to the delay parameter of the scheduled task and the pre-configured time accuracy, and store the scheduled task in the task node corresponding to the task address; wherein the task hash table includes a plurality of the task nodes; A hash table polling device, used for polling the task nodes in the task hash table, and pushing the to-be-executed tasks in the task nodes to the task execution queue, wherein the to-be-executed tasks are generated by pushing the target tasks in the to-be-executed state to the task execution queue, and the to-be-executed state is determined according to the value of the polling number of the target tasks; A task processing device, used to obtain and execute the task to be executed from the task execution queue, and determine the number of execution failures of the task to be executed according to the execution result of the task to be executed; if the number of execution failures is greater than a retry number threshold, the task to be executed is determined as a failed execution task, and the failed execution task is pushed to a failed task queue; The failed task management device is used to store the failed execution task to restore the failed execution task.
10. An electronic device, characterized in that: include: processor; as well as A memory having computer-readable instructions stored thereon, wherein the computer-readable instructions, when executed by the processor, implement the scheduled task processing method according to any one of claims 1 to 7.
11. A computer-readable storage medium having a computer program stored thereon, wherein the computer program, when executed by a processor, implements the scheduled task processing method according to any one of claims 1 to 7.
Citation Information
Patent Citations
Timing task processing method and device
CN110096340A
