Scheduling method and device for timed tasks in service system, equipment and medium
By creating multi-time-level task queues in the business system and storing timing tasks according to first-level time parameters, the problem of limited performance of the traditional scheduling framework is solved, and precise scheduling and efficient execution of timing tasks is achieved.
Patent Information
- Application Number
- CN202411716741.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-27
- Publication Date
- 2025-04-15
AI Technical Summary
The traditional timing task scheduling framework has limited performance due to the low concurrent reading and writing performance of the database, making it difficult to achieve accurate and efficient timing task scheduling.
By creating a task queue containing multiple time levels, multiple timing tasks and task processing times in the business system are obtained, and timing tasks are stored into the task queue according to the first-level time parameters. When the current time of the system is consistent with the task processing time of the target timing task, the target timing tasks are scheduled and executed.
It realizes task queues that directly persist timing tasks to multiple time levels, quickly locate target timing tasks, ensure accurate scheduling of timing tasks in the business system, and improves system performance and efficiency.
Smart Images

Figure CN119829230A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of task scheduling, and in particular to a scheduling method, device, equipment and medium for timing tasks in a business system. Background Art
[0002] Scheduled tasks refer to the automatic execution of specific tasks at a predetermined time point or time interval. Scheduled task applications are mainly based on the needs of automated operations, planned operations, periodic tasks, and improving system efficiency. They reduce the burden of manual intervention, ensure that the system performs specific operations at critical moments, and maintain system stability and availability. Scheduled tasks are also used for asynchronous processing, resource optimization, and task scheduling. They play an important role in distributed systems, improve system efficiency, and reduce the need for manual operations, thereby making the system run more stably and reliably.
[0003] The scheduling framework in the related technology creates scheduled tasks by directly persisting the task data of the scheduled tasks in the database, and does not retrieve and execute the scheduling until the scheduled task reaches the trigger time. However, databases generally have the problem of low concurrent read and write performance, which leads to limited performance of traditional scheduling frameworks. Summary of the invention
[0004] In view of the above problems, a method, apparatus, device and medium for scheduling timed tasks in a business system is proposed to overcome the above problems or at least partially solve the above problems, including:
[0005] A method for scheduling a scheduled task in a business system, characterized in that the method comprises:
[0006] Create a task queue with multiple time levels;
[0007] Acquire multiple scheduled tasks in the business system and task processing time of the scheduled tasks, wherein the task processing time includes a primary time parameter;
[0008] Storing the plurality of scheduled tasks in the task queue according to the first-level time parameters;
[0009] Obtain one or more target scheduled tasks that are ranked first in the task queue, the task processing time of the target scheduled tasks, and the current system time of the business system;
[0010] When the current time of the system is consistent with the task processing time of the target scheduled task, the target scheduled task is scheduled and executed.
[0011] In some optional embodiments of the present application, the task processing time further includes a plurality of secondary time parameters, and when the current time of the system is consistent with the task processing time of the target scheduled task, before scheduling and executing the target scheduled task, the following steps are included:
[0012] Extracting the system primary time corresponding to the primary time parameter and the system secondary time corresponding to the secondary time parameter from the current system time of the business system;
[0013] Comparing the first-level time parameter with the first-level time of the system to obtain a first comparison result;
[0014] Comparing each of the secondary time parameters with the system secondary time respectively to obtain a plurality of second comparison results;
[0015] According to the first comparison result and the plurality of second comparison results, it is determined whether the current time of the system is consistent with the task processing time of the target scheduled task.
[0016] In some optional embodiments of the present application, determining whether the current time of the system is consistent with the task processing time of the target scheduled task according to the first comparison result and the plurality of second comparison results includes:
[0017] When the first comparison result indicates that the results are consistent, and when each of the second comparison results indicates that the results are consistent, it is determined that the current time of the system is consistent with the task processing time of the target scheduled task.
[0018] In some optional embodiments of the present application, the levels of the multiple secondary time parameters are different, and determining whether the current time of the system is consistent with the task processing time of the target scheduled task based on the first comparison result and the multiple second comparison results includes:
[0019] When the first comparison result characterization results are consistent and at least one of the second comparison result characterization results is inconsistent, it is determined that the current time of the system is inconsistent with the task processing time of the target scheduled task.
[0020] In some optional embodiments of the present application, after determining that the current time of the system is inconsistent with the task processing time of the target scheduled task, the process includes:
[0021] Deleting the target scheduled task from the task queue, and determining the highest-level target secondary time parameter from the multiple secondary time parameters;
[0022] According to the target secondary time parameter, the target scheduled task is stored in a task queue corresponding to the target secondary time parameter.
[0023] In some optional embodiments of the present application, the task queue containing multiple time levels includes a second-level task queue, a minute-level task queue, an hour-level task queue, a day-level task queue and a month-level task queue.
[0024] In some optional embodiments of the present application, storing the plurality of scheduled tasks in the task queue according to the primary time parameter includes:
[0025] Determine a time type of the first-level time parameter, where the time type is one of a month-level time type, a day-level time type, an hour-level time type, a minute-level time type, and a second-level time type;
[0026] If the time type is a monthly time type, the scheduled task is stored in the position corresponding to the monthly time in the monthly task queue;
[0027] If the time type is a day-level time type, the scheduled task is stored in the day-level task queue at a position corresponding to the day-level time;
[0028] If the time type is an hourly time type, the scheduled task is stored in the hourly task queue at a position corresponding to the hourly time;
[0029] If the time type is a minute-level time type, the scheduled task is stored in the minute-level task queue at a position corresponding to the minute-level time;
[0030] If the time type is a second-level time type, the scheduled task is stored in a second-level task queue at a position corresponding to the second-level time.
[0031] A scheduling device for a scheduled task in a business system, the device comprising:
[0032] A queue creation module is configured to create a task queue containing multiple time levels;
[0033] A task acquisition module is configured to acquire a plurality of scheduled tasks in the business system and task processing time of the scheduled tasks, wherein the task processing time includes a primary time parameter;
[0034] A task storage module is configured to store the plurality of scheduled tasks into the task queue according to the first-level time parameter;
[0035] A time acquisition module is configured to acquire one or more target scheduled tasks ranked first in the task queue, the task processing time of the target scheduled tasks, and the current system time of the business system;
[0036] The task scheduling module is configured to schedule and execute the target scheduled task when the current time of the system is consistent with the task processing time of the target scheduled task.
[0037] An electronic device comprises a processor, a memory and a computer program stored in the memory and capable of running on the processor, wherein the computer program implements the data processing method as described above when executed by the processor.
[0038] A computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the data processing method described above is implemented.
[0039] The embodiments of the present invention have the following advantages:
[0040] By creating a task queue containing multiple time levels, multiple scheduled tasks in the business system and the task processing time of the scheduled tasks are obtained. The task processing time includes the first-level time parameters. Multiple scheduled tasks are stored in the task queue according to the first-level time parameters. The top one or more target scheduled tasks in the task queue, the task processing time of the target scheduled task, and the current system time of the business system are obtained. When the current system time is consistent with the task processing time of the target scheduled task, the target scheduled task is scheduled and executed. It realizes the direct persistence of multiple scheduled tasks in the business system to task queues with multiple time levels, and on this basis, the target scheduled task is quickly located to ensure the accurate scheduling of scheduled tasks in the business system. BRIEF DESCRIPTION OF THE DRAWINGS
[0041] In order to more clearly illustrate the technical solution of the present invention, the accompanying drawings required for use in the description of the present invention will be briefly introduced below. Obviously, the accompanying drawings in the following description are only some embodiments of the present invention. For ordinary technicians in this field, other accompanying drawings can be obtained based on these accompanying drawings without paying creative labor.
[0042] Figure 1 This is a flowchart of a method for scheduling scheduled tasks in a business system provided by an embodiment of the present application;
[0043] Figure 2 This is a schematic diagram of the Kafka time wheel scheduling framework provided by some embodiments of the present application;
[0044] Figure 3 is a schematic diagram of a timing wheel provided in some embodiments of the present application;
[0045] Figure 4 is a flowchart of the steps of another method for scheduling a scheduled task in a business system provided by some embodiments of the present application;
[0046] Figure 5 This is the main process of implementing scheduled tasks based on the Kafka time wheel provided by some embodiments of the present application;
[0047] Figure 6 It is a structural diagram of a scheduling device for scheduled tasks in a business system provided in some embodiments of the present application. DETAILED DESCRIPTION
[0048] In order to make the above-mentioned purposes, features and advantages of the present invention more obvious and easy to understand, the present invention is further described in detail below in conjunction with the accompanying drawings and specific embodiments. Obviously, the described embodiments are part of the embodiments of the present invention, rather than all the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0049] Reference Figure 1 , shows a flowchart of a method for scheduling a scheduled task in a business system provided by an embodiment of the present invention, which may specifically include the following steps:
[0050] Step 101: Create a task queue containing multiple time levels.
[0051] Among them, the business system refers to a computer system used to support specific business processes. The business system usually includes multiple modules and functions for processing business data, executing business logic, generating reports, etc. Business systems include but are not limited to Enterprise Resource Planning (ERP) systems, Customer Relationship Management (CRM) systems, supply chain management systems, etc. Scheduled tasks refer to tasks that are automatically executed at specific time points or time intervals. Scheduled tasks are usually used to perform periodic operations. In business systems, scheduled tasks are used to perform business logic such as data backup, log cleaning, and report generation. Task queues are a data structure used to store and manage tasks to be executed. Task queues can be used in a variety of scenarios such as asynchronous processing, task scheduling, and delayed tasks. Time levels refer to different time intervals or time ranges contained in task queues. Each time level represents a specific time period. The time level can help the system manage tasks with different delay times more efficiently.
[0052] In some implementations of the present embodiment, the task queues of multiple time levels can be specifically a hierarchical Kafka timing wheel (Timing Wheel) structure, and the hierarchical Kafka timing wheel is composed of multiple timing wheels, and each timing wheel represents a different time level. Specifically, the bottom timing wheel can represent a second-level task, the upper layer of the timing wheel represents a minute-level task, and the upper layer represents an hour-level task, and so on. The level of the timing wheel can be adjusted according to business needs. Each slot in the timing wheel represents a time interval, and the pointer of the timing wheel moves over time to point to the current time slot. When the pointer moves to a new slot, it triggers the execution of all scheduled tasks in the slot. The hierarchical structure of the present application can effectively handle massive timing tasks and has low time complexity.
[0053] Step 102: Acquire multiple scheduled tasks in the business system and task processing time of the scheduled tasks, where the task processing time includes a primary time parameter.
[0054] Among them, the task processing time refers to the time when the scheduled task starts to execute. The first-level time parameter refers to the highest-level time in the scheduled task processing time, and the highest-level time refers to the time with the largest time range. For example, at a certain moment, the business system applies to create three scheduled tasks task1, task2, and task3, and hopes that these three tasks will be triggered after one second, one hour, one minute and five seconds, and one month respectively. Then the task processing time of the three scheduled tasks is "one second", "one hour, one minute and five seconds", and "one month and one hour", and the first-level time parameters of the three scheduled tasks are "one second", "one hour", and "one month" respectively.
[0055] Step 103: storing the plurality of scheduled tasks in the task queue according to the first-level time parameter;
[0056] After creating a multi-time-level task queue and a business system creating multiple scheduled tasks, each scheduled task can be stored in the task queue according to the first-level time parameter of each scheduled task.
[0057] In the specific implementation of this embodiment, the three scheduled tasks are stored according to their primary time parameters "one second", "one hour" and "one month". Figure 2 The figure shows a schematic diagram of the Kafka time wheel scheduling framework provided in some embodiments of the present application, in which the business system creates tasks and persists them in the Kafka time wheel framework, and the Kafka time wheel schedules tasks.
[0058] Step 104: obtaining one or more target scheduled tasks that are ranked first in the task queue, the task processing time of the target scheduled tasks, and the current system time of the business system;
[0059] The target scheduled task refers to the business system scheduled task that ranks first in the task queue, which can be one or more.
[0060] In order to execute the scheduled tasks stored in the task queue, it is necessary to obtain the target scheduled tasks and their task processing times that are ranked first in the multi-level Kafka time wheel. If the business system applies to create 10 scheduled tasks, and the task processing times of the 10 scheduled tasks are all "first second", then when they are stored in the task queue, the 10 scheduled tasks are all stored in the position corresponding to the first second. Then the target scheduled tasks ranked first are these 10 scheduled tasks, and the task processing times of the 10 scheduled tasks are all "first second". Figure 3 As shown, it is a schematic diagram of the time wheel provided in some embodiments of the present application, and the 10 scheduled tasks in the above example can be stored as a task list at the position where scale 1 is located. In addition, it is also necessary to obtain the current system time of the business system, that is, the scale to which the time wheel rotates. When the time wheel rotates to the first second, it means that the current time of the business system is one second.
[0061] Step 105: When the current system time is consistent with the task processing time of the target scheduled task, the target scheduled task is scheduled and executed.
[0062] When the time scale that the time wheel rotates to coincides with the task processing time of the scheduled task, it means that the target scheduled task needs to be triggered. For example, the task processing time of the top scheduled task is "the first second", or the task processing time of the top 10 scheduled tasks is "the first second". Then when the time wheel rotates to the one-second scale, the task processing time of the target scheduled task task1 is exactly the same as the current system time. At this time, task1 is read from the message queue and task1 is executed; or the 10 stored scheduled tasks are read from the message queue and these 10 scheduled tasks are executed.
[0063] The above-mentioned embodiment of the present application creates a task queue including multiple time levels, obtains multiple scheduled tasks in the business system and the task processing time of the scheduled tasks, the task processing time includes a first-level time parameter, stores multiple scheduled tasks in the task queue according to the first-level time parameter, obtains one or more target scheduled tasks ranked at the top in the task queue, the task processing time of the target scheduled task, and the system current time of the business system, and when the system current time is consistent with the task processing time of the target scheduled task, schedules and executes the target scheduled task. It realizes the direct persistence of multiple scheduled tasks in the business system to task queues of multiple time levels, and on this basis quickly locates the target scheduled task, ensuring the accurate scheduling of scheduled tasks in the business system.
[0064] Reference Figure 4 , shows a flowchart of the steps of another method for scheduling a scheduled task in a business system provided by some embodiments of the present application, which may specifically include the following steps:
[0065] Step 401: Create a task queue containing multiple time levels;
[0066] Step 402: Acquire multiple scheduled tasks in the business system and task processing time of the scheduled tasks, where the task processing time includes a first-level time parameter;
[0067] Step 403: storing multiple scheduled tasks in a task queue according to the first-level time parameters;
[0068] Step 404: Obtain one or more target scheduled tasks that are ranked first in the task queue, the task processing time of the target scheduled tasks, and the current system time of the business system.
[0069] The process from step 401 to step 404 is the same as the process from step 101 to step 104 and will not be described again here.
[0070] In some embodiments of the present application, the task queue containing multiple time levels includes a second-level task queue, a minute-level task queue, an hour-level task queue, a day-level task queue, and a month-level task queue.
[0071] In the present application, multiple time wheel levels are used to manage timed tasks with different time spans. The time wheel of each level contains a fixed number of buckets, and each slot represents a time interval. After the pointer of the time wheel of the highest level rotates a circle, the task is further passed to the time wheel of the lower level for fine management. Through this hierarchical structure, the hierarchical time wheel can efficiently manage timed tasks from short time to long time span. Through hierarchical management, the present application reduces the number of slots of each time wheel level, thereby reducing memory consumption. In addition, through the hierarchical structure, the hierarchical time wheel can efficiently manage tasks from short time to long time span, avoiding the efficiency problem of single-level time wheel in long time span task management.
[0072] In the specific implementation, multiple time-level task queues are created, including second-level task queues, minute-level task queues, hour-level task queues, daily-level task queues, and monthly-level task queues. The storage data structure is shown in Table 1. 187 message queues are created, including 12 monthly-level, 31 daily-level, 24 hour-level, 60 minute-level, and 60 second-level queues, corresponding to each time level and each time scale in each time level. The hierarchical time wheel can adjust the time interval and number of slots of each level according to the specific application scenario. For example, according to actual business needs, millisecond-level task queues and microsecond-level task queues can be set to meet different task management needs. Each time scale of each time level corresponds to a Topic. In the initial state of the system, there is no scheduled task, and the data of each Topic is empty.
[0073] Topic is a logical unit used to classify and store messages in Kafka. Each Topic can be seen as a container for messages. Producers can publish messages to a specific Topic, and consumers can subscribe to and consume messages from a specific Topic. Multiple producers can publish messages to the same Topic, and multiple consumers can subscribe to the same Topic and consume messages. After being published to a Topic, messages will be persistently stored until the specified retention time or storage space limit is reached.
[0074] Table 1
[0075] Time level Time scale topic Current storage data Second First second s_1 [] ... ... ... ... Second Sixtieth second s_60 [] point First point m_1 [] ... ... ... ... point Sixtieth m_60 [] hour First Time h_1 [] ... ... ... ... hour 24th hour m_24 [] sky Day 1 d_1 [] ... ... ... ... sky Day 31 d_31 [] moon Month 1 M_1 [] ... ... ... ... moon December M_12 []
[0076] In some embodiments of the present application, step 403 may include the following sub-steps:
[0077] Sub-step 11: determining the time type of the first-level time parameter, where the time type is one of a month-level time type, a day-level time type, an hour-level time type, a minute-level time type, and a second-level time type;
[0078] Sub-step 12: If the time type is a monthly time type, storing the scheduled task in a position corresponding to the monthly time in the monthly task queue;
[0079] Sub-step 13: If the time type is a day-level time type, store the scheduled task in a position corresponding to the day-level time in the day-level task queue;
[0080] Sub-step 14: If the time type is an hourly time type, storing the scheduled task in a position corresponding to the hourly time in the hourly task queue;
[0081] Sub-step 15: If the time type is a minute-level time type, store the scheduled task in a position corresponding to the minute-level time in the minute-level task queue;
[0082] Sub-step 16: If the time type is a second-level time type, store the scheduled task in a second-level task queue at a position corresponding to the second-level time.
[0083] Continuing with the above example, the business system applies for three scheduled tasks, task1, task2, and task3. The task processing times of the three scheduled tasks are "one second", "one hour, one minute and five seconds", and "one month and one hour", respectively. First, determine that the first-level time parameters of the three scheduled tasks are "one second", "one hour", and "one month", that is, the time types corresponding to the first-level time parameters of the three scheduled tasks are "second", "hour", and "month", respectively. When the time type is "month", the scheduled task is stored in the position corresponding to the monthly time "one month" in the monthly task queue, that is, "the first month", and so on.
[0084] Table 2
[0085] Time level Time scale topic Current storage data Second First second s_1 [task1] ... ... ... ... Second Sixtieth second s_60 [] point First point m_1 [] ... ... ... ... point Sixtieth m_60 [] hour First Time h_1 [task2] ... ... ... ... hour 24th hour m_24 [] sky Day 1 d_1 [] ... ... ... ... sky Day 31 d_31 [] moon Month 1 M_1 [task3] ... ... ... ... moon December M_12 []
[0086] The embodiment of the present application stores task1 in the entry with a time scale of the first second, stores task2 in the entry with a time scale of the first hour, and stores task3 in the entry with a time scale of the first month. As shown in Table 2, these three scheduled tasks are persisted in the task queue.
[0087] Step 405: extracting the system primary time corresponding to the primary time parameter and the system secondary time corresponding to the secondary time parameter from the system current time of the business system;
[0088] In some embodiments of the present application, the task processing time also includes multiple secondary time parameters, such as the task processing time of task2 in the above example is "one hour, one minute and five seconds", where "one hour" with the largest time range is the primary time parameter, and "one minute" and "five seconds" are multiple secondary time parameters corresponding to task2. The current time of the system is also the scale to which the time wheel rotates. Assuming that the scale to which the time wheel rotates is "one hour, 0 minutes and 5 seconds", the system primary time corresponding to the primary time parameter of the target scheduled task is "one hour", and the system secondary time corresponding to the secondary time parameter of the target scheduled task is "0 minutes" and "5 seconds". If there is a task 4 whose task processing time is "one month, one hour, four minutes and three seconds", the primary time parameter corresponding to task4 is "one month", and the corresponding secondary time parameters are four, namely "0 days", "one hour", "four minutes" and "3 seconds". Assuming that the scale to which the time wheel rotates is "twenty days, three hours and five seconds", the system primary time is "0 months", and multiple system secondary times are "twenty days", "three hours", "0 minutes" and "5 seconds".
[0089] Step 406: Compare the first-level time parameter with the system first-level time to obtain a first comparison result.
[0090] Step 407: Compare each of the secondary time parameters with the system secondary time respectively to obtain a plurality of second comparison results.
[0091] In order to achieve accurate scheduling of massive scheduled tasks, it is necessary to compare the target scheduled task obtained in the above steps with the scale that the time wheel currently rotates to. In the target scheduled task, it is necessary to compare the first-level time parameter with the system's first-level time to obtain a first comparison result, and it is also necessary to compare each second-level time parameter in the target scheduled task with the system's second-level time to obtain a second comparison result.
[0092] For example, task1, task2 and task3 in the above example are stored in the "first second", "first hour" and "first month" of the task queue according to their respective primary time parameters. Task1 is triggered to execute when the time wheel rotates to the first second mark, and task1 is deleted from the task queue. The time wheel continues to rotate. When the time wheel rotates to the "first hour", the first comparison result obtained in step 406 is the same, but it does not mean that task2 needs to be triggered to execute at this time, so it is necessary to compare through step 407 to obtain the second comparison result.
[0093] Step 408: Determine whether the current system time is consistent with the task processing time of the target scheduled task based on the first comparison result and the plurality of second comparison results.
[0094] In some embodiments of the present application, step 408 may include the following sub-steps:
[0095] Sub-step 21: when the first comparison result indicates that the results are consistent, and each of the second comparison results indicates that the results are consistent, determining that the current time of the system is consistent with the task processing time of the target scheduled task.
[0096] Only when the system's primary time is equal to the primary time parameter of the target scheduled task, and multiple secondary times of the system are equal to multiple secondary time parameters of the target scheduled task, can it be determined that the current system time is consistent with the task processing time of the target scheduled task.
[0097] For example, when the time wheel rotates to the scale of "2:3:4", and the processing time of the top-ranked target scheduled task is "2:3:4", the time wheel rotates to the task processing time of the target scheduled task, and the scheduled task can be accurately scheduled and executed. It should be noted that although the processing time of the target scheduled task for attendance is "2:3:4", its storage position in the task queue will change continuously as the time wheel rotates. The specific description is in the subsequent sub-step 42, which will not be repeated here.
[0098] In some embodiments of the present application, step 408 may also include the following sub-steps:
[0099] Sub-step 31: when the first comparison result characterization results are consistent and at least one of the second comparison result characterization results is inconsistent, determining that the current system time is inconsistent with the task processing time of the target scheduled task.
[0100] When the system's primary time is equal to the primary time parameter of the target scheduled task, but any of the system's multiple secondary times is inconsistent with the corresponding secondary time parameter of the target scheduled task, it can be determined that the system's current time is inconsistent with the task processing time of the target scheduled task. It should be noted that if the first comparison result is inconsistent, it means that the primary system time of the system's current time is inconsistent with the primary time parameter of the target scheduled task, then it can be directly determined that the system's current time is inconsistent with the task processing time of the target scheduled task, without comparing the secondary time parameter with the system's secondary time. For example, if the task processing time of the top-ranked target scheduled task is "two hours, three minutes and four seconds" (the position of the target scheduled task in the task queue is "the second hour"), and the system's current time is "one hour", then it can be directly determined that the time is inconsistent, that is, the time wheel has not rotated to the processing time of the target scheduled task, and it is necessary to continue to rotate and wait.
[0101] In some embodiments of the present application, the levels of the multiple secondary time parameters are different, and the following sub-steps may be included after sub-step 21:
[0102] Sub-step 41: deleting the target scheduled task from the task queue, and determining the target secondary time parameter with the highest level from the multiple secondary time parameters;
[0103] Sub-step 42: based on the target secondary time parameter, storing the target scheduled task into a task queue corresponding to the target secondary time parameter.
[0104] In some implementations of this embodiment, when the first comparison result characterization results are consistent and at least one second comparison result characterization result is inconsistent, it is necessary to delete the target scheduled task from the task queue and store the target scheduled task in the corresponding task queue position based on the highest-level target secondary time parameter among multiple secondary time parameters of the target scheduled task.
[0105] For example, task1, task2 and task3 in the above example are stored in the "first second", "first hour" and "first month" of the task queue according to their respective first-level time parameters. Among them, task1 is triggered to execute when the time wheel rotates to the first second scale, and task1 is deleted from the task queue. The time wheel continues to rotate. When the time wheel rotates to the "first hour", it can be determined that the first comparison result is the same, but it does not mean that task2 needs to be triggered to execute at this time. Therefore, the above steps are required to compare and obtain the second comparison result. The second comparison result obtained at this time is not the same. In the specific implementation process, task2 needs to be deleted from the position corresponding to the first hour of the task queue first, and it is persisted according to the highest level "one minute" in the second-level time parameter of task2, as shown in Table 3. When the time wheel is turned to the one-hour scale, since task2 is triggered at one hour, one minute and five seconds, the execution time has not yet been reached, it is persisted to a specific position in the hour-level message queue. At this time, the specific location where task2 is stored is shown in Table 3.
[0106] Table 3
[0107] Time level Time scale topic Current storage data Second First second s_1 [] ... ... ... ... Second Sixtieth second s_60 [] point First point m_1 [task2] ... ... ... ... point Sixtieth m_60 [] hour First Time h_1 [] ... ... ... ... hour 24th hour m_24 [] sky Day 1 d_1 [] ... ... ... ... sky Day 31 d_31 [] moon Month 1 M_1 [task3] ... ... ... ... moon December M_12 []
[0108] For the scheduled task with a task processing time of "2 hours, 3 minutes and 4 seconds" in the above example, a supplementary explanation is given. Assuming that the task processing time of a scheduled task is "2 hours, 3 minutes and 4 seconds", when the scheduled task is created, the scheduled task is stored in the "second hour" position in the task queue. When the time wheel rotates to 2 hours, since the first comparison result is equal and the second comparison result is not equal, the task will be deleted from the queue and stored in the position corresponding to the "third minute" in the task queue according to the "three minutes" of the task. When the time wheel rotates to "2 hours and 3 minutes", since the first comparison result is equal but the comparison result at the second level in the second comparison result is different, the task will be deleted from the queue again and stored in the position corresponding to the "4th second" in the task queue. When the time wheel continues to rotate and rotates to "2 hours, 3 minutes and 4 seconds", it can be determined that the current system time and the task processing time of the target scheduled task are equal.
[0109] Step 409: When the current system time is consistent with the task processing time of the target scheduled task, the target scheduled task is scheduled and executed.
[0110] For task2 in the above table, when the time wheel turns to 1 hour, 1 minute and 5 seconds, it means that the current system time is consistent with the task processing time of the target scheduled task, and task2 is scheduled and executed. Figure 5 As shown, the main process of implementing scheduled tasks based on the Kafka time wheel provided in some embodiments of the present application is that first, the business system creates a scheduled task, calculates the time wheel scale corresponding to the scheduled task and writes it to the position corresponding to the target scale, the time wheel rotates, and during the rotation of the time wheel, the scheduled task corresponding to the current scale is obtained in real time, and the scheduled task is executed.
[0111] The above-mentioned embodiment of the present application creates a task queue including multiple time levels, obtains multiple scheduled tasks in the business system and the task processing time of the scheduled tasks, the task processing time includes a first-level time parameter, stores multiple scheduled tasks in the task queue according to the first-level time parameter, obtains one or more target scheduled tasks ranked at the top in the task queue, the task processing time of the target scheduled task, and the system current time of the business system, and when the system current time is consistent with the task processing time of the target scheduled task, schedules and executes the target scheduled task. It realizes the direct persistence of multiple scheduled tasks in the business system to task queues of multiple time levels, and on this basis, quickly locates the target scheduled tasks to ensure the accurate scheduling of scheduled tasks in the business system; in addition, the embodiment of the present application realizes the rapid positioning of target scheduled tasks by utilizing multi-level task queues, greatly reducing the number of message queues required to store scheduled tasks with different trigger times, thereby ensuring accurate scheduling of tasks at the second level while also providing high concurrency support.
[0112] It should be noted that, for the sake of simplicity, the method embodiments are described as a series of action combinations, but those skilled in the art should be aware that the embodiments of the present invention are not limited by the order of the actions described, because according to the embodiments of the present invention, certain steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should also be aware that the embodiments described in the specification are all preferred embodiments, and the actions involved are not necessarily required by the embodiments of the present invention.
[0113] Reference Figure 6 , shows a schematic diagram of the structure of a scheduling device for a scheduled task in a business system provided by an embodiment of the present invention, which may specifically include the following modules:
[0114] The queue creation module 601 is configured to create a task queue including multiple time levels;
[0115] A task acquisition module 602 is configured to acquire a plurality of scheduled tasks in the business system and task processing time of the scheduled tasks, wherein the task processing time includes a primary time parameter;
[0116] The task storage module 603 is configured to store the plurality of scheduled tasks into the task queue according to the first-level time parameter;
[0117] The time acquisition module 604 is configured to acquire one or more target scheduled tasks ranked first in the task queue, the task processing time of the target scheduled tasks, and the current system time of the business system;
[0118] The task scheduling module 605 is configured to schedule and execute the target scheduled task when the current time of the system is consistent with the task processing time of the target scheduled task.
[0119] In some optional embodiments of the present application, the task processing time further includes a plurality of secondary time parameters, and the device includes:
[0120] A first extraction module is configured to extract the system primary time corresponding to the primary time parameter and the system secondary time corresponding to the secondary time parameter from the system current time of the business system;
[0121] A first comparison module is configured to compare the first-level time parameter with the first-level time of the system to obtain a first comparison result;
[0122] A second comparison module is configured to compare each of the secondary time parameters with the system secondary time respectively to obtain a plurality of second comparison results;
[0123] The result determination module is configured to determine whether the current time of the system is consistent with the task processing time of the target scheduled task according to the first comparison result and the plurality of second comparison results.
[0124] In some optional embodiments of the present application, the result determination module includes:
[0125] The first determining submodule is configured to determine that the current time of the system is consistent with the task processing time of the target scheduled task when the first comparison result indicates that the results are consistent and each of the second comparison results indicates that the results are consistent.
[0126] In some optional embodiments of the present application, the levels of the multiple secondary time parameters are different, and the result determination module includes:
[0127] The second determining submodule is configured to determine that the current time of the system is inconsistent with the task processing time of the target scheduled task when the first comparison result characterization results are consistent and at least one of the second comparison result characterization results is inconsistent.
[0128] In some optional embodiments of the present application, the result determination module further includes:
[0129] A task deletion module is configured to delete the target scheduled task from the task queue and determine the target secondary time parameter with the highest level from the multiple secondary time parameters;
[0130] The task adjustment module is configured to store the target scheduled task in a task queue corresponding to the target secondary time parameter according to the target secondary time parameter.
[0131] In some optional embodiments of the present application, the task queue containing multiple time levels includes a second-level task queue, a minute-level task queue, an hour-level task queue, a day-level task queue and a month-level task queue.
[0132] In some optional embodiments of the present application, the task storage module 603 includes:
[0133] A type determination submodule is configured to determine a time type of the primary time parameter, wherein the time type is one of a month-level time type, a day-level time type, an hour-level time type, a minute-level time type, and a second-level time type;
[0134] A first storage submodule is configured to store the scheduled task in a position corresponding to the monthly time in the monthly task queue if the time type is a monthly time type;
[0135] A second storage submodule is configured to store the scheduled task to a position corresponding to the day-level time in the day-level task queue if the time type is a day-level time type;
[0136] A third storage submodule is configured to store the scheduled task to a position corresponding to the hourly time in the hourly task queue if the time type is an hourly time type;
[0137] A fourth storage submodule is configured to store the scheduled task in a position corresponding to the minute-level time in the minute-level task queue if the time type is a minute-level time type;
[0138] The fifth storage submodule is configured to store the scheduled task in a position corresponding to the second-level time in the second-level task queue if the time type is a second-level time type.
[0139] An embodiment of the present invention further provides an electronic device, which may include a processor, a memory, and a computer program stored in the memory and capable of running on the processor. When the computer program is executed by the processor, the scheduling method of scheduled tasks in the above business system is implemented.
[0140] An embodiment of the present invention further provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the method for scheduling timed tasks in the above business system is implemented.
[0141] As for the device embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment.
[0142] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of relevant data must comply with the relevant laws, regulations and standards of the relevant countries and regions, and provide corresponding operation entrances for users to choose to authorize or refuse.
[0143] The various embodiments in this specification are described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the various embodiments can be referenced to each other.
[0144] Those skilled in the art will appreciate that the embodiments of the present invention may be provided as methods, devices, or computer program products. Therefore, the embodiments of the present invention may take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Moreover, the embodiments of the present invention may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program codes.
[0145] The embodiments of the present invention are described with reference to the flowcharts and / or block diagrams of the methods, terminal devices (systems), and computer program products according to the embodiments of the present invention. It should be understood that each process and / or block in the flowchart and / or block diagram, as well as the combination of the processes and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing terminal device to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing terminal device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0146] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing terminal device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce a manufactured product including an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0147] These computer program instructions can also be loaded onto a computer or other programmable data processing terminal device so that a series of operating steps are executed on the computer or other programmable terminal device to produce a computer-implemented process, thereby providing instructions for executing on the computer or other programmable terminal device to implement the process. Figure 1 A process or multiple processes and / or boxes Figure 1 A step that specifies a function in one or more boxes.
[0148] Although the preferred embodiments of the present invention have been described, those skilled in the art may make additional changes and modifications to these embodiments once they have learned the basic creative concept. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments and all changes and modifications that fall within the scope of the embodiments of the present invention.
[0149] Finally, it should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or terminal device 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 terminal device. In the absence of further restrictions, the elements defined by the sentence "including one..." do not exclude the existence of other identical elements in the process, method, article or terminal device including the above elements.
[0150] The above is a detailed introduction to the scheduling method, device, equipment and medium for timed tasks in the provided business system. Specific examples are used in this article to illustrate the principles and implementation methods of the present invention. The description of the above embodiments is only used to help understand the method of the present invention and its core idea; at the same time, for general technical personnel in this field, according to the idea of the present invention, there will be changes in the specific implementation method and application scope. In summary, the content of this specification should not be understood as a limitation on the present invention.
Claims
1. A method for scheduling scheduled tasks in a business system, characterized in that: The method comprises: Create a task queue with multiple time levels; Acquire multiple scheduled tasks in the business system and task processing time of the scheduled tasks, wherein the task processing time includes a primary time parameter; Storing the plurality of scheduled tasks in the task queue according to the first-level time parameters; Obtain one or more target scheduled tasks that are ranked first in the task queue, the task processing time of the target scheduled tasks, and the current system time of the business system; When the current time of the system is consistent with the task processing time of the target scheduled task, the target scheduled task is scheduled and executed.
2. The method according to claim 1, characterized in that The task processing time also includes a plurality of secondary time parameters, and when the current time of the system is consistent with the task processing time of the target scheduled task, before scheduling and executing the target scheduled task, it includes: Extracting the system primary time corresponding to the primary time parameter and the system secondary time corresponding to the secondary time parameter from the system current time of the business system; Comparing the first-level time parameter with the first-level time of the system to obtain a first comparison result; Comparing each of the secondary time parameters with the system secondary time respectively to obtain a plurality of second comparison results; According to the first comparison result and the plurality of second comparison results, it is determined whether the current time of the system is consistent with the task processing time of the target scheduled task.
3. The method according to claim 2, characterized in that The determining, based on the first comparison result and the plurality of second comparison results, whether the current system time is consistent with the task processing time of the target scheduled task includes: When the first comparison result indicates that the results are consistent, and when each of the second comparison results indicates that the results are consistent, it is determined that the current time of the system is consistent with the task processing time of the target scheduled task.
4. The method according to claim 2, characterized in that: The levels of the multiple secondary time parameters are different, and determining whether the current time of the system is consistent with the task processing time of the target scheduled task according to the first comparison result and the multiple second comparison results includes: When the first comparison result characterization results are consistent and at least one of the second comparison result characterization results is inconsistent, it is determined that the current time of the system is inconsistent with the task processing time of the target scheduled task.
5. The method according to claim 4, characterized in that After determining that the current time of the system is inconsistent with the task processing time of the target scheduled task, the method includes: Deleting the target scheduled task from the task queue, and determining the highest-level target secondary time parameter from the multiple secondary time parameters; According to the target secondary time parameter, the target scheduled task is stored in a task queue corresponding to the target secondary time parameter.
6. The method according to claim 1, characterized in that The task queues containing multiple time levels include a second-level task queue, a minute-level task queue, an hour-level task queue, a day-level task queue and a month-level task queue.
7. The method according to claim 6, characterized in that The storing the plurality of scheduled tasks into the task queue according to the first-level time parameter comprises: Determine a time type of the first-level time parameter, where the time type is one of a month-level time type, a day-level time type, an hour-level time type, a minute-level time type, and a second-level time type; If the time type is a monthly time type, the scheduled task is stored in the position corresponding to the monthly time in the monthly task queue; If the time type is a day-level time type, the scheduled task is stored in the day-level task queue at a position corresponding to the day-level time; If the time type is an hourly time type, the scheduled task is stored in the hourly task queue at a position corresponding to the hourly time; If the time type is a minute-level time type, the scheduled task is stored in the minute-level task queue at a position corresponding to the minute-level time; If the time type is a second-level time type, the scheduled task is stored in a second-level task queue at a position corresponding to the second-level time.
8. A scheduling device for scheduled tasks in a business system, characterized in that: The device comprises: A queue creation module is configured to create a task queue containing multiple time levels; A task acquisition module is configured to acquire a plurality of scheduled tasks in the business system and task processing time of the scheduled tasks, wherein the task processing time includes a primary time parameter; A task storage module is configured to store the plurality of scheduled tasks into the task queue according to the first-level time parameter; A time acquisition module is configured to acquire one or more target scheduled tasks ranked first in the task queue, the task processing time of the target scheduled tasks, and the current system time of the business system; The task scheduling module is configured to schedule and execute the target scheduled task when the current time of the system is consistent with the task processing time of the target scheduled task.
9. An electronic device, characterized in that: The method comprises a processor, a memory and a computer program stored in the memory and capable of running on the processor, wherein when the computer program is executed by the processor, the method for timing tasks in a business system as claimed in any one of claims 1 to 7 is implemented.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the method for timing tasks in a business system according to any one of claims 1 to 7 is implemented.
Citation Information
Cited By
A simulation scheduling method and device based on a multi-layer time wheel
CN122547486A