Task scheduling method, device, equipment and computer storage medium
Through the locking processing and delayed execution mechanism of task scheduling in the financial industry, the problem of low efficiency in task scheduling is solved, the unified management and success detection of main tasks and sub-tasks are realized, and the efficiency and success of task scheduling are improved. Rate.
Patent Information
- Application Number
- CN202010530661.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-06-11
- Publication Date
- 2024-10-01
- Estimated Expiration
- 2040-06-11
AI Technical Summary
In task scheduling processing in the financial industry, existing technology cannot achieve unified viewing and effective execution of main tasks and their subsystem tasks, resulting in increased task scheduling costs and low efficiency.
By obtaining the main task to be executed in the main task configuration table, perform locking processing, detect the execution time, obtain the subtask and detect its execution success, if not successful, it will be added to the delay queue and delayed execution according to the retry interval. Until success.
It improves the efficiency of task scheduling processing, avoids repeated execution of tasks, enhances the accuracy of detection and execution of task success, and ensures the success rate of tasks.
Smart Images

Figure CN111666141B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of financial technology (Fintech), and in particular to a task scheduling method, device, equipment and computer storage medium. Background Art
[0002] With the development of computer technology, more and more technologies (big data, distributed, blockchain, artificial intelligence, etc.) are applied in the financial field. The traditional financial industry is gradually transforming to financial technology (Fintech), but due to the security and real-time requirements of the financial industry, higher requirements are also placed on technology. At present, when performing task scheduling, it is generally carried out through QUARTZ (open source job scheduling framework), but when each system uses QUARTZ for task scheduling, it is processed separately, and it is impossible to uniformly view the task execution status of all subsystems corresponding to the main task, and it is impossible to determine whether the main task has been successfully executed, which leads to increased task scheduling costs and low efficiency. Therefore, how to improve the efficiency of task scheduling has become a technical problem that needs to be solved urgently. Summary of the invention
[0003] The main purpose of the present invention is to provide a task scheduling method, device, equipment and computer storage medium, aiming to solve the technical problem of how to improve the efficiency of task scheduling processing.
[0004] To achieve the above object, the present invention provides a task scheduling method, which comprises the following steps:
[0005] Obtain multiple main tasks to be executed in the main task configuration table, and lock each of the main tasks to obtain the execution task;
[0006] Detect whether there is a target task whose execution time is greater than the current time among the execution tasks;
[0007] If so, all subtasks corresponding to the target task are obtained, and the target task is executed according to each of the subtasks to detect whether the target task is executed successfully;
[0008] If the execution is not successful, the target task is added to the delay queue corresponding to the target task, and a retry interval is determined according to the task execution parameters of the target task, and the target task is delayed based on the retry interval.
[0009] If the delayed execution process is successful, it is determined that the target task is executed successfully.
[0010] Optionally, the step of obtaining multiple main tasks to be executed in the main task configuration table includes:
[0011] Obtain all tasks in the main task configuration table, and detect whether the status of each task is the target status;
[0012] If there is a task in each of the tasks whose status is the target status, the task corresponding to the target status is used as the main task.
[0013] Optionally, locking each of the main tasks to obtain a step of executing the task includes:
[0014] Traverse each of the main tasks in turn, and determine whether there is a value in the redis corresponding to the current main task being traversed;
[0015] If not, the target value is input into the redis to complete the locking process of the current main task, and the current main task is used as the execution task until the traversal of each main task is completed.
[0016] Optionally, the step of detecting whether the target task is successfully executed includes:
[0017] Detecting whether there is a subtask that has not been successfully executed among the subtasks;
[0018] If there is a subtask that has not been successfully executed among the subtasks, it is determined that the target task has not been successfully executed.
[0019] Optionally, after the step of delaying the execution of the target task based on the retry interval, the method further comprises:
[0020] If the delayed execution process is unsuccessful, the step of determining a retry interval according to the task execution parameters of the target task, performing delayed execution process on the target task based on the retry interval, and detecting whether the number of times the delayed execution process of the target task is performed is greater than a preset number;
[0021] If it is greater, it is determined that the target task has failed to execute.
[0022] Optionally, before the step of detecting whether there is a target task whose execution time is greater than the current time in each of the execution tasks, the method includes:
[0023] Traversing each of the execution tasks in turn, and determining the task mode corresponding to the currently traversed current execution task, and detecting whether the task mode is a delay mode;
[0024] If so, the execution time of the currently executed task is determined based on a preset time interval until the traversal of each of the executed tasks is completed.
[0025] Optionally, after the step of detecting whether the task mode is a delay mode, the following steps are included:
[0026] If the task mode is the cron mode, a preset fixed time node is obtained, and the execution time of the currently executed task is determined according to the fixed time node until the traversal of each of the executed tasks is completed.
[0027] In addition, to achieve the above object, the present invention also provides a task scheduling device, the task scheduling device comprising:
[0028] An acquisition module is used to acquire multiple main tasks to be executed in the main task configuration table, and lock each of the main tasks to acquire the execution task;
[0029] A detection module, used to detect whether there is a target task whose execution time is greater than the current time among the execution tasks;
[0030] An execution module, used for obtaining all subtasks corresponding to the target task if any, and executing the target task according to each of the subtasks, and detecting whether the target task is executed successfully;
[0031] A delayed execution module, for adding the target task to a delayed queue corresponding to the target task if the execution is unsuccessful, determining a retry interval according to the task execution parameters of the target task, and performing delayed execution processing on the target task based on the retry interval;
[0032] The determination module is used to determine that the target task is executed successfully if the delayed execution process is successful.
[0033] In addition, to achieve the above-mentioned purpose, the present invention also provides a task scheduling device, which includes: a memory, a processor, and a task scheduling program stored in the memory and executable on the processor, and the task scheduling program implements the steps of the task scheduling method described above when executed by the processor.
[0034] In addition, to achieve the above-mentioned purpose, the present invention also provides a computer storage medium, on which a task scheduling program is stored, and when the task scheduling program is executed by a processor, the steps of the task scheduling method described above are implemented.
[0035] The present invention obtains multiple main tasks to be executed in the main task configuration table, and locks each of the main tasks to obtain the execution tasks; detects whether there is a target task whose execution time is greater than the current time in each of the execution tasks; if so, obtains all subtasks corresponding to the target task, executes the target task according to each of the subtasks, and detects whether the target task is successfully executed; if not, adds the target task to the delay queue corresponding to the target task, determines the retry interval time according to the task execution parameters of the target task, and performs delayed execution processing on the target task based on the retry interval time; if the delayed execution processing is successful, it is determined that the target task is successfully executed. By first locking multiple main tasks in the main task configuration table to obtain the execution task, and determining the target task whose execution time is greater than the current time based on the execution task, the effective progress of the target task is guaranteed, and the phenomenon of the same task being executed multiple times at the same time is avoided, thereby ensuring the efficiency of task execution. The target task will be executed according to all subtasks corresponding to the target task, and when the target task is not executed successfully, the target task will be delayed according to the retry interval time, thereby realizing the concatenation of each subtask, improving the accuracy of detecting whether the target task is executed successfully, and delaying the execution of the target task that has not been executed successfully, thereby ensuring the success rate of the target task execution and improving the efficiency of task scheduling. BRIEF DESCRIPTION OF THE DRAWINGS
[0036] Figure 1 It is a schematic diagram of the structure of a task scheduling device in a hardware operating environment involved in an embodiment of the present invention;
[0037] Figure 2 It is a flowchart of the first embodiment of the task scheduling method of the present invention;
[0038] Figure 3 Schematic diagram of device modules of the task scheduling device of the present invention.
[0039] The realization of the purpose, functional features and advantages of the present invention will be further explained in conjunction with embodiments and with reference to the accompanying drawings. DETAILED DESCRIPTION
[0040] It should be understood that the specific embodiments described herein are only used to explain the present invention, and are not used to limit the present invention.
[0041] like Figure 1 As shown, Figure 1 It is a schematic diagram of the structure of a task scheduling device in a hardware operating environment involved in an embodiment of the present invention.
[0042] The task scheduling device in the embodiment of the present invention may be a PC or a server device, on which a Java virtual machine runs.
[0043] like Figure 1 As shown, the task scheduling device may include: a processor 1001, such as a CPU, a network interface 1004, a user interface 1003, a memory 1005, and a communication bus 1002. Among them, the communication bus 1002 is used to realize the connection and communication between these components. The user interface 1003 may include a display screen (Display), an input unit such as a keyboard (Keyboard), and the optional user interface 1003 may also include a standard wired interface and a wireless interface. The network interface 1004 may optionally include a standard wired interface and a wireless interface (such as a WI-FI interface). The memory 1005 may be a high-speed RAM memory, or a stable memory (non-volatile memory), such as a disk memory. The memory 1005 may also be a storage device independent of the aforementioned processor 1001.
[0044] Those skilled in the art will understand that Figure 1 The task scheduling device structure shown in the figure does not constitute a limitation on the device, and may include more or less components than shown in the figure, or combine certain components, or arrange the components differently.
[0045] like Figure 1 As shown, the memory 1005 as a computer storage medium may include an operating system, a network communication module, a user interface module, and a task scheduling program.
[0046] exist Figure 1 In the task scheduling device shown, the network interface 1004 is mainly used to connect to the background server and communicate data with the background server; the user interface 1003 is mainly used to connect to the client (user end) and communicate data with the client; and the processor 1001 can be used to call the task scheduling program stored in the memory 1005 and perform the operations in the following task scheduling method.
[0047] Based on the above hardware structure, an embodiment of the task scheduling method of the present invention is proposed.
[0048] Reference Figure 2 , Figure 2 This is a flow chart of a first embodiment of a task scheduling method of the present invention, wherein the method comprises:
[0049] Step S10, obtaining multiple main tasks to be executed in the main task configuration table, and performing a locking process on each of the main tasks to obtain an execution task;
[0050] In this embodiment, the task scheduling host of the application task scheduling method starts at least two processes for task scheduling management, one of which is a task status daemon process, which is responsible for monitoring the execution status of the task, and the other is a task execution process, which is responsible for scheduling executable tasks. And the main task configuration table in this embodiment is mainly responsible for maintaining the execution status of a certain task, and the table fields include: task name, task ID (Identity document, account number), task mode, task execution time expression, task execution server address list, next execution time, task execution status and task execution parameters. Among them, the task mode includes delay mode and cron mode. When the task mode is delay, it means that the task will be executed at a fixed time interval, and the value of the time interval can be determined according to the task execution time expression, and the unit is milliseconds. For example, when the task mode of a certain task is delay and the task execution time expression is 1000, it can be considered that the task will be automatically executed once every 1000 milliseconds. However, when the task mode is cron, the task execution time expression configuration is a cron expression, and the execution frequency of the task will be determined according to the configured cron expression. For example, when the task execution time expression is configured as 0 10 6 1*?, it means that it will be executed once at 6:10 a.m. on the 1st of each month. Among them, the task execution status mainly includes I-initialization, N-executable, W-executing, S-successful execution, and F-failed execution. And in this embodiment, in addition to providing a main task configuration table, a subtask configuration table is also required. The subtask configuration table mainly maintains the execution status of multiple subtasks corresponding to a main task. The table fields include: main field ID, subtask ID, task execution host list and task execution status (including I-initialization, N-executable, W-executing, S-successful execution, and F-failed execution).
[0051] In this embodiment, the main task in the main task configuration table can be called by multiple servers (i.e., task scheduling servers) at the same time, and in each task accessor, at least one process will be started to detect whether the tasks in the task configuration table (including the main task configuration table and the subtask configuration table) are executable. That is, multiple main tasks to be executed in the main task configuration table are obtained. The way to detect whether the task is executable can be to query the task execution status.
[0052] And in this embodiment, in each task scheduling server, in addition to the above-mentioned task status daemon process, there is also a task execution process, which has multiple execution threads. Among them, the number of execution threads can be determined according to the number of main tasks to be executed, and in order to avoid excessive number of threads, resulting in waste of server resources, a maximum execution thread M (such as M = 15) is generally set, and when the number of tasks is n and the number of servers in the cluster is c, the number of execution threads V = min (M, n / c). And in order to prevent multiple threads from processing the same task at the same time, each main task to be processed can be locked first to obtain the locked main task, that is, the execution task. The locking processing method can be to use redis+lua to lock, that is, in the redis server, use TASK_ID as the primary key to query whether there is a value in redis (data structure server). If there is no value, TASK_ID is written to redis, and true (accurate) is returned at the same time, indicating that the lock has been grabbed; if there is a value, it means that other servers have grabbed the lock and false (error) is returned. And after determining that the main task is locked, it can be used as an execution task and the task status is adjusted to executable.
[0053] Step S20, detecting whether there is a target task whose execution time is greater than the current time among the execution tasks;
[0054] After obtaining each execution task, it is possible to sequentially detect whether there is a target task whose execution time is greater than the current time in each execution task, and perform different operations according to different detection results. Among them, the execution time is the time when the execution task is executed next time.
[0055] Step S30, if it exists, obtain all subtasks corresponding to the target task, and execute the target task according to each subtask, and detect whether the target task is executed successfully;
[0056] When it is found that there is a target task with an execution time greater than the current time, the target task can be executed, that is, the task execution server parses the notification information carried by the target task, obtains the TASK_ID and task execution parameters, and then writes the TASK_ID as the key value and the task execution parameters as the value value to the redis server, and executes the target task according to the TASK_ID matching the corresponding execution method, and then detects whether the target task is executed successfully, and performs different operations according to different detection results. However, if there is no target task with an execution time greater than the current time, continue to wait until the target task exists.
[0057] Among them, the method of detecting whether the target task is executed successfully can be to detect whether all subtasks corresponding to the target task are executed successfully, that is, the task status daemon maintains the execution status of the target task according to the execution results of the subtasks, and detects the execution status of all subtasks corresponding to the target task. If all are executed successfully, the execution status of the target task can be modified to execution success, that is, the target task is determined to be executed successfully. If the execution status of some subtasks is execution failure, the execution status of the target task is modified to execution failure, that is, the target task is determined to be executed failed.
[0058] Step S40, if the execution is not successful, the target task is added to the delay queue corresponding to the target task, and a retry interval is determined according to the task execution parameters of the target task, and a delayed execution process is performed on the target task based on the retry interval;
[0059] Step S50: If the delayed execution process is successful, it is determined that the target task is executed successfully.
[0060] When it is determined that the target task is executed successfully, the target task can be delayed, that is, the target task is added to the delay queue for execution, and the task execution parameter EXEC_PARAMS in the task configuration table where the target task is located is obtained, and the retry interval time is obtained in the task execution parameter. After the retry interval time has passed, the target task is executed, that is, delayed execution is performed. If the delayed execution is successful, it can be determined that the target task is executed successfully. However, if the delayed execution fails, it is necessary to obtain a new retry interval time to continue to execute the target task until the target task is executed successfully, or the number of delayed executions of the target task is greater than a certain value, or it is still in an execution failure state, then the delayed execution of the target task is stopped. That is, read the previously saved information with the key TASK_ID from redis, and obtain the retry interval configuration REDO_TIME_CFG from EXEC_PARAMS. The configuration format can be set as follows: 1,5,10,30,60, which means that 5 retries are required, the first retry interval is 1 minute, the second retry interval is 5 minutes, and so on. And read the key value from redis. If it is not read, it is determined that the first execution failed, and the key is set to 1, and the target task is put into the delay queue of redis for retry. When performing delayed execution processing, a thread will be started to continuously scan the delay queue of redis. If the target task is executed successfully, the key value will be deleted, and the TASK_ID information in redis will be deleted, and then the execution result will be called back to the task scheduling server. If the execution fails, the key value will be increased by 1, and the task will be placed in the redis delay queue according to the configured retry interval and wait for retry processing. When the number of retries exceeds the configured value, it is considered to be a failure. At this time, the result of the task execution failure will be called back to the task scheduling host, and the key value will be deleted, and the TASK_ID information in redis will be deleted. However, if the target task is executed successfully, the data with the key TASK_ID previously written to redis will be deleted, and then the execution result will be called back to the task scheduling server.
[0061] In this embodiment, all scheduled tasks (including main tasks and subtasks) are managed by the task scheduling server, and the execution status of each scheduled task is maintained by the task status daemon, so that all scheduled tasks can be unified, and the execution status of each scheduled task can also be viewed uniformly in the task scheduling server. At the same time, in terms of task concurrency control, the redis+lua locking method is adopted to reduce the dependence on database performance, and the redis delay queue is used to implement the automatic retry mechanism after the task execution fails.
[0062] In this embodiment, multiple main tasks to be executed in the main task configuration table are obtained, and each of the main tasks is locked to obtain the execution task; it is detected whether there is a target task whose execution time is greater than the current time in each of the execution tasks; if so, all subtasks corresponding to the target task are obtained, and the target task is executed according to each of the subtasks to detect whether the target task is successfully executed; if not, the target task is added to the delay queue corresponding to the target task, and the retry interval time is determined according to the task execution parameters of the target task, and the target task is delayed based on the retry interval time. The execution process is performed; if the delayed execution process is successful, it is determined that the target task is successfully executed. By first locking multiple main tasks in the main task configuration table to obtain the execution task, and determining the target task whose execution time is greater than the current time based on the execution task, the effective progress of the target task is guaranteed, and the phenomenon of the same task being executed multiple times at the same time is avoided, thereby ensuring the efficiency of task execution. The target task will be executed according to all subtasks corresponding to the target task, and when the target task is not executed successfully, the target task will be delayed according to the retry interval time, thereby realizing the concatenation of each subtask, improving the accuracy of detecting whether the target task is executed successfully, and delaying the execution of the target task that has not been executed successfully, thereby ensuring the success rate of the target task execution and improving the efficiency of task scheduling.
[0063] Further, based on the first embodiment of the task scheduling method of the present invention, a second embodiment of the task scheduling method of the present invention is proposed. This embodiment is a refinement of step S10 of the first embodiment of the present invention, the step of obtaining multiple main tasks to be executed in the main task configuration table, including:
[0064] Step a, obtaining all tasks in the main task configuration table, and detecting whether the status of each task is the target status;
[0065] In this embodiment, it is also necessary to first obtain all the tasks set in advance by the user in the main task configuration table, and then detect whether the status of each task is the target status in turn to determine whether the task in the main task configuration table can be executed. And different operations are performed according to different detection results. Among them, the status of the task includes I-initialization, N-executable, W-executing, S-execution success, F-execution failure. The target status can be I-initialization, S-execution success and F-execution failure.
[0066] Step b: If there is a task in each of the tasks whose status is the target status, the task corresponding to the target status is used as the main task.
[0067] When it is found that there is a task in the target state among all tasks, this task can be directly used as the main task to perform task locking processing. However, if there is no task in the target state among all tasks, the detection query will continue until the task corresponding to the target state is found.
[0068] In this embodiment, by acquiring all tasks in the main task configuration table and taking the task corresponding to the target state as the main task, the accuracy of the acquired main task is guaranteed.
[0069] Furthermore, each of the main tasks is locked to obtain the steps for executing the task, including:
[0070] Step c, traverse each of the main tasks in turn, and determine whether there is a value in the redis corresponding to the current main task being traversed;
[0071] In this embodiment, when it is necessary to lock each main task, you can choose the redis+lua method to perform locking processing, that is, traverse each main task in turn, and use TASK_ID as the primary key to determine whether there is a value in the redis (data structure server) corresponding to the current main task currently traversed, and perform different operations based on different determination results.
[0072] Step d: if not, input the target value into the redis to complete the locking process of the current main task, and use the current main task as the execution task until the traversal of each main task is completed.
[0073] When it is found through judgment that there is no value in the redis corresponding to the current main task currently traversed, it can be determined that the current main task has not been processed by other threads. At this time, TASK_ID can be written into the redis to indicate that the current main task has grabbed the lock, that is, the locking process of the current main task has been completed. At this time, the current main task that has been locked can be used as the execution task. However, if there is a value in the redis of the current main task, it is determined that the current main task is being processed by other threads. It is necessary to wait for the value in redis to be cleared and write TASK_ID into the redis until the traversal of each main task is completed. Among them, the locking operation is performed in the redis server using a lua script. The target value can be a value set by the user in advance, such as TASK_ID.
[0074] In this embodiment, by traversing each main task and when it is determined that there is no value in the redis corresponding to the current main task, the target value is input to complete the locking process of the current main task to obtain the execution task, until the traversal of each main task is completed, thereby ensuring the accuracy of the acquired execution task.
[0075] Furthermore, the step of detecting whether the target task is successfully executed includes:
[0076] Step e, detecting whether there is any subtask that has not been successfully executed among the subtasks;
[0077] In this embodiment, when detecting whether the target task is executed successfully, it is necessary to first determine the subtask configuration table corresponding to the target task, wherein all subtasks of the target task are placed in the subtask configuration table, and detect whether there are subtasks that have not been successfully executed among all the subtasks in the subtask configuration table, and determine whether the target task is executed successfully based on different detection results.
[0078] Step f: If there is a subtask that has not been successfully executed among the subtasks, it is determined that the target task has not been successfully executed.
[0079] If it is found that some subtasks are successfully executed and some are unsuccessful, that is, there are unsuccessful subtasks in each subtask, it can be determined that the target task is not successfully executed. However, if all subtasks are successfully executed, it can be determined that the target task is successfully executed.
[0080] In this embodiment, when it is determined that there is a subtask that has not been successfully executed among the subtasks, it is determined that the target task has not been successfully executed, thereby ensuring the accuracy of detecting whether the target task has been successfully executed.
[0081] Further, after the step of delaying the execution of the target task based on the retry interval, the method further comprises:
[0082] Step h, if the delayed execution process is unsuccessful, then executing the step of determining the retry interval according to the task execution parameters of the target task, performing delayed execution process on the target task based on the retry interval, and detecting whether the number of delayed execution processes of the target task is greater than a preset number;
[0083] In this embodiment, when it is found that the delayed execution processing of the target task is unsuccessful, it is necessary to continue the delayed execution processing, that is, determine a new retry interval time according to the task execution parameters (the new retry interval time can be the same as the retry interval time, or it can be different), and execute the target task after the new retry interval time. If it is still not executed successfully, continue to perform the delayed execution processing on the target task. And when the target task is delayed, the number of times the target task is delayed is counted, and it is detected whether the number is greater than the preset number (any number set in advance by the user), and different operations are performed according to different detection results, that is, it is determined whether the target task can be successfully executed before the preset number of times when the delayed execution processing is performed. If it can, the operation of delaying the execution of the target task will be stopped when the execution is successful.
[0084] In step x, if it is greater than, it is determined that the target task has failed to execute.
[0085] When it is determined that the number of times the target task is delayed is greater than the preset number, the target task execution may fail. However, if the number of times the target task is delayed is less than or equal to the preset number, it can be determined that the target task has been successfully executed, and when the execution is successful, the operation of delaying the execution of the target task is stopped.
[0086] In this embodiment, if the delayed execution process is unsuccessful, the delayed execution process will continue, and when the number of delayed execution processes for the target task is greater than a preset number, it is determined that the target task has failed to execute, thereby avoiding waste of resources while improving the success rate of the target task execution.
[0087] Furthermore, before the step of detecting whether there is a target task whose execution time is greater than the current time in each of the execution tasks, the method includes:
[0088] Step k, traversing each of the execution tasks in turn, and determining the task mode corresponding to the currently traversed current execution task, and detecting whether the task mode is a delay mode;
[0089] In this embodiment, before executing the execution task, it is necessary to traverse each execution task in turn, and determine whether the task mode of the currently traversed current execution task is the delay mode, and perform different operations according to different detection results. Among them, the task mode includes the delay mode and the cron mode.
[0090] Step m: if yes, then determine the execution time of the currently executed task based on a preset time interval until the traversal of each of the executed tasks is completed.
[0091] When it is determined that the task mode is the delay mode, the time interval set by the user in advance can be directly obtained, and the execution time of the current task can be determined based on the time interval. The time interval can be set by the user in advance according to the task event expression corresponding to the delay mode, and then the current task is executed according to the execution time. For example, if the task mode of a task is delay, and the time interval set by the user according to the task event expression is 1000 in milliseconds, it can be determined that the task is executed every 1000 milliseconds. Until each task traversal is completed.
[0092] In this embodiment, by traversing each execution task, when the task mode of the current execution task is delay, the execution time is determined according to a preset time interval until the traversal of each execution task is completed, thereby ensuring the accuracy of the acquired execution time.
[0093] Further, after the step of detecting whether the task mode is the DELAY mode, the following steps are included:
[0094] Step n: if the task mode is the cron mode, a preset fixed time node is obtained, and the execution time of the currently executed task is determined according to the fixed time node until the traversal of each of the executed tasks is completed.
[0095] When it is found that the task mode is cron mode, the fixed time node set by the user in advance can be directly obtained, and the execution time of the current task can be determined according to the fixed time node. The fixed time node can be determined by the user in advance according to the task event expression corresponding to the cron mode, and then the current task is executed according to the execution time. For example, if the task mode of a task is cron, and the task event expression set is 0 10 61*?, it can be determined that the task will be executed once at 6:10 am on the 1st of each month until the traversal of each task is completed.
[0096] In this embodiment, when it is determined that the task mode is the cron mode, the execution time is determined according to a preset fixed time node until each execution task traversal is completed, thereby ensuring the accuracy of the acquired execution time.
[0097] The present invention also provides a task scheduling device, referring to Figure 3 , the task scheduling device comprises:
[0098] The acquisition module A10 is used to acquire multiple main tasks to be executed in the main task configuration table, and lock each of the main tasks to acquire the execution task;
[0099] A detection module A20 is used to detect whether there is a target task whose execution time is greater than the current time among the execution tasks;
[0100] An execution module A30 is used to obtain all subtasks corresponding to the target task if it exists, and execute the target task according to each of the subtasks to detect whether the target task is successfully executed;
[0101] The delayed execution module A40 is used to add the target task to the delayed queue corresponding to the target task if the execution is not successful, determine the retry interval according to the task execution parameters of the target task, and perform delayed execution processing on the target task based on the retry interval;
[0102] The determination module A50 is used to determine that the target task is executed successfully if the delayed execution process is successful.
[0103] Optionally, the acquisition module A10 is further used for:
[0104] Obtain all tasks in the main task configuration table, and detect whether the status of each task is the target status;
[0105] If there is a task in each of the tasks whose status is the target status, the task corresponding to the target status is used as the main task.
[0106] Optionally, the acquisition module A10 is further used to:
[0107] Traverse each of the main tasks in turn, and determine whether there is a value in the redis corresponding to the current main task being traversed;
[0108] If not, the target value is input into the redis to complete the locking process of the current main task, and the current main task is used as the execution task until the traversal of each main task is completed.
[0109] Optionally, the execution module A30 is further used to:
[0110] Detecting whether there is a subtask that has not been successfully executed among the subtasks;
[0111] If there is a subtask that has not been successfully executed among the subtasks, it is determined that the target task has not been successfully executed.
[0112] Optionally, the delayed execution module A40 is further used to:
[0113] If the delayed execution process is unsuccessful, the step of determining a retry interval according to the task execution parameters of the target task, performing delayed execution process on the target task based on the retry interval, and detecting whether the number of times the delayed execution process of the target task is performed is greater than a preset number;
[0114] If it is greater, it is determined that the target task has failed to execute.
[0115] Optionally, the detection module A20 is further used to:
[0116] Traversing each of the execution tasks in turn, and determining the task mode corresponding to the currently traversed current execution task, and detecting whether the task mode is a delay mode;
[0117] If so, the execution time of the currently executed task is determined based on a preset time interval until the traversal of each of the executed tasks is completed.
[0118] Optionally, the detection module A20 is further used to:
[0119] If the task mode is the cron mode, a preset fixed time node is obtained, and the execution time of the currently executed task is determined according to the fixed time node until the traversal of each of the executed tasks is completed.
[0120] The methods executed by the above-mentioned program units can refer to the various embodiments of the task scheduling method of the present invention, which will not be described in detail here.
[0121] The invention also provides a computer storage medium.
[0122] The computer storage medium of the present invention stores a task scheduling program, and when the task scheduling program is executed by a processor, the steps of the task scheduling method described above are implemented.
[0123] Among them, the method implemented when the task scheduling program running on the processor is executed can refer to the various embodiments of the task scheduling method of the present invention, and will not be repeated here.
[0124] It should be noted that, in this article, the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, article or system including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or system. In the absence of further restrictions, an element defined by the sentence "comprises a ..." does not exclude the existence of other identical elements in the process, method, article or system including the element.
[0125] The serial numbers of the above embodiments of the present invention are only for description and do not represent the advantages or disadvantages of the embodiments.
[0126] Through the description of the above implementation methods, those skilled in the art can clearly understand that the above-mentioned embodiment methods can be implemented by means of software plus a necessary general hardware platform, and of course by hardware, but in many cases the former is a better implementation method. Based on such an understanding, the technical solution of the present invention is essentially or the part that contributes to the prior art can be embodied in the form of a software product, which is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk) as described above, and includes a number of instructions for a terminal device (which can be a mobile phone, computer, server, air conditioner, or network device, etc.) to execute the methods described in each embodiment of the present invention.
[0127] The above are only preferred embodiments of the present invention, and are not intended to limit the patent scope of the present invention. Any equivalent structure or equivalent process transformation made using the contents of the present invention specification and drawings, or directly or indirectly applied in other related technical fields, are also included in the patent protection scope of the present invention.
Claims
1. A task scheduling method, characterized in that: The task scheduling method comprises the following steps: Obtain multiple main tasks to be executed in the main task configuration table, and perform locking processing on each of the main tasks to obtain the execution task; wherein the locking processing includes: querying whether there is a value in redis with the task account TASK_ID of the main task as the primary key in the data structure server redis, and if there is no value, writing TASK_ID to redis to complete the locking processing of the main task; Detect whether there is a target task whose execution time is greater than the current time among the execution tasks; If so, all subtasks corresponding to the target task are obtained, and the target task is executed according to each of the subtasks to detect whether the target task is successfully executed; wherein the target task is executed based on a task execution process, and the task execution process includes multiple execution threads, and the number of execution threads is the minimum value between the maximum number of execution threads and a set value, and the set value is the ratio of the number of main tasks to the number of cluster servers; If the execution is not successful, the target task is added to the delay queue corresponding to the target task, and a retry interval is determined according to the task execution parameters of the target task, and the target task is delayed based on the retry interval. If the delayed execution process is successful, it is determined that the target task is executed successfully.
2. The task scheduling method according to claim 1, characterized in that: The step of obtaining a plurality of main tasks to be executed in the main task configuration table includes: Obtain all tasks in the main task configuration table, and detect whether the status of each task is the target status; If there is a task in each of the tasks whose status is the target status, the task corresponding to the target status is used as the main task.
3. The task scheduling method according to claim 1, characterized in that: The step of detecting whether the target task is successfully executed includes: Detecting whether there is a subtask that has not been successfully executed among the subtasks; If there is a subtask that has not been successfully executed among the subtasks, it is determined that the target task has not been successfully executed.
4. The task scheduling method according to claim 1, characterized in that: After the step of delaying the execution of the target task based on the retry interval, the method further comprises: If the delayed execution process is unsuccessful, the step of determining a retry interval according to the task execution parameters of the target task, performing delayed execution process on the target task based on the retry interval, and detecting whether the number of times the delayed execution process of the target task is performed is greater than a preset number; If it is greater, it is determined that the target task has failed to execute.
5. The task scheduling method according to any one of claims 1 to 4, characterized in that: Before the step of detecting whether there is a target task whose execution time is greater than the current time among the execution tasks, the step includes: Traversing each of the execution tasks in turn, and determining the task mode corresponding to the currently traversed current execution task, and detecting whether the task mode is a delay mode; If so, the execution time of the currently executed task is determined based on a preset time interval until the traversal of each of the executed tasks is completed.
6. The task scheduling method according to claim 5, characterized in that: After the step of detecting whether the task mode is the delay mode, the method further comprises: If the task mode is the cron mode, a preset fixed time node is obtained, and the execution time of the currently executed task is determined according to the fixed time node until the traversal of each of the executed tasks is completed.
7. A task scheduling device, characterized in that: The task scheduling device comprises: The acquisition module is used to acquire multiple main tasks to be executed in the main task configuration table, and perform locking processing on each of the main tasks to acquire the execution task; wherein the locking processing includes: using the task account TASK_ID of the main task as the primary key in the data structure server redis to query whether there is a value in redis, and if there is no value, writing TASK_ID to redis to complete the locking processing of the main task; A detection module, used to detect whether there is a target task whose execution time is greater than the current time among the execution tasks; An execution module, used for obtaining all subtasks corresponding to the target task, if any, and executing the target task according to each of the subtasks, and detecting whether the target task is successfully executed; wherein the target task is executed based on a task execution process, the task execution process includes multiple execution threads, the number of the execution threads is the minimum value between the maximum number of execution threads and a set value, and the set value is the ratio of the number of main tasks to the number of cluster servers; A delayed execution module, for adding the target task to a delayed queue corresponding to the target task if the execution is unsuccessful, determining a retry interval according to the task execution parameters of the target task, and performing delayed execution processing on the target task based on the retry interval; The determination module is used to determine that the target task is executed successfully if the delayed execution process is successful.
8. A task scheduling device, characterized in that: The task scheduling device comprises: a memory, a processor, and a task scheduling program stored in the memory and executable on the processor. When the task scheduling program is executed by the processor, the steps of the task scheduling method according to any one of claims 1 to 6 are implemented.
9. A computer storage medium, characterized in that The computer storage medium stores a task scheduling program, and when the task scheduling program is executed by the processor, the steps of the task scheduling method according to any one of claims 1 to 6 are implemented.
Citation Information
Patent Citations
Method and equipment for task issuance
CN107479962A
Condition-based task scheduling method and device, equipment and storage medium
CN110333940A
Multi-task processing method and device based on service system, equipment and storage medium
CN110413388A
