Delayed task execution method and device, equipment, storage medium and product

By polling and processing delay tasks in relational databases, the problem of high complexity of the system of performing distributed delay tasks in the prior art is solved, and a simpler and more flexible system architecture is realized.

CN119718722APending Publication Date: 2025-03-28ZHEJIANG ZEEKR INTELLIGENT TECH CO LTD +1
View PDF 8 Cites 0 Cited by

Patent Information

Application Number
CN202411800611.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-12-09
Publication Date
2025-03-28

AI Technical Summary

Technical Problem

In the prior art, the system for performing distributed delay tasks is highly complex, resulting in increased maintenance and management difficulties.

Method used

By scanning the delay tasks stored in the relational database at every preset first interval, obtaining task information and processing tasks according to execution policies, the dependence on middleware is reduced and the system architecture is simplified.

Benefits of technology

Reduces the system complexity of performing distributed delay tasks, improves system flexibility and maintainability, and reduces dependence on message queues.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119718722A_ABST
    Figure CN119718722A_ABST
Patent Text Reader

Abstract

The invention discloses a delay task execution method and device, equipment, a storage medium and a product, relates to the technical field of computers, and discloses a delay task execution method which comprises the steps that delay tasks stored in a preset relational database are scanned every preset first interval time, task information of all the delay tasks is obtained, the delay task is pre-stored in the relational database, and the task information comprises task parameters and an execution strategy; if the task parameter meets a preset execution condition, executing a corresponding delay task through a preset executor to obtain a task execution result; and if the task execution result is execution failure, processing the delay task based on the execution strategy to obtain a target processing result. According to the method, a database polling implementation mode is provided, and complex middleware does not need to be introduced, so that the complexity of a system for executing the distributed delay task is reduced.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of computer technology, and in particular to a method, device, equipment, storage medium and product for executing a delayed task. Background Art

[0002] At present, with the development of computer technology, enterprises are facing problems such as the surge in the number of users, high concurrency challenges, and the increase in the complexity of business logic, which requires the modernization of the traditional task scheduling mechanism. Based on this, technicians proposed a distributed delayed task system to solve the above problems. Among them, the construction of the distributed delayed task system aims to solve core problems such as high availability, fault-tolerant recovery, scalability, load balancing, elastic scheduling and data consistency.

[0003] In the related technology, the message queue method is usually adopted, that is, the system modules transmit messages and data through the message queue to realize the distributed delay task processing. However, after the additional introduction of the message queue in this method, the corresponding maintenance and management mechanism needs to be added, which increases the complexity of the overall system and leads to high system complexity in executing distributed delay tasks.

[0004] The above contents are only used to assist in understanding the technical solution of the present application and do not constitute an admission that the above contents are prior art. Summary of the invention

[0005] The main purpose of this application is to provide a method for executing a delayed task, aiming to solve the technical problem of high system complexity in executing distributed delayed tasks in related technologies.

[0006] To achieve the above purpose, the present application proposes a method for executing a delayed task, and the method for executing the delayed task includes:

[0007] Scanning the delayed tasks stored in a preset relational database at every preset first interval to obtain task information of each delayed task, wherein the delayed tasks are pre-stored in the relational database, and the task information includes task parameters and execution strategies;

[0008] If the task parameters meet the preset execution conditions, the corresponding delayed task is executed by the preset executor to obtain the task execution result;

[0009] If the task execution result is execution failure, the delayed task is processed based on the execution strategy to obtain a target processing result.

[0010] Optionally, the step of processing the delayed task based on the execution strategy to obtain a target processing result includes:

[0011] Based on the execution strategy, determine the execution interval time and retry number threshold;

[0012] After the execution interval time has passed, retrying the delayed task to obtain a retry execution result;

[0013] Determine whether the retry execution result is an execution failure, if the retry execution result is an execution failure, determine the current retry number, and determine whether the current retry number exceeds the retry number threshold;

[0014] If the current number of retries does not exceed the retry number threshold, then return to the step of retrying the delayed task after the execution interval time to obtain the retry execution result, until the retry execution result is successful or the current number of retries exceeds the retry number threshold, then stop task processing and obtain the target processing result.

[0015] Optionally, if the current number of retries does not exceed the retry number threshold, returning to the step of retrying the delayed task after the execution interval to obtain a retry execution result, until the retry execution result is a successful execution or the current number of retries exceeds the retry number threshold, the task processing is stopped, and the step of obtaining the target processing result includes:

[0016] If the current number of retries does not exceed the retry number threshold, then based on the preset additional duration, the execution interval is increased to obtain the increased execution interval;

[0017] Based on the increased execution interval time, return to the step of retrying the delayed task after the execution interval time has passed to obtain the retry execution result, and stop task processing until the retry execution result is successful or the current retry number exceeds the retry number threshold to obtain the target processing result.

[0018] Optionally, the step of executing the corresponding delayed task by a preset executor to obtain the task execution result includes:

[0019] Obtaining configuration parameters of each executor in a preset executor set, and determining an allocation strategy based on the task parameters and the configuration parameters;

[0020] Based on the allocation strategy, a corresponding target executor is selected from the executor set, and the delayed task is allocated to the corresponding target executor;

[0021] The corresponding delayed task is executed by the target executor to obtain the task execution result.

[0022] Optionally, before the step of scanning the delayed tasks in the preset relational database at every preset first interval to obtain the task information of each delayed task, the method includes:

[0023] After generating the delayed task, determining the task parameters of the delayed task;

[0024] Based on the task parameters, generating an execution strategy for the delayed task;

[0025] The delayed tasks with the execution strategy are stored in a preset relational database.

[0026] Optionally, the target processing result includes delayed task processing information. If the task execution result is execution failure, the delayed task is processed based on the execution strategy to obtain the target processing result. The method includes:

[0027] Classifying each of the delayed task processing information by value to obtain delayed task processing information of different values, wherein delayed task processing information of high value has a long life cycle;

[0028] The delayed task processing information with higher value is stored in the resource pool with longer coverage period, and the delayed task processing information with lower value is stored in the resource pool with shorter coverage period;

[0029] At every preset second interval time, the delayed task processing information that meets the deletion condition in the resource pool is deleted to obtain a deleted resource pool.

[0030] In addition, to achieve the above-mentioned purpose, the present application also proposes a delayed task execution device, the delayed task execution device comprising:

[0031] A scanning module, used for scanning the delayed tasks stored in a preset relational database at every preset first interval time to obtain task information of each delayed task, wherein the delayed tasks are pre-stored in the relational database, and the task information includes task parameters and execution strategies;

[0032] An execution module, used for executing the corresponding delayed task through a preset executor to obtain a task execution result if the task parameters meet the preset execution conditions;

[0033] The processing module is used to process the delayed task based on the execution strategy to obtain a target processing result if the task execution result is execution failure.

[0034] In addition, to achieve the above-mentioned purpose, the present application also proposes a delayed task execution device, which includes: a memory, a processor, and a computer program stored in the memory and executable on the processor, and the computer program is configured to implement the steps of the delayed task execution method as described above.

[0035] In addition, to achieve the above-mentioned purpose, the present application also proposes a storage medium, which is a computer-readable storage medium, and a computer program is stored on the storage medium. When the computer program is executed by the processor, the steps of the execution method of the delayed task as described above are implemented.

[0036] In addition, to achieve the above-mentioned purpose, the present application also provides a computer program product, which includes a computer program, and when the computer program is executed by a processor, it implements the steps of the method for executing the delayed task as described above.

[0037] One or more technical solutions proposed in this application have at least the following technical effects:

[0038] Compared with the related art, which usually adopts the message queue method, that is, the system modules transmit messages and data through the message queue to realize the distributed delayed task processing. However, after the additional introduction of the message queue in this method, the corresponding maintenance and management mechanism needs to be added, which increases the complexity of the overall system, resulting in a high system complexity for executing distributed delayed tasks. In this application, the delayed tasks stored in the preset relational database are scanned at every preset first interval to obtain the task information of each delayed task, wherein the delayed task is pre-stored in the relational database, and the task information includes task parameters and execution strategy; if the task parameters meet the preset execution conditions, the corresponding delayed task is executed by the preset executor to obtain the task execution result; if the task execution result is an execution failure, the delayed task is processed based on the execution strategy to obtain the target processing result. It is understandable that the application proposes to set up a relational database with delayed task information, and realize the processing of delayed tasks by polling the relational database and processing the delayed task by the executor. Among them, the implementation method of database polling does not need to introduce complex middleware, thereby reducing the system complexity of executing distributed delayed tasks. Furthermore, after the task execution fails, the application further processes the delayed task according to the execution strategy pre-stored in the relational database, thereby enhancing the flexibility of task execution. BRIEF DESCRIPTION OF THE DRAWINGS

[0039] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and, together with the description, serve to explain the principles of the present application.

[0040] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.

[0041] Figure 1 A flowchart diagram of the first embodiment of the method for executing a delayed task of the present application;

[0042] Figure 2 This is a schematic diagram of the module interaction flow of the method for executing the delayed task of this application;

[0043] Figure 3 A flowchart diagram of a second embodiment of a method for executing a delayed task of the present application is provided;

[0044] Figure 4 A schematic diagram of the module structure of the execution device of the delayed task in the embodiment of the present application;

[0045] Figure 5 A schematic diagram of the device structure of the hardware operating environment involved in the method for executing a delayed task in an embodiment of the present application.

[0046] The purpose, features and advantages of this application will be further described in conjunction with the embodiments and with reference to the accompanying drawings. DETAILED DESCRIPTION

[0047] It should be understood that the specific embodiments described herein are only used to explain the technical solutions of the present application and are not used to limit the present application.

[0048] In order to better understand the technical solution of the present application, a detailed description will be given below in conjunction with the accompanying drawings and specific implementation methods.

[0049] The main solution of the embodiment of the present application is: at every preset first interval time, the delayed tasks stored in the preset relational database are scanned to obtain task information of each delayed task, wherein the delayed tasks are pre-stored in the relational database, and the task information includes task parameters and execution strategies; if the task parameters meet the preset execution conditions, the corresponding delayed tasks are executed by the preset executor to obtain the task execution result; if the task execution result is an execution failure, the delayed tasks are processed based on the execution strategy to obtain the target processing result.

[0050] In this embodiment, the execution device of the delayed task is taken as the execution subject. For the convenience of description, it will be explained as "device" hereinafter.

[0051] In the related technology, the message queue method is usually adopted, that is, the system modules transmit messages and data through the message queue to realize the distributed delay task processing. However, after the additional introduction of the message queue in this method, the corresponding maintenance and management mechanism needs to be added, which increases the complexity of the overall system and leads to high system complexity in executing distributed delay tasks.

[0052] The present application provides a solution to achieve the execution of distributed delayed tasks and reduce the system complexity of executing distributed delayed tasks.

[0053] From the above embodiments, it can be seen that the present application scans the delayed tasks stored in the preset relational database at every preset first interval time to obtain the task information of each delayed task, wherein the delayed tasks are pre-stored in the relational database, and the task information includes task parameters and execution strategies; if the task parameters meet the preset execution conditions, the corresponding delayed tasks are executed by the preset executor to obtain the task execution result; if the task execution result is an execution failure, the delayed tasks are processed based on the execution strategy to obtain the target processing result. It is understandable that the present application proposes to set up a relational database that stores delayed task information, and to process the delayed tasks by polling the relational database and processing the delayed tasks by the executor. The implementation method of database polling does not require the introduction of complex middleware, thereby reducing the system complexity of executing distributed delayed tasks. And after the task execution fails, the present application further processes its delayed tasks according to the execution strategy pre-stored in the relational database, thereby enhancing the flexibility of task execution.

[0054] It should be noted that the execution subject of this embodiment can be a computing service device with data processing, network communication and program running functions, such as a tablet computer, a personal computer, a mobile phone, etc., or an electronic device capable of realizing the above functions, a terminal system, etc. The following takes the execution device of the delayed task as an example to illustrate this embodiment and the following embodiments.

[0055] Based on this, the present application embodiment provides a method for executing a delayed task, referring to Figure 1 , Figure 1 This is a flow chart of the first embodiment of the method for executing a delayed task of the present application.

[0056] In this embodiment, the method for executing the delayed task includes steps S100 to S300:

[0057] Step S100, scanning the delayed tasks stored in a preset relational database at every preset first interval time to obtain task information of each delayed task, wherein the delayed tasks are pre-stored in the relational database, and the task information includes task parameters and execution strategies;

[0058] It should be noted that the first interval time is a time interval pre-set by the device, which is used to determine how often to scan the delayed tasks in the database. For example, the device scans the delayed tasks in the preset relational database every 5 seconds. The first interval time can be fixed or dynamically adjusted, and is not specifically limited here.

[0059] Furthermore, the relational database refers to a relational database used to store delayed task information in the system, such as MySQL, PostgreSQL, etc. This database will store various information of the task, including but not limited to the creation time, execution time, task status, etc. of the delayed task.

[0060] It is understandable that the delayed task is a special type of task. The delayed task does not need to be executed immediately, but needs to be executed at a specific time point. The delayed task is usually used to process business logic that does not require high real-time performance but needs to be triggered at a specific time. For example, on an e-commerce platform, if the user does not pay within a certain period of time (such as 30 minutes) after placing an order, the device will automatically cancel the order.

[0061] In a specific implementation, when the preset first interval time arrives, the device will perform a scanning operation to query the database for all delayed tasks that meet the execution conditions. This operation usually involves querying a specific table in the database to obtain relevant information about the delayed task. Among them, the task information includes task parameters and execution strategies. The task parameters are specific data required to execute the task, such as input data, configuration parameters, etc.; the execution strategy defines how the task should be executed, including execution priority, retry strategy, failure handling strategy, etc.

[0062] In the specific implementation, the above description is a periodic database scanning process for retrieving and executing delayed tasks that meet the execution conditions. This process is a key component of the distributed task scheduling system, ensuring that the device can execute tasks according to the predetermined schedule.

[0063] In a specific implementation, before the step of scanning the delayed tasks in the preset relational database at every preset interval to obtain the task information of each delayed task, the method includes:

[0064] After generating the delayed task, determining the task parameters of the delayed task; generating an execution strategy of the delayed task based on the task parameters; and storing the delayed task with the execution strategy in a preset relational database.

[0065] In the specific implementation, the device generates a delayed task, which is the process of creating a task that needs to be executed at a certain point in the future. This task may be a simple operation, such as sending a notification, or a complex business process, such as executing a data analysis script.

[0066] It is understandable that the generated delayed task contains task parameters. The device determines the task parameters of the delayed task by extracting the task parameters of the delayed task. The task parameters include but are not limited to: execution time, that is, the specific time or time range when the task needs to be executed; execution data, that is, the data required when the task is executed, such as user ID, order number, etc.; execution conditions, that is, the conditions that trigger the execution of the task, such as a change in a certain state; priority, that is, the execution priority of the task, to determine which task is executed first when multiple tasks are waiting to be executed.

[0067] Furthermore, the device generates an execution strategy for the delayed task based on the task parameters. Specifically, the device generates an execution strategy based on the task parameters, which defines how the task is executed. The execution strategy includes but is not limited to: retry strategy, that is, if the task fails to execute, whether it needs to be retried, and the frequency and number of retries; execution order, that is, whether the task is executed immediately or queued; execution frequency, that is, for periodic tasks, how often it is executed; failure handling, that is, if the task fails to execute, how the system should handle it, such as retrying, logging, sending alarms, etc.; resource allocation, that is, the resources required for task execution, such as memory, CPU, etc.

[0068] In the specific implementation, once the task parameters and execution strategy are determined, the device will store this information in a preset relational database. The above process ensures that the delayed task can be executed correctly at the right time, and all execution information is recorded and managed. In this way, the system administrator can monitor the execution status of the task and promptly discover and deal with possible problems.

[0069] Step S200, if the task parameters meet the preset execution conditions, the corresponding delayed task is executed by the preset executor to obtain the task execution result;

[0070] It should be noted that each delayed task will have a set of task parameters when it is created. These parameters define the execution details of the task, such as the execution time, the data required for execution, etc. At the same time, the device will preset some execution conditions, which are the criteria for triggering the execution of the task. For example, the execution condition can be: when the current time reaches the scheduled execution time of the task.

[0071] In a specific implementation, if the task parameters meet the preset execution conditions, that is, once the parameters of the delayed task meet the execution conditions, the device will execute the delayed task through a preset executor. Among them, the executor is the component in the device responsible for executing the task. The executor can be a background service, a specific server, or a cloud function. Specifically, the executor will execute the task according to the instructions defined in the task parameters, such as sending emails, calling APIs, processing data, etc.

[0072] In the specific implementation, after the executor completes the task, it will return a task execution result, which can be success, failure, or any other feedback information of the task execution. The device will record this result for subsequent monitoring, logging, or triggering other operations based on the execution result.

[0073] In a specific implementation, the device executes the corresponding delayed task through a preset executor, and the step of obtaining the task execution result includes:

[0074] The configuration parameters of each executor in the preset executor set are obtained, and an allocation strategy is determined based on the task parameters and the configuration parameters; based on the allocation strategy, a corresponding target executor is selected from the executor set, and the delayed task is allocated to the corresponding target executor; the corresponding delayed task is executed by the target executor to obtain a task execution result.

[0075] It is understandable that in a distributed system, there are multiple executors (which may be different servers or service instances) available for assigning tasks. Each executor has its own configuration parameters, which define the capabilities of the executor, such as processing power, resource limits, supported task types, etc.

[0076] In the specific implementation, the device needs to determine an allocation strategy based on the task parameters (resources required for the task, priority, specific requirements, etc.) and the configuration parameters of the executor. The purpose of the allocation strategy is to select the most suitable executor to perform a specific task in order to optimize resource usage, reduce execution time, and improve task success rate. Specifically, the allocation strategy is determined based on multiple factors, such as the load of the executor, the urgency of the task, and the relevance of the executor's geographical location to the task.

[0077] Furthermore, the device selects the most suitable executor from all available executors to perform the task based on the determined allocation strategy. This process involves some algorithms, such as polling, random selection, weight-based selection, etc.

[0078] In a specific implementation, once the device selects the target executor, it will assign the delayed task to the executor. The specific process may be that the device registers the task on the executor, updates the task status to "to be executed", and records the task assignment information.

[0079] In the specific implementation, after receiving the task, the target executor will execute the task at the scheduled time. After the execution is completed, the executor will return the execution result of the task, which may be success, failure or other status information.

[0080] It is understandable that the above process ensures that delayed tasks can be efficiently and reasonably allocated and executed. Through intelligent allocation strategies, the device can maximize the utilization of actuators, reduce the delay of task execution, and improve overall performance. This mechanism is particularly important in distributed systems that need to process a large number of tasks, such as in cloud computing platforms, big data processing systems, or microservice architectures.

[0081] Step S300: If the task execution result is execution failure, the delayed task is processed based on the execution strategy to obtain a target processing result.

[0082] It should be noted that when a delayed task is assigned to an executor and executed, the task execution may fail due to various reasons (such as executor failure, insufficient resources, unavailability of the service on which the task depends, etc.). Therefore, if the task execution result is an execution failure, the device processes the delayed task based on the execution strategy to obtain the target processing result. Specifically, when a delayed task is created, an execution strategy is usually defined. This strategy includes processing rules when the task execution fails, where the execution strategy includes but is not limited to the number of retries, retry interval, failure notification, and operations after failure.

[0083] In a specific implementation, after the above processing, the device will obtain a target processing result, which includes: task success, that is, the task is successfully executed after retry; task failure, that is, the task still fails to execute after retry.

[0084] It is understandable that the above process ensures that even in the event of a task failure, the device can perform reasonable processing according to the predefined strategy to maximize the success rate of the task, reduce the impact of failure, and provide information for subsequent troubleshooting and system optimization.

[0085] In the specific implementation, refer to Figure 2This application divides the system into four modules: monitoring, executor, task storage and production, to achieve refined management of the task life cycle. Through modular design, the system is highly decoupled and maintainable.

[0086] Furthermore, the production module is not only responsible for task initialization and parameter definition, but also supports highly customized execution strategy configuration, such as custom execution time, number of retries and failure response strategy, which greatly enhances the flexibility and adaptability of task scheduling.

[0087] In the specific implementation, the monitoring module in the system continuously monitors with extremely low resource consumption, automatically captures qualified tasks, and seamlessly connects to the executor module to ensure the instant execution and status tracking of tasks, thereby improving the system response speed and stability.

[0088] In the specific implementation, this application uses MySQL as the task storage medium to ensure the persistent storage of task data, which is not affected by application restart. At the same time, this application also provides a real-time view of task execution to make up for the general lack of task progress monitoring and strategy adjustment functions in the market, that is, to provide users with an intuitive task queue view and execution status feedback, enhancing the transparency and controllability of operation and maintenance.

[0089] In a specific implementation, the device processes the delayed task based on the execution strategy to obtain the target processing result, including:

[0090] Based on the execution strategy, determine the execution interval time and the retry number threshold; after the execution interval time has passed, retry the delayed task to obtain a retry execution result; judge whether the retry execution result is an execution failure, if the retry execution result is an execution failure, determine the current retry number, and judge whether the current retry number exceeds the retry number threshold; if the current retry number does not exceed the retry number threshold, return to the step of retrying the delayed task after the execution interval time has passed to obtain a retry execution result, until the retry execution result is a successful execution or the current retry number exceeds the retry number threshold, then stop task processing and obtain the target processing result.

[0091] It should be noted that the device determines two key parameters based on the task execution strategy: the execution interval time and the retry threshold. The execution interval time refers to how long it takes to wait before trying to execute the task again after the task fails, and the retry threshold refers to how many consecutive failures the task will fail after which retrying will stop.

[0092] In the specific implementation, after the preset execution interval, the device will retry the delayed task for the first time. After the retry execution, the device will get a retry execution result. The device needs to determine whether the retry execution result is an execution failure. If the retry execution result is a success, the task processing is stopped and the success result is recorded; if the retry execution result is a failure, the next step is entered.

[0093] Furthermore, the device will record the current number of retries and determine whether this number exceeds the preset retry threshold. If the current number of retries does not exceed the threshold, the system will wait for the execution interval time again before retrying the task again. If the retry execution result continues to be execution failure, and the current number of retries does not exceed the threshold, the device will continue to repeat the above retry processing steps, and the above process will continue until the task is successfully executed or the number of retries reaches the threshold. If the task is successfully executed, the device will record the successful processing result and stop task processing. If the current number of retries exceeds the threshold, the system will stop task processing and record the final processing result.

[0094] It is understandable that the above process ensures that when the delayed task fails, it can be reasonably retried according to the preset strategy, and at the same time, infinite retries are avoided by setting the retry threshold, ensuring the stability of the device and the effective use of resources. This mechanism is particularly important when processing tasks that require high reliability, such as payment processing, data synchronization, notification sending and other key business processes.

[0095] In a specific implementation, if the current number of retries does not exceed the retry number threshold, returning to the step of retrying the delayed task after the execution interval time to obtain a retry execution result, until the retry execution result is a successful execution or the current number of retries exceeds the retry number threshold, the task processing is stopped, and the step of obtaining the target processing result includes:

[0096] If the current number of retries does not exceed the retry number threshold, the execution interval is increased based on the preset additional duration to obtain the increased execution interval; based on the increased execution interval, return to the step of retrying the delayed task after the execution interval to obtain the retry execution result, until the retry execution result is successful or the current number of retries exceeds the retry number threshold, then stop task processing to obtain the target processing result.

[0097] In the specific implementation, after the task execution fails, the device will check whether the current number of retries has exceeded the preset retry threshold. If the current number of retries does not exceed the threshold, the device will increase the execution interval according to the preset additional time rule. This part of the setting is to reduce the system burden and avoid resource waste caused by frequent retries. Specifically, the increase in execution interval time can be linear (a fixed time is added each time) or exponential (each increase is a multiple of the previous time), depending on the design of the strategy, which is not specifically limited here.

[0098] Understandably, this retry strategy of gradually increasing the interval helps to reduce the consumption of system resources while ensuring that the task can be executed in the end, and avoids system overload caused by frequent retries. This strategy is very effective when processing tasks that may be affected by temporary failures, such as network requests, database operations, and external service calls.

[0099] Furthermore, during the task execution, if a failure occurs, a retry mechanism is usually set up to improve the success rate of the task. Increasing the execution interval during each retry process can bring the following beneficial effects:

[0100] 1. Reduce resource competition: If a task fails and is retried immediately, it may increase resource competition, especially in a resource-limited environment. By increasing the execution interval, the immediate demand for resources can be reduced, thereby reducing resource competition.

[0101] 2. Avoid service overload: If a task fails because the dependent service or resource is temporarily unavailable or overloaded, retrying immediately may increase the burden on the service. Increasing the execution interval can give the service time to recover, thereby increasing the probability of a successful retry.

[0102] 3. Adaptive adjustment: In some cases, the execution time of a task may change due to external factors. By increasing the execution interval, the system can adapt to these changes, thereby improving the execution efficiency of the task.

[0103] Compared with the related art, which usually adopts the message queue method, that is, the system modules transmit messages and data through the message queue to realize the distributed delayed task processing. However, after the additional introduction of the message queue in this method, the corresponding maintenance and management mechanism needs to be added, which increases the complexity of the overall system, resulting in a high system complexity for executing distributed delayed tasks. In this application, the delayed tasks stored in the preset relational database are scanned at every preset first interval to obtain the task information of each delayed task, wherein the delayed task is pre-stored in the relational database, and the task information includes task parameters and execution strategy; if the task parameters meet the preset execution conditions, the corresponding delayed task is executed by the preset executor to obtain the task execution result; if the task execution result is an execution failure, the delayed task is processed based on the execution strategy to obtain the target processing result. It is understandable that the application proposes to set up a relational database with delayed task information, and realize the processing of delayed tasks by polling the relational database and processing the delayed task by the executor. Among them, the implementation method of database polling does not need to introduce complex middleware, thereby reducing the system complexity of executing distributed delayed tasks. Furthermore, after the task execution fails, the application further processes the delayed task according to the execution strategy pre-stored in the relational database, thereby enhancing the flexibility of task execution.

[0104] Based on the above first embodiment, the present application also proposes another embodiment, referring to Figure 3 , the execution method of the delayed task includes:

[0105] In a specific implementation, after the step of processing the delayed task based on the execution strategy to obtain the target processing result if the task execution result is an execution failure, the method includes:

[0106] Step A100, classifying each delayed task processing information by value to obtain delayed task processing information of different values, wherein delayed task processing information of high value has a long life cycle;

[0107] In a specific implementation, the present application also proposes to classify the delayed task processing information by value, store the information in resource pools of different life cycles according to its value, and clean up the resource pools regularly.

[0108] In a specific implementation, the device first performs a value assessment on all delayed task processing information to determine the importance or value of each piece of information, where the value assessment may be based on a variety of factors, such as the urgency of the task, the impact of the task on the business, the execution results of the task, etc. The device classifies this information into categories with different value levels based on the results of the value assessment, where delayed task processing information with high value may need to be retained for a longer period of time for future reference or analysis.

[0109] Step A200, storing the delayed task processing information with higher value into a resource pool with a longer coverage period, and storing the delayed task processing information with lower value into a resource pool with a shorter coverage period;

[0110] In the specific implementation, the device will store the task processing information in different resource pools according to its value level. Information with higher value will be stored in a resource pool with a longer coverage period, which means that the information will be retained for a longer time. On the contrary, information with lower value will be stored in a resource pool with a shorter coverage period, and the information may be deleted in a shorter time.

[0111] Step A300: Deleting delayed task processing information that meets a deletion condition in the resource pool at every preset second interval time to obtain a deleted resource pool.

[0112] In a specific implementation, the device will periodically (at a preset second interval) check the delayed task processing information in the resource pool. Specifically, the device will determine which information needs to be deleted based on preset deletion conditions. These conditions may include the storage time of the information, the value level of the information, the relevance of the information, etc. The information that meets the deletion conditions will be deleted from the resource pool to free up storage space and maintain the efficiency and performance of the resource pool.

[0113] It is understandable that the purpose of the above process is to optimize resource usage, ensuring that important task processing information is retained for a long time, while less important information is cleared after a certain period of time to avoid wasting resources. This method is very useful when processing data such as log data, historical records, temporary files, etc. that need to be cleared regularly. In this way, the device can maintain efficient operation while ensuring the security and accessibility of critical data.

[0114] It should be noted that the above examples are only used to understand the present application and do not constitute a limitation on the execution method of the delayed task of the present application. More simple transformations based on this technical concept are all within the scope of protection of the present application.

[0115] This application also provides a delayed task execution device, please refer to Figure 4 , the execution device of the delayed task includes:

[0116] The scanning module 10 is used to scan the delayed tasks stored in the preset relational database at every preset first interval time to obtain task information of each delayed task, wherein the delayed tasks are pre-stored in the relational database, and the task information includes task parameters and execution strategies;

[0117] An execution module 20 is used to execute the corresponding delayed task through a preset executor to obtain a task execution result if the task parameters meet the preset execution conditions;

[0118] The processing module 30 is used to process the delayed task based on the execution strategy to obtain a target processing result if the task execution result is execution failure.

[0119] Optionally, the processing module 30 includes:

[0120] A retry module, used to retry the delayed task after the execution interval has passed, and obtain a retry execution result;

[0121] A judgment module, used to judge whether the retry execution result is an execution failure, and if the retry execution result is an execution failure, determine the current retry number, and judge whether the current retry number exceeds the retry number threshold;

[0122] The iterative processing module is used to return to the step of retrying the delayed task after the execution interval time to obtain the retry execution result if the current retry number does not exceed the retry number threshold, and stop task processing to obtain the target processing result until the retry execution result is successful or the current retry number exceeds the retry number threshold.

[0123] Optionally, the iterative processing module includes:

[0124] An increasing module, for increasing the execution interval time based on a preset additional time length if the current number of retries does not exceed the retry number threshold, to obtain the execution interval time after the time length has been increased;

[0125] The iterative task execution module is used to return to the step of retrying the delayed task after the execution interval time has passed based on the increased execution interval time, and obtain the retry execution result, until the retry execution result is successful execution or the current retry number exceeds the retry number threshold to stop task processing and obtain the target processing result.

[0126] Optionally, the execution module 20 includes:

[0127] An acquisition module, used to acquire configuration parameters of each executor in a preset executor set, and determine an allocation strategy based on the task parameters and the configuration parameters;

[0128] A selection module, configured to select a corresponding target executor from the executor set based on the allocation strategy, and allocate the delayed task to the corresponding target executor;

[0129] The delayed task execution module is used to execute the corresponding delayed task through the target executor to obtain the task execution result.

[0130] Optionally, the execution device of the delayed task further includes:

[0131] A determination module, used for determining the task parameters of the delayed task after generating the delayed task;

[0132] A generation module, used for generating an execution strategy of the delayed task based on the task parameters;

[0133] The storage module is used to store the delayed tasks with the execution strategy in a preset relational database.

[0134] Optionally, the execution device of the delayed task further includes:

[0135] A classification module, used for classifying each delayed task processing information by value to obtain delayed task processing information of different values, wherein delayed task processing information of high value has a long life cycle;

[0136] A resource storage module, used to store the delayed task processing information of higher value into a resource pool with a longer coverage period, and store the delayed task processing information of lower value into a resource pool with a shorter coverage period;

[0137] The deleting module is used to delete the delayed task processing information that meets the deletion condition in the resource pool at every preset second interval time to obtain the deleted resource pool.

[0138] The execution device of the delayed task provided by the present application adopts the execution method of the delayed task in the above embodiment, which can solve the technical problem of the execution of the delayed task. Compared with the prior art, the beneficial effects of the execution device of the delayed task provided by the present application are the same as the beneficial effects of the execution method of the delayed task provided by the above embodiment, and the other technical features in the execution device of the delayed task are the same as the features disclosed in the above embodiment method, which will not be repeated here.

[0139] The present application provides a delayed task execution device, the delayed task execution device includes: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the delayed task execution method in the above-mentioned embodiment one.

[0140] Reference below Figure 5 , which shows a schematic diagram of the structure of an execution device suitable for implementing the delayed task of the embodiment of the present application. The execution device of the delayed task in the embodiment of the present application may include but is not limited to mobile terminals such as mobile phones, laptops, digital broadcast receivers, PDAs (Personal Digital Assistants), PADs (Portable Application Descriptions), PMPs (Portable Media Players), vehicle-mounted terminals (such as vehicle-mounted navigation terminals), etc., and fixed terminals such as digital TVs, desktop computers, etc. Figure 5 The execution device of the delayed task shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present application.

[0141] like Figure 5As shown, the execution device of the delayed task may include a processing device 1001 (such as a central processing unit, a graphics processor, etc.), which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM: Read Only Memory) 1002 or a program loaded from a storage device 1003 to a random access memory (RAM: Random Access Memory) 1004. In RAM1004, various programs and data required for the operation of the execution device of the delayed task are also stored. The processing device 1001, ROM1002 and RAM1004 are connected to each other through a bus 1005. An input / output (I / O) interface 1006 is also connected to the bus. Typically, the following systems can be connected to the I / O interface 1006: input devices 1007 including, for example, a touch screen, a touchpad, a keyboard, a mouse, an image sensor, a microphone, an accelerometer, a gyroscope, etc.; output devices 1008 including, for example, a liquid crystal display (LCD), a speaker, a vibrator, etc.; storage devices 1003 including, for example, a magnetic tape, a hard disk, etc.; and communication devices 1009. The communication device 1009 can allow the execution device of the delayed task to communicate with other devices wirelessly or by wire to exchange data. Although the figure shows the execution device of the delayed task with various systems, it should be understood that it is not required to implement or have all the systems shown. More or fewer systems may be implemented or have instead.

[0142] In particular, according to the embodiments disclosed in the present application, the process described above with reference to the flowchart can be implemented as a computer software program. For example, the embodiments disclosed in the present application include a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program includes a program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from a network through a communication device, or installed from a storage device 1003, or installed from a ROM 1002. When the computer program is executed by the processing device 1001, the above-mentioned functions defined in the method of the embodiment disclosed in the present application are executed.

[0143] The execution device of the delayed task provided by the present application adopts the execution method of the delayed task in the above embodiment, which can solve the technical problem of the execution of the delayed task. Compared with the prior art, the beneficial effects of the execution device of the delayed task provided by the present application are the same as the beneficial effects of the execution method of the delayed task provided by the above embodiment, and the other technical features in the execution device of the delayed task are the same as the features disclosed in the method of the previous embodiment, which will not be repeated here.

[0144] It should be understood that the various parts disclosed in this application can be implemented by hardware, software, firmware or a combination thereof. In the description of the above embodiments, specific features, structures, materials or characteristics can be combined in any one or more embodiments or examples in a suitable manner.

[0145] The above is only a specific implementation of the present application, but the protection scope of the present application is not limited thereto. Any person skilled in the art who is familiar with the present technical field can easily think of changes or substitutions within the technical scope disclosed in the present application, which should be included in the protection scope of the present application. Therefore, the protection scope of the present application should be based on the protection scope of the claims.

[0146] The present application provides a computer-readable storage medium having computer-readable program instructions (ie, computer programs) stored thereon, and the computer-readable program instructions are used to execute the execution method of the delayed task in the above-mentioned embodiment.

[0147] The computer-readable storage medium provided in the present application may be, for example, a USB flash drive, but is not limited to electrical, magnetic, optical, electromagnetic, infrared, or semiconductor systems, systems or devices, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In this embodiment, the computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in combination with an instruction execution system, system or device. The program code contained on the computer-readable storage medium may be transmitted using any appropriate medium, including but not limited to: wires, optical cables, RF (Radio Frequency), etc., or any suitable combination of the above.

[0148] The computer-readable storage medium may be included in the delayed task execution device; or may exist independently without being assembled into the delayed task execution device.

[0149] The computer-readable storage medium carries one or more programs. When the one or more programs are executed by the delayed task execution device, the delayed task execution device performs the delayed task execution.

[0150] Computer program code for performing the operations of the present application may be written in one or more programming languages ​​or a combination thereof, including object-oriented programming languages ​​such as Java, Smalltalk, C++, and conventional procedural programming languages ​​such as "C" or similar programming languages. The program code may be executed entirely on the user's computer, partially on the user's computer, as a separate software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., via the Internet using an Internet service provider).

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

[0152] The modules involved in the embodiments described in this application may be implemented by software or hardware, wherein the name of the module does not constitute a limitation on the unit itself in some cases.

[0153] The readable storage medium provided by the present application is a computer-readable storage medium, which stores computer-readable program instructions (i.e., computer programs) for executing the above-mentioned delayed task execution method, and can solve the technical problem of delayed task execution. Compared with the prior art, the beneficial effects of the computer-readable storage medium provided by the present application are the same as the beneficial effects of the delayed task execution method provided by the above-mentioned embodiment, and will not be repeated here.

[0154] The present application also provides a computer program product, including a computer program, which implements the steps of the above-mentioned delayed task execution method when executed by a processor.

[0155] The computer program product provided by this application can solve the technical problem of delay task execution. Compared with the prior art, the beneficial effects of the computer program product provided by this application are the same as the beneficial effects of the delay task execution method provided by the above embodiment, which will not be repeated here.

[0156] The above descriptions are only some embodiments of the present application, and are not intended to limit the patent scope of the present application. All equivalent structural changes made using the contents of the present application specification and drawings under the technical concept of the present application, or direct / indirect applications in other related technical fields are included in the patent protection scope of the present application.

Claims

1. A method for executing a delayed task, characterized in that: The method for executing the delayed task includes: Scanning the delayed tasks stored in a preset relational database at every preset first interval to obtain task information of each delayed task, wherein the delayed tasks are pre-stored in the relational database, and the task information includes task parameters and execution strategies; If the task parameters meet the preset execution conditions, the corresponding delayed task is executed by the preset executor to obtain the task execution result; If the task execution result is execution failure, the delayed task is processed based on the execution strategy to obtain a target processing result.

2. The method for executing a delayed task as claimed in claim 1, characterized in that: The step of processing the delayed task based on the execution strategy to obtain a target processing result includes: Based on the execution strategy, determine the execution interval time and retry number threshold; After the execution interval time has passed, retrying the delayed task to obtain a retry execution result; Determine whether the retry execution result is an execution failure, if the retry execution result is an execution failure, determine the current retry number, and determine whether the current retry number exceeds the retry number threshold; If the current number of retries does not exceed the retry number threshold, then return to the step of retrying the delayed task after the execution interval time to obtain the retry execution result, until the retry execution result is successful or the current number of retries exceeds the retry number threshold, then stop task processing and obtain the target processing result.

3. The method for executing a delayed task as claimed in claim 2, characterized in that: If the current number of retries does not exceed the retry number threshold, returning to the step of retrying the delayed task after the execution interval to obtain a retry execution result, until the retry execution result is a successful execution or the current number of retries exceeds the retry number threshold, the task processing is stopped, and the step of obtaining the target processing result includes: If the current number of retries does not exceed the retry number threshold, then based on the preset additional duration, the execution interval is increased to obtain the increased execution interval; Based on the increased execution interval time, return to the step of retrying the delayed task after the execution interval time has passed to obtain the retry execution result, and stop task processing until the retry execution result is successful or the current retry number exceeds the retry number threshold to obtain the target processing result.

4. The method for executing a delayed task as claimed in claim 1, characterized in that: The step of executing the corresponding delayed task by a preset executor to obtain the task execution result includes: Obtaining configuration parameters of each executor in a preset executor set, and determining an allocation strategy based on the task parameters and the configuration parameters; Based on the allocation strategy, a corresponding target executor is selected from the executor set, and the delayed task is allocated to the corresponding target executor; The corresponding delayed task is executed by the target executor to obtain the task execution result.

5. The method for executing a delayed task as claimed in claim 1, characterized in that: Before the step of scanning the delayed tasks in the preset relational database at every preset first interval to obtain the task information of each delayed task, the method includes: After generating the delayed task, determining the task parameters of the delayed task; Based on the task parameters, generating an execution strategy for the delayed task; The delayed tasks with the execution strategy are stored in a preset relational database.

6. The method for executing a delayed task according to any one of claims 1 to 5, characterized in that: The target processing result includes delayed task processing information. If the task execution result is execution failure, the delayed task is processed based on the execution strategy to obtain the target processing result. The method includes: Classifying each of the delayed task processing information by value to obtain delayed task processing information of different values, wherein delayed task processing information of high value has a long life cycle; The delayed task processing information with higher value is stored in the resource pool with longer coverage period, and the delayed task processing information with lower value is stored in the resource pool with shorter coverage period; At every preset second interval time, the delayed task processing information that meets the deletion condition in the resource pool is deleted to obtain a deleted resource pool.

7. A device for executing a delayed task, characterized in that: The device comprises: A scanning module, used for scanning the delayed tasks stored in a preset relational database at every preset first interval time to obtain task information of each delayed task, wherein the delayed tasks are pre-stored in the relational database, and the task information includes task parameters and execution strategies; An execution module, used for executing the corresponding delayed task through a preset executor to obtain a task execution result if the task parameters meet the preset execution conditions; The processing module is used to process the delayed task based on the execution strategy to obtain a target processing result if the task execution result is execution failure.

8. A delayed task execution device, characterized in that: The device comprises: a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the computer program is configured to implement the steps of the method for executing a delayed task as claimed in any one of claims 1 to 6.

9. A storage medium, characterized in that: The storage medium is a computer-readable storage medium, and a computer program is stored on the storage medium. When the computer program is executed by a processor, the steps of the method for executing a delayed task as described in any one of claims 1 to 6 are implemented.

10. A computer program product, characterized in that The computer program product comprises a computer program, and when the computer program is executed by a processor, the steps of the method for executing a delayed task as claimed in any one of claims 1 to 6 are implemented.

Citation Information

Patent Citations

  • Delay task execution method and device and electronic device

    CN110032438A

  • Delay task processing method and device, storage medium and electronic equipment

    CN110413384A

  • Task failure retry method and device, computer equipment and storage medium

    CN110968410A

  • Task processing method and device, computer equipment and storage medium

    CN115543565A

  • Synchronous-to-asynchronous task processing method and device, equipment, medium and product

    CN117873682A