Task triggering method and device, computer device and storage medium
By using the task execution round number and slot in the timer slot list for automated polling, the problem of low efficiency in triggering traditional timeout events is solved, and efficient handling of timeout events in online medical consultations is achieved.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- KANG JIAN INFORMATION TECH (SHENZHEN) CO LTD
- Filing Date
- 2022-02-15
- Publication Date
- 2026-04-24
AI Technical Summary
Traditional timeout event triggering methods are inefficient and involve a large number of invalid database scans, resulting in low efficiency in handling timeout events in online medical consultations.
By responding to task processing requests, the task execution round number and slot are obtained, a task to be processed is created, and it is placed in the task list corresponding to the timer slot. The task execution round number and slot are used to realize automatic polling. When the timer runs to the slot node, the task list is traversed to find and trigger the target execution task when the remaining running round number reaches the preset number of rounds.
It improves the triggering efficiency of timeout events, ensuring that tasks are executed immediately when they reach their processing time limit, reducing invalid database scans, and improving the efficiency of online medical consultations.
Smart Images

Figure CN114416324B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computer technology, and in particular to a task triggering method, apparatus, computer device, and storage medium. Background Technology
[0002] With the development of computer technology, online medical consultation technology has emerged. Online medical consultation technology refers to conducting remote consultations and diagnoses using information technologies such as the internet. In online medical consultations, many timeout events can occur, affecting the efficiency of the consultation; therefore, it is necessary to provide reminders for timeout events.
[0003] In traditional technologies, the common approach to timeout event triggering is to scan persistent task data such as databases, so that the computational logic executes the timeout event in the remote database using SQL (Structured Query Language).
[0004] However, traditional methods typically involve periodically scanning persistent task data, resulting in inefficient triggering methods and potentially a large number of invalid database scans, leading to inefficient timeout event triggering. Summary of the Invention
[0005] Therefore, it is necessary to provide a task triggering method, apparatus, computer device, computer-readable storage medium, and computer program product that can improve the efficiency of timeout event triggering in response to the above-mentioned technical problems.
[0006] Firstly, this application provides a task triggering method. The method includes:
[0007] Respond to the task processing request, obtain the task execution round number and task execution slot corresponding to the task to be processed, and create the corresponding task to be processed based on the task execution round number and task execution slot;
[0008] Based on the number of task execution rounds and the task execution slot, place the tasks to be processed in the task list corresponding to the timer slot;
[0009] When the timer reaches a slot node, obtain the list of target tasks corresponding to the current slot node;
[0010] Iterate through the target task list and determine the remaining number of operation rounds for each task in the target task list;
[0011] Find the target task in the target task list that has reached the preset number of remaining running rounds, and trigger the target task.
[0012] In one embodiment, after traversing the target task list and determining the remaining number of operation rounds for each task in the target task list, the method further includes:
[0013] When there are no target tasks in the target task list that have reached the preset number of remaining rotations, the remaining number of rotations is deducted and the remaining number of rotations is updated.
[0014] Jump to the step of obtaining the target task list corresponding to the current slot node when the timer runs to the slot node.
[0015] In one embodiment, responding to a task processing request, obtaining the task execution round number and task execution slot corresponding to the task to be processed, and creating the corresponding task to be processed based on the task execution round number and task execution slot includes:
[0016] Respond to the task processing request, determine the task processing duration based on the task identifier carried in the task processing request, and obtain the timer attribute information;
[0017] Based on the task processing duration and timer attribute information, obtain the task execution round number and task execution slot corresponding to the task to be processed, and create the corresponding task to be processed based on the task execution round number and task execution slot.
[0018] In one embodiment, the timer attribute information includes the timer start time, historical execution duration, and the total number of timer slots;
[0019] Based on the task processing duration and timer attribute information, obtain the task execution round number and task execution slot corresponding to the task to be processed, and create the corresponding task to be processed based on the task execution round number and task execution slot, including:
[0020] The first execution duration is determined based on the task processing time and the timer start time;
[0021] The second execution duration is determined based on the first execution duration and the historical execution duration;
[0022] The number of task execution rounds is determined based on the second execution duration and the total number of timer slots, and the task execution slot is determined based on the first execution duration and the total number of timer slots.
[0023] Create corresponding pending tasks based on the task execution round and task execution slot.
[0024] In one embodiment, the number of task execution rounds is determined based on the second execution duration and the total number of timer slots, and the task execution slots are determined based on the first execution duration and the total number of timer slots, including:
[0025] Calculate the ratio of the second execution duration to the total number of timer slots, use the ratio as the number of task execution rounds, and take the modulo of the first execution duration with the total number of timer slots to obtain the task execution slot.
[0026] In one embodiment, placing the task to be processed in the task list corresponding to the timer slot according to the task execution round number and the task execution slot includes:
[0027] Based on the number of task execution rounds and the task execution slot, write the tasks to be processed into the local buffer queue;
[0028] Based on a preset time window, retrieve tasks to be processed from the buffer queue;
[0029] Load the tasks to be processed into the task list corresponding to the timer slot.
[0030] In one embodiment, triggering the target to perform the task includes:
[0031] The corresponding target message queue is determined based on the target task identifier of the target task.
[0032] Push a timeout notification message to the target message queue.
[0033] Secondly, this application also provides a task triggering device. The device includes:
[0034] The response module is used to respond to task processing requests, obtain the task execution round number and task execution slot corresponding to the task to be processed, and create the corresponding task to be processed based on the task execution round number and task execution slot.
[0035] The placement module is used to place the tasks to be processed into the task list corresponding to the timer slot based on the number of task execution rounds and the task execution slot.
[0036] The acquisition module is used to obtain the list of target tasks corresponding to the current slot node when the timer runs to the slot node;
[0037] The traversal module is used to traverse the target task list and determine the number of remaining operation rounds for each task in the target task list.
[0038] The trigger module is used to find the target task in the target task list that has reached the preset number of remaining running rounds, and trigger the target task to execute.
[0039] Thirdly, this application also provides a computer device. The computer device includes a memory and a processor, the memory storing a computer program, and the processor executing the computer program to perform the following steps:
[0040] Respond to the task processing request, obtain the task execution round number and task execution slot corresponding to the task to be processed, and create the corresponding task to be processed based on the task execution round number and task execution slot;
[0041] Based on the number of task execution rounds and the task execution slot, place the tasks to be processed in the task list corresponding to the timer slot;
[0042] When the timer reaches a slot node, obtain the list of target tasks corresponding to the current slot node;
[0043] Iterate through the target task list and determine the remaining number of operation rounds for each task in the target task list;
[0044] Find the target task in the target task list that has reached the preset number of remaining running rounds, and trigger the target task.
[0045] Fourthly, this application also provides a computer-readable storage medium. The computer-readable storage medium stores a computer program thereon, which, when executed by a processor, performs the following steps:
[0046] Respond to the task processing request, obtain the task execution round number and task execution slot corresponding to the task to be processed, and create the corresponding task to be processed based on the task execution round number and task execution slot;
[0047] Based on the number of task execution rounds and the task execution slot, place the tasks to be processed in the task list corresponding to the timer slot;
[0048] When the timer reaches a slot node, obtain the list of target tasks corresponding to the current slot node;
[0049] Iterate through the target task list and determine the remaining number of operation rounds for each task in the target task list;
[0050] Find the target task in the target task list that has reached the preset number of remaining running rounds, and trigger the target task.
[0051] Fifthly, this application also provides a computer program product. The computer program product includes a computer program that, when executed by a processor, performs the following steps:
[0052] Respond to the task processing request, obtain the task execution round number and task execution slot corresponding to the task to be processed, and create the corresponding task to be processed based on the task execution round number and task execution slot;
[0053] Based on the number of task execution rounds and the task execution slot, place the tasks to be processed in the task list corresponding to the timer slot;
[0054] When the timer reaches a slot node, obtain the list of target tasks corresponding to the current slot node;
[0055] Iterate through the target task list and determine the remaining number of operation rounds for each task in the target task list;
[0056] Find the target task in the target task list that has reached the preset number of remaining running rounds, and trigger the target task.
[0057] The aforementioned task triggering method, apparatus, computer equipment, storage medium, and computer program product, by responding to task processing requests, obtain the task execution round number and task execution slot corresponding to the task to be processed, and create the corresponding task to be processed based on the task execution round number and task execution slot. It can place the task to be processed in the task list corresponding to the timer slot based on the task execution round number and task execution slot. Thus, when the timer reaches a slot node, it can obtain the target task list corresponding to the current slot node, traverse the target task list, determine the remaining number of execution rounds for each task in the target task list, and poll the task to be processed. Furthermore, it can find the target execution task in the target task list whose remaining number of execution rounds has reached a preset number of rounds, and trigger the target execution task. Throughout this process, it can automatically poll the task to be processed locally using the task execution round number and task execution slot. When the task to be processed reaches its processing time limit, i.e., when the task to be processed is the target execution task, it immediately triggers the execution, thereby improving the efficiency of timeout event triggering. Attached Figure Description
[0058] Figure 1 This is an application environment diagram of the task triggering method in one embodiment;
[0059] Figure 2 This is a flowchart illustrating a task triggering method in one embodiment;
[0060] Figure 3 This is a schematic diagram of a timer in one embodiment;
[0061] Figure 4 This is a flowchart illustrating the task triggering method in another embodiment;
[0062] Figure 5 This is a structural block diagram of a task triggering device in one embodiment;
[0063] Figure 6 This is an internal structural diagram of a computer device in one embodiment. Detailed Implementation
[0064] To make the objectives, technical solutions, and advantages of this application clearer, the following detailed description is provided in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the scope of this application.
[0065] The task triggering method provided in this application embodiment can be applied to, for example... Figure 1 In the application environment shown, terminal 102 communicates with server 104 via a network. A data storage system can store the data that server 104 needs to process. The data storage system can be integrated onto server 104 or placed on a cloud or other network server. Users initiate task processing requests (specifically, online consultation requests) to server 104 by operating on terminal 102. Server 104 responds to the task processing request, obtains the task execution round number and task execution slot corresponding to the task to be processed, and creates the corresponding task to be processed based on the task execution round number and task execution slot. Based on the task execution round number and task execution slot, the task to be processed is placed in the task list corresponding to the timer slot. When the timer reaches the slot node, the target task list corresponding to the current slot node is obtained, the target task list is traversed, the remaining number of execution rounds corresponding to each task in the target task list is determined, and the target execution task whose remaining number of execution rounds has reached the preset number of rounds is found and triggered. The terminal 102 can be, but is not limited to, various personal computers, laptops, smartphones, tablets, IoT devices, and portable wearable devices. IoT devices can include smart speakers, smart TVs, smart air conditioners, and smart in-vehicle systems. Portable wearable devices can include smartwatches, smart bracelets, and head-mounted devices. The server 104 can be implemented using a standalone server or a server cluster consisting of multiple servers.
[0066] In one embodiment, such as Figure 2 As shown, a task triggering method is provided, which can be applied to Figure 1 Taking server 104 as an example, the following steps are included:
[0067] Step 202: Respond to the task processing request, obtain the task execution round number and task execution slot corresponding to the task to be processed, and create the corresponding task to be processed according to the task execution round number and task execution slot.
[0068] In this context, a task processing request refers to a request to process a task. For example, a task processing request could specifically refer to a request to process an online consultation. A pending task is a timed task corresponding to a task processing request, used to monitor the processing time of that request. For example, a pending task could specifically refer to a timed task corresponding to an online consultation task, used to monitor the processing time of that task. The task execution rounds refer to the number of rounds the pending task needs to execute within the timer. The task execution slot refers to the slot number where the pending task should be placed within the timer. A timer is a logical timer that includes many slots, each corresponding to an operating frequency. For example, a timer can be like... Figure 3 As shown, there are 8 ticks (the ticking sound of a clock) on it. If we assume that each tick of the timer is 1 second, it will take 8 seconds to complete this wheel. The scale corresponding to each tick is a slot. A linked list is maintained on the slot, representing the unprocessed tasks maintained in this tick.
[0069] Specifically, when an online consultation is needed, the user will initiate a task processing request to the server by operating on the terminal. The server responds to the task processing request, determines the task processing duration based on the task processing request, and obtains the timer's attribute information. Based on the task processing duration and attribute information, the server obtains the task execution round number and task execution slot corresponding to the task to be processed, and creates the corresponding task to be processed based on these two task attribute parameters.
[0070] Step 204: Based on the task execution round number and task execution slot, place the tasks to be processed into the task list corresponding to the timer slot.
[0071] The task list is used to maintain the pending tasks within the timer slots. Specifically, the task list can refer to a linked list used to maintain pending tasks. After a pending task is placed in the task list corresponding to a timer slot, the timer can monitor the execution of task processing requests by timing the pending tasks, triggering a timeout message when the task processing request reaches its processing time limit. It should be noted that when the task processing request corresponding to a pending task is pre-processed or reaches its processing time limit (i.e., when the pending task reaches its execution time limit), the server will remove the pending task from the task list.
[0072] Specifically, the server determines the timer slot where the pending tasks should be placed based on the task execution slot, and places the pending tasks in the task list corresponding to the timer slot according to the task execution round.
[0073] Step 206: When the timer reaches the slot node, obtain the target task list corresponding to the current slot node.
[0074] Specifically, the server runs a timer in real time. When the timer reaches a slot node, it retrieves the target task list corresponding to the current slot node to determine whether the tasks in the target task list need to be executed.
[0075] Step 208: Traverse the target task list and determine the remaining number of runs for each task in the target task list.
[0076] The remaining number of rotations describes how many more rotations the timer needs to run before the pending task can be executed. For example, the remaining number of rotations can be 0, indicating that the pending task can be executed.
[0077] Specifically, after obtaining the target task list, the server will traverse the target task list and determine the remaining number of operation rounds for each task in the target task list in order to determine whether any task needs to be executed after this round.
[0078] Step 210: Locate the target task in the target task list that has reached the preset number of remaining running rounds, and trigger the target task.
[0079] The preset number of rounds refers to a pre-set threshold number of rounds used to determine whether the pending task needs to be executed. It can be set as needed. For example, the preset number of rounds can be 0.
[0080] Specifically, the server compares the remaining number of operation rounds for each task in the target task list with the preset number of rounds to find the target task in the target task list whose remaining number of operation rounds has reached the preset number of rounds. When there is a target task in the target task list, it means that the target task needs to be executed. The server will trigger the target task to indicate that the task processing request corresponding to the target task has reached the processing time limit and does not need to continue to be executed, and remove the target task from the task list.
[0081] The aforementioned task triggering method, by responding to task processing requests, obtains the task execution round number and task execution slot corresponding to the task to be processed, and creates the corresponding task to be processed based on the task execution round number and task execution slot. It can place the task to be processed in the task list corresponding to the timer slot based on the task execution round number and task execution slot. Thus, when the timer reaches a slot node, it obtains the target task list corresponding to the current slot node, traverses the target task list, determines the remaining number of execution rounds for each task in the target task list, and polls the tasks to be processed. It can then find the target execution task in the target task list whose remaining number of execution rounds has reached a preset number and trigger the target execution task. The entire process can utilize the task execution round number and task execution slot to achieve automated polling of tasks to be processed locally. When a task to be processed reaches its processing time limit, i.e., when the task to be processed is the target execution task, the trigger is executed immediately, which can improve the efficiency of timeout event triggering.
[0082] In one embodiment, after traversing the target task list and determining the remaining number of runs for each task in the target task list, the method further includes:
[0083] When there are no target tasks in the target task list that have reached the preset number of remaining rotations, the remaining number of rotations is deducted and the remaining number of rotations is updated.
[0084] Jump to the step of obtaining the target task list corresponding to the current slot node when the timer runs to the slot node.
[0085] Specifically, when there are no target tasks in the target task list with the remaining number of execution rounds reaching the preset number, it means that no pending tasks have reached their execution time limit and need to be executed. The server will deduct the remaining number of execution rounds for each task in the target task list and update the remaining number of execution rounds to achieve the execution round count for tasks in the target task list. At the same time, the timer continues to run in real time. The timer will continue to run to a new slot node, obtain the target task list corresponding to the current slot node, traverse the target task list, determine the remaining number of execution rounds for each task in the target task list, find the target task in the target task list with the remaining number of execution rounds reaching the preset number, and trigger the target task to be executed.
[0086] Specifically, after the timer completes one cycle, it will run again to the slot node in the target task list where the remaining number of cycles for each task has been updated. When it runs to this slot node again, the server will retrieve the target task list corresponding to this slot node, traverse the target task list, determine the updated remaining number of cycles for each task in the target task list, find the target task in the target task list whose updated remaining number of cycles has reached the preset number, and trigger the target task.
[0087] Furthermore, if there exists an updated remaining number of execution rounds equal to the preset number, it indicates that the task corresponding to that updated remaining number of execution rounds is the target execution task and has reached its execution deadline. The server will trigger the target execution task determined at this time to indicate that the task processing request corresponding to the target execution task has reached its processing time limit and does not need to continue execution, and will remove the target execution task from the target task list. If there is no updated remaining number of execution rounds equal to the preset number, it means that after another round of timer operation, no task in the target task list has reached its execution time limit. The server will again deduct the updated remaining number of execution rounds corresponding to each task in the target task list and update the updated remaining number of execution rounds. That is, it will update the remaining number of execution rounds again to realize the execution round count and counting of tasks in the target task list, and jump to the step of obtaining the target task list corresponding to the current slot node when the timer runs to the slot node. When the timer runs to the current slot node again, it will judge each task in the target task list again.
[0088] In this embodiment, when there is no target task in the target task list with a remaining number of running rounds that has reached the preset number of rounds, the remaining number of running rounds is deducted and the remaining number of running rounds is updated. This enables the execution polling and counting of tasks to be processed. By jumping to the step of obtaining the target task list corresponding to the current slot node when the timer runs to the slot node, the timer can be used to realize automated polling for execution triggering, thereby improving the efficiency of timeout event triggering.
[0089] In one embodiment, responding to a task processing request, obtaining the task execution round number and task execution slot corresponding to the task to be processed, and creating the corresponding task to be processed based on the task execution round number and task execution slot includes:
[0090] Respond to the task processing request, determine the task processing duration based on the task identifier carried in the task processing request, and obtain the timer attribute information;
[0091] Based on the task processing duration and timer attribute information, obtain the task execution round number and task execution slot corresponding to the task to be processed, and create the corresponding task to be processed based on the task execution round number and task execution slot.
[0092] The task identifier is used to distinguish different types of tasks. For example, for online consultation tasks, the task identifier distinguishes different types of online consultations from different service providers. For instance, the task identifier can be represented by "service provider + task type + service number," where the service provider refers to the online consultation service provider, which can be different medical institutions. The task processing time refers to the pre-set time required to process the task. The processing time can vary depending on the type of task. For example, for online consultation tasks, online consultation types include internal consultations, external consultations, and prescription business consultations. The corresponding task processing time could be: 15 minutes for internal consultations, 20 minutes for external consultations, and 30 minutes for prescription business consultations.
[0093] The timer attribute information describes the basic attributes of the timer, including the timer start time, historical execution duration, and total number of timer slots. The timer start time refers to the time when the timer is first started, the historical execution duration refers to the total time the timer has been running, and the total number of timer slots refers to the total number of slots set on the timer.
[0094] Specifically, when an online consultation is needed, the user will operate through the terminal to initiate a task processing request with a task identifier to the server. The server responds to the task processing request, determines the task type based on the task identifier carried in the task processing request, determines the pre-set task processing duration based on the task type, and obtains the timer attribute information at the current time. Based on the task processing duration and the timer attribute information, the server determines the number of task execution rounds and the task execution slot, and creates the corresponding pending task based on the two task attribute parameters of the number of task execution rounds and the task execution slot.
[0095] In this embodiment, by responding to a task processing request carrying a task identifier, determining the task processing duration based on the task identifier, and obtaining timer attribute information, it is possible to obtain the task execution round number and task execution slot corresponding to the task to be processed based on the task processing duration and timer attribute information, and create the corresponding task to be processed based on the task execution round number and task execution slot, thereby realizing the creation of the task to be processed.
[0096] In one embodiment, the timer attribute information includes the timer start time, historical execution duration, and the total number of timer slots;
[0097] Based on the task processing duration and timer attribute information, obtain the task execution round number and task execution slot corresponding to the task to be processed, and create the corresponding task to be processed based on the task execution round number and task execution slot, including:
[0098] The first execution duration is determined based on the task processing time and the timer start time;
[0099] The second execution duration is determined based on the first execution duration and the historical execution duration;
[0100] The number of task execution rounds is determined based on the second execution duration and the total number of timer slots, and the task execution slot is determined based on the first execution duration and the total number of timer slots.
[0101] Create corresponding pending tasks based on the task execution round and task execution slot.
[0102] Specifically, the server determines the first execution duration of the timer based on the task processing duration, the timer start time, and the current time. Then, based on the first execution duration and the timer's historical execution duration, it determines the second execution duration. The second execution duration is the remaining time the timer needs to run while monitoring the pending tasks. After determining the second execution duration, the server calculates the ratio of the second execution duration to the total number of timer slots. This ratio is used as the number of task execution rounds. The server then takes the modulo of the first execution duration with the total number of timer slots to obtain the task execution slot. Based on these two task attribute parameters—the number of task execution rounds and the task execution slot—the server creates the corresponding pending task.
[0103] For example, after the timer starts, the server records the timer start time. After each task is created, the server calculates the number of ticks (a) (i.e., the first execution duration) based on the task's processing time and the timer start time. Then, it subtracts the number of ticks (b) (i.e., the historical execution duration) since the timer started to obtain the second execution duration.
[0104] In this embodiment, by utilizing the task processing duration, timer start time, historical execution duration, and total number of timer slots, the number of task execution rounds and task execution slots are determined, enabling the creation of tasks to be processed using the number of task execution rounds and task execution slots.
[0105] In one embodiment, determining the number of task execution rounds based on the second execution duration and the total number of timer slots, and determining the task execution slot based on the first execution duration and the total number of timer slots, includes:
[0106] Calculate the ratio of the second execution duration to the total number of timer slots, use the ratio as the number of task execution rounds, and take the modulo of the first execution duration with the total number of timer slots to obtain the task execution slot.
[0107] Specifically, since the second execution duration is the time that the timer still needs to run while monitoring the tasks to be processed, the server can determine the number of task execution rounds by calculating the ratio of the second execution duration to the total number of timer slots. At the same time, the server will take the modulo of the first execution duration with the total number of timer slots, and the task execution slot where the task to be processed needs to be placed can be determined by taking the modulo.
[0108] For example, the server will divide the total number of timer slots by the second execution duration. The result of the division is recorded as the round number (i.e., the number of task execution rounds). The tick number (a) is modulo the total number of timer slots and recorded as the slot index (i.e., the task execution slot).
[0109] In this embodiment, the number of task execution rounds can be determined by calculating the ratio of the second execution duration to the total number of timer slots. The task execution slot can be obtained by taking the modulo of the first execution duration with the total number of timer slots.
[0110] In one embodiment, placing the task to be processed in the task list corresponding to the timer slot according to the task execution round number and the task execution slot includes:
[0111] Based on the number of task execution rounds and the task execution slot, write the tasks to be processed into the local buffer queue;
[0112] Based on a preset time window, retrieve tasks to be processed from the buffer queue;
[0113] Load the tasks to be processed into the task list corresponding to the timer slot.
[0114] The local buffer queue is used to cache pending tasks. The preset time window refers to a pre-set time period for retrieving pending tasks. For example, if the preset time window is 6 hours, the server will only retrieve pending tasks within the 6 hours corresponding to the preset time window each time it retrieves tasks.
[0115] Specifically, the server writes the tasks to be processed into a local buffer queue based on the task execution rounds and task execution slots. Based on a preset time window, it retrieves the tasks to be processed within the time period corresponding to that window from the buffer queue and loads them into the task list corresponding to the timer slot. In this embodiment, the timer slot corresponds to the task execution slot.
[0116] For example, the server loads tasks from its local buffer queue onto timers asynchronously. It's important to note that during asynchronous loading, the server only loads recent tasks, ensuring that all tasks maintained by the timer slots are due to be triggered soon. A continuously moving preset time window ensures that all distant tasks in the buffer queue are asynchronously loaded into the timer in descending order of execution time. Recent tasks can be defined as needed; for example, recent tasks could specifically refer to tasks triggered within the last 6 hours, in which case the preset time window would be 6 hours.
[0117] In this embodiment, by writing the tasks to be processed into a local buffer queue according to the number of task execution rounds and the task execution slot, and retrieving the tasks to be processed from the buffer queue based on a preset time window, the tasks to be processed are loaded into the task list corresponding to the timer slot, thus realizing the loading of tasks to be processed.
[0118] In one embodiment, triggering the target to perform a task includes:
[0119] The corresponding target message queue is determined based on the target task identifier of the target task.
[0120] Push a timeout notification message to the target message queue.
[0121] Specifically, different tasks correspond to different message queues. When a target task exists in the target task list, the server queries the preset target task identifier and message queue correspondence based on the target task identifier, determines the corresponding target message queue, and pushes a timeout message to the target message queue. The target message queue then sends the timeout message to the corresponding business party, informing them that the processing request for the task corresponding to the target task has timed out. Upon receiving the timeout message, the business party understands that processing has expired and can speed up processing to improve efficiency. The timeout message can take the form of: "Current task processing has timed out." For example, when the task is an online consultation task, the timeout message could be: "Current online consultation task has timed out."
[0122] In this embodiment, by using asynchronous message triggering, the business can obtain the required timeout prompt message by focusing only on its own message queue, without consuming resources. Furthermore, by utilizing the message queue's accumulation and retry mechanism, the performance and redundancy of the server can be improved.
[0123] In one embodiment, to Figure 3 Taking the timer in the example, we will illustrate the task triggering method of this application. Here, we assume that the preset number of rounds is 0.
[0124] correspond Figure 3 The timer in the program, when the processing time of task 1 is 4 seconds, indicates that the task should be executed after 4 seconds, and therefore it should be loaded into the timer. Figure 3 The slot with index 3 is currently in the task execution rounds, which are 0. If the processing time for task 2 is 28 seconds, it means the task should be executed in 28 seconds, and therefore it should also be loaded into the task queue. Figure 3 The timer is set to slot 3, and the task execution round count is 3. For these two pending tasks, once the timer starts, it ticks once per second, iterating through the tasks associated with the slot. Tasks with 0 execution rounds are immediately triggered and removed from the task list; otherwise, their round count is deducted. When the timer reaches slot 3, it finds that pending task 1 has 0 execution rounds, so it is designated as the target task and triggered. Pending task 2 has 3 execution rounds, so its round count is deducted and updated to 2. This process continues until the timer completes 3 cycles. On the fourth cycle, when it reaches slot 3 again, it finds that the current task execution round count is 0, designates it as the target task, and triggers pending task 2.
[0125] It should be noted that the timer in this application can maintain a large number of pending tasks (such as a timer with 360 slots, each slot storing 10,000 tasks, so a single machine can support 3.6 million timed tasks). At the same time, the CPU (central processing unit) can calculate (complete traversal within one tick) to determine whether a large number of tasks should be triggered, which can achieve very high single-machine scheduling performance.
[0126] In one embodiment, such as Figure 4 As shown in the diagram, the task triggering method of this application is illustrated by a flowchart, which specifically includes the following steps:
[0127] Step 402: Respond to the task processing request, determine the task processing duration based on the task identifier carried in the task processing request, and obtain the timer attribute information, which includes the timer start time, historical execution duration, and the total number of timer slots.
[0128] Step 404: Determine the first execution duration based on the task processing time and the timer start time;
[0129] Step 406: Determine the second execution duration based on the first execution duration and the historical execution duration;
[0130] Step 408: Calculate the ratio of the second execution duration to the total number of timer slots, use the ratio as the number of task execution rounds, and take the modulo of the total number of timer slots based on the first execution duration to obtain the task execution slot;
[0131] Step 410: Create corresponding pending tasks based on the task execution round number and task execution slot;
[0132] Step 412: Write the tasks to be processed into the local buffer queue according to the task execution round number and task execution slot.
[0133] Step 414: Based on a preset time window, retrieve the tasks to be processed from the buffer queue;
[0134] Step 416: Load the tasks to be processed into the task list corresponding to the timer slot;
[0135] Step 418: When the timer reaches the slot node, obtain the target task list corresponding to the current slot node;
[0136] Step 420: Traverse the target task list and determine the remaining number of operation rounds for each task in the target task list;
[0137] Step 422: Find the target task in the target task list that has reached the preset number of remaining rotations. If there is no target task in the target task list that has reached the preset number of remaining rotations, jump to step 424. If there is a target task in the target task list that has reached the preset number of remaining rotations, jump to step 426.
[0138] Step 424: Subtract the remaining number of rotating wheels, update the remaining number of rotating wheels, and jump to step 418;
[0139] Step 426: Determine the corresponding target message queue based on the target task identifier of the target task;
[0140] Step 428: Push a timeout notification message to the target message queue.
[0141] It should be understood that although the steps in the flowcharts of the embodiments described above are shown sequentially according to the arrows, these steps are not necessarily executed in the order indicated by the arrows. Unless explicitly stated herein, there is no strict order restriction on the execution of these steps, and they can be executed in other orders. Moreover, at least some steps in the flowcharts of the embodiments described above may include multiple steps or multiple stages. These steps or stages are not necessarily completed at the same time, but can be executed at different times. The execution order of these steps or stages is not necessarily sequential, but can be performed alternately or in turn with other steps or at least some of the steps or stages of other steps.
[0142] Based on the same inventive concept, this application also provides a task triggering device for implementing the task triggering method described above. The solution provided by this device is similar to the solution described in the above method; therefore, the specific limitations in one or more task triggering device embodiments provided below can be found in the limitations of the task triggering method described above, and will not be repeated here.
[0143] In one embodiment, such as Figure 5 As shown, a task triggering device is provided, including: a response module 502, a placement module 504, an acquisition module 506, a traversal module 508, and a triggering module 510, wherein:
[0144] The response module 502 is used to respond to task processing requests, obtain the task execution round number and task execution slot corresponding to the task to be processed, and create the corresponding task to be processed according to the task execution round number and task execution slot.
[0145] The placement module 504 is used to place the tasks to be processed into the task list corresponding to the timer slot according to the number of task execution rounds and the task execution slot;
[0146] The acquisition module 506 is used to acquire the target task list corresponding to the current slot node when the timer runs to the slot node;
[0147] Traversal module 508 is used to traverse the target task list and determine the number of remaining operation rounds for each task in the target task list.
[0148] Trigger module 510 is used to find the target task in the target task list that has reached the preset number of remaining rotations and trigger the target task to execute.
[0149] The aforementioned task triggering device, by responding to task processing requests, obtains the task execution round number and task execution slot corresponding to the task to be processed, and creates the corresponding task to be processed based on the task execution round number and task execution slot. It can place the task to be processed in the task list corresponding to the timer slot based on the task execution round number and task execution slot. Thus, when the timer runs to the slot node, it can obtain the target task list corresponding to the current slot node, traverse the target task list, determine the remaining number of running rounds corresponding to each task in the target task list, realize the polling of the task to be processed, and then find the target execution task in the target task list that has reached the preset number of remaining running rounds, and trigger the target execution task. The whole process can realize the automatic polling of the task to be processed locally using the task execution round number and task execution slot. When the task to be processed reaches the processing time limit, that is, when the task to be processed is the target execution task, the triggering is executed immediately, which can improve the efficiency of timeout event triggering.
[0150] In one embodiment, the triggering module is further configured to deduct the remaining number of running rounds, update the remaining number of running rounds, and jump to the step of obtaining the target task list corresponding to the current slot node when the timer runs to the slot node when there is no target task in the target task list with the remaining number of running rounds reaching the preset number of running rounds.
[0151] In one embodiment, the response module is further configured to respond to a task processing request, determine the task processing duration based on the task identifier carried in the task processing request, obtain timer attribute information, obtain the task execution round number and task execution slot corresponding to the task to be processed based on the task processing duration and timer attribute information, and create the corresponding task to be processed based on the task execution round number and task execution slot.
[0152] In one embodiment, the timer attribute information includes the timer start time, historical execution duration, and the total number of timer slots. The response module is further configured to determine a first execution duration based on the task processing duration and the timer start time, determine a second execution duration based on the first execution duration and the historical execution duration, determine the number of task execution rounds based on the second execution duration and the total number of timer slots, determine the task execution slot based on the first execution duration and the total number of timer slots, and create a corresponding task to be processed based on the number of task execution rounds and the task execution slot.
[0153] In one embodiment, the response module is further configured to calculate the ratio of the second execution duration to the total number of timer slots, use the ratio as the number of task execution rounds, and take the modulo of the total number of timer slots based on the first execution duration to obtain the task execution slot.
[0154] In one embodiment, the placement module is further configured to write the tasks to be processed into a local buffer queue according to the number of task execution rounds and the task execution slot, retrieve the tasks to be processed from the buffer queue based on a preset time window, and load the tasks to be processed into the task list corresponding to the timer slot.
[0155] In one embodiment, the triggering module is further configured to determine the corresponding target message queue based on the target task identifier of the target task to be executed, and push a timeout prompt message to the target message queue.
[0156] Each module in the aforementioned task triggering device can be implemented entirely or partially through software, hardware, or a combination thereof. These modules can be embedded in the processor of a computer device in hardware form or independent of it, or stored in the memory of a computer device in software form, so that the processor can call and execute the operations corresponding to each module.
[0157] In one embodiment, a computer device is provided, which may be a server, and its internal structure diagram may be as follows: Figure 6 As shown, the computer device includes a processor, memory, and a network interface connected via a system bus. The processor provides computing and control capabilities. The memory includes non-volatile storage media and internal memory. The non-volatile storage media stores the operating system, computer programs, and a database. The internal memory provides an environment for the operation of the operating system and computer programs stored in the non-volatile storage media. The database stores data such as tasks to be processed. The network interface communicates with external terminals via a network connection. When the computer program is executed by the processor, it implements a task triggering method.
[0158] Those skilled in the art will understand that Figure 6 The structure shown is merely a block diagram of a portion of the structure related to the present application and does not constitute a limitation on the computer device to which the present application is applied. Specific computer devices may include more or fewer components than those shown in the figure, or combine certain components, or have different component arrangements.
[0159] In one embodiment, a computer device is provided, including a memory and a processor, wherein the memory stores a computer program, and the processor executes the computer program to perform the following steps:
[0160] Respond to the task processing request, obtain the task execution round number and task execution slot corresponding to the task to be processed, and create the corresponding task to be processed based on the task execution round number and task execution slot;
[0161] Based on the number of task execution rounds and the task execution slot, place the tasks to be processed in the task list corresponding to the timer slot;
[0162] When the timer reaches a slot node, obtain the list of target tasks corresponding to the current slot node;
[0163] Iterate through the target task list and determine the remaining number of operation rounds for each task in the target task list;
[0164] Find the target task in the target task list that has reached the preset number of remaining running rounds, and trigger the target task.
[0165] In one embodiment, when the processor executes the computer program, it further implements the following steps: when there is no target task in the target task list with a remaining number of running rounds reaching a preset number of rounds, the remaining number of running rounds is deducted, the remaining number of running rounds is updated, and the process jumps to the step of obtaining the target task list corresponding to the current slot node when the timer runs to the slot node.
[0166] In one embodiment, when the processor executes the computer program, it further performs the following steps: responding to a task processing request, determining the task processing duration based on the task identifier carried in the task processing request, and obtaining timer attribute information; obtaining the task execution round number and task execution slot corresponding to the task to be processed based on the task processing duration and timer attribute information, and creating the corresponding task to be processed based on the task execution round number and task execution slot.
[0167] In one embodiment, when the processor executes the computer program, it further performs the following steps: determining a first execution duration based on the task processing duration and the timer start time; determining a second execution duration based on the first execution duration and the historical execution duration; determining the number of task execution rounds based on the second execution duration and the total number of timer slots; determining the task execution slot based on the first execution duration and the total number of timer slots; and creating a corresponding task to be processed based on the number of task execution rounds and the task execution slot.
[0168] In one embodiment, when the processor executes the computer program, it further performs the following steps: calculating the ratio of the second execution duration to the total number of timer slots, using the ratio as the number of task execution rounds, and taking the modulo of the total number of timer slots based on the first execution duration to obtain the task execution slot.
[0169] In one embodiment, when the processor executes the computer program, it further performs the following steps: writing the task to be processed into a local buffer queue according to the task execution round number and the task execution slot; retrieving the task to be processed from the buffer queue based on a preset time window; and loading the task to be processed into the task list corresponding to the timer slot.
[0170] In one embodiment, when the processor executes the computer program, it further performs the following steps: determining the corresponding target message queue based on the target task identifier of the target task to be executed, and pushing a timeout prompt message to the target message queue.
[0171] In one embodiment, a computer-readable storage medium is provided having a computer program stored thereon, the computer program performing the following steps when executed by a processor:
[0172] Respond to the task processing request, obtain the task execution round number and task execution slot corresponding to the task to be processed, and create the corresponding task to be processed based on the task execution round number and task execution slot;
[0173] Based on the number of task execution rounds and the task execution slot, place the tasks to be processed in the task list corresponding to the timer slot;
[0174] When the timer reaches a slot node, obtain the list of target tasks corresponding to the current slot node;
[0175] Iterate through the target task list and determine the remaining number of operation rounds for each task in the target task list;
[0176] Find the target task in the target task list that has reached the preset number of remaining running rounds, and trigger the target task.
[0177] In one embodiment, when the computer program is executed by the processor, it further implements the following steps: when there is no target task in the target task list with a remaining number of running rounds reaching a preset number of rounds, the remaining number of running rounds is deducted, the remaining number of running rounds is updated, and the process jumps to the step of obtaining the target task list corresponding to the current slot node when the timer reaches the slot node.
[0178] In one embodiment, when the computer program is executed by the processor, it further performs the following steps: responding to a task processing request, determining the task processing duration based on the task identifier carried in the task processing request, and obtaining timer attribute information; obtaining the task execution round number and task execution slot corresponding to the task to be processed based on the task processing duration and timer attribute information, and creating the corresponding task to be processed based on the task execution round number and task execution slot.
[0179] In one embodiment, when the computer program is executed by the processor, it further performs the following steps: determining a first execution duration based on the task processing duration and the timer start time; determining a second execution duration based on the first execution duration and the historical execution duration; determining the number of task execution rounds based on the second execution duration and the total number of timer slots; determining the task execution slot based on the first execution duration and the total number of timer slots; and creating a corresponding task to be processed based on the number of task execution rounds and the task execution slot.
[0180] In one embodiment, when the computer program is executed by the processor, it further performs the following steps: calculating the ratio of the second execution duration to the total number of timer slots, using the ratio as the number of task execution rounds, and taking the modulo of the total number of timer slots based on the first execution duration to obtain the task execution slot.
[0181] In one embodiment, when the computer program is executed by the processor, it further performs the following steps: writing the tasks to be processed into a local buffer queue according to the task execution round number and the task execution slot; retrieving the tasks to be processed from the buffer queue based on a preset time window; and loading the tasks to be processed into the task list corresponding to the timer slot.
[0182] In one embodiment, when the computer program is executed by the processor, it further performs the following steps: determining the corresponding target message queue based on the target task identifier of the target task to be executed, and pushing a timeout prompt message to the target message queue.
[0183] In one embodiment, a computer program product is provided, including a computer program that, when executed by a processor, performs the following steps:
[0184] Respond to the task processing request, obtain the task execution round number and task execution slot corresponding to the task to be processed, and create the corresponding task to be processed based on the task execution round number and task execution slot;
[0185] Based on the number of task execution rounds and the task execution slot, place the tasks to be processed in the task list corresponding to the timer slot;
[0186] When the timer reaches a slot node, obtain the list of target tasks corresponding to the current slot node;
[0187] Iterate through the target task list and determine the remaining number of operation rounds for each task in the target task list;
[0188] Find the target task in the target task list that has reached the preset number of remaining running rounds, and trigger the target task.
[0189] In one embodiment, when the computer program is executed by the processor, it further implements the following steps: when there is no target task in the target task list with a remaining number of running rounds reaching a preset number of rounds, the remaining number of running rounds is deducted, the remaining number of running rounds is updated, and the process jumps to the step of obtaining the target task list corresponding to the current slot node when the timer reaches the slot node.
[0190] In one embodiment, when the computer program is executed by the processor, it further performs the following steps: responding to a task processing request, determining the task processing duration based on the task identifier carried in the task processing request, and obtaining timer attribute information; obtaining the task execution round number and task execution slot corresponding to the task to be processed based on the task processing duration and timer attribute information, and creating the corresponding task to be processed based on the task execution round number and task execution slot.
[0191] In one embodiment, when the computer program is executed by the processor, it further performs the following steps: determining a first execution duration based on the task processing duration and the timer start time; determining a second execution duration based on the first execution duration and the historical execution duration; determining the number of task execution rounds based on the second execution duration and the total number of timer slots; determining the task execution slot based on the first execution duration and the total number of timer slots; and creating a corresponding task to be processed based on the number of task execution rounds and the task execution slot.
[0192] In one embodiment, when the computer program is executed by the processor, it further performs the following steps: calculating the ratio of the second execution duration to the total number of timer slots, using the ratio as the number of task execution rounds, and taking the modulo of the total number of timer slots based on the first execution duration to obtain the task execution slot.
[0193] In one embodiment, when the computer program is executed by the processor, it further performs the following steps: writing the tasks to be processed into a local buffer queue according to the task execution round number and the task execution slot; retrieving the tasks to be processed from the buffer queue based on a preset time window; and loading the tasks to be processed into the task list corresponding to the timer slot.
[0194] In one embodiment, when the computer program is executed by the processor, it further performs the following steps: determining the corresponding target message queue based on the target task identifier of the target task to be executed, and pushing a timeout prompt message to the target message queue.
[0195] Those skilled in the art will understand that all or part of the processes in the methods of the above embodiments can be implemented by a computer program instructing related hardware. The computer program can be stored in a non-volatile computer-readable storage medium, and when executed, it can include the processes of the embodiments of the above methods. Any references to memory, databases, or other media used in the embodiments provided in this application can include at least one of non-volatile and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetic random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. By way of illustration and not limitation, RAM can take many forms, such as Static Random Access Memory (SRAM) or Dynamic Random Access Memory (DRAM). The databases involved in the embodiments provided in this application may include at least one type of relational database and non-relational database. Non-relational databases may include, but are not limited to, blockchain-based distributed databases. The processors involved in the embodiments provided in this application may be general-purpose processors, central processing units, graphics processing units, digital signal processors, programmable logic devices, quantum computing-based data processing logic devices, etc., and are not limited to these.
[0196] The technical features of the above embodiments can be combined in any way. For the sake of brevity, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
[0197] The embodiments described above are merely illustrative of several implementation methods of this application, and while the descriptions are specific and detailed, they should not be construed as limiting the scope of this patent application. It should be noted that those skilled in the art can make various modifications and improvements without departing from the concept of this application, and these all fall within the protection scope of this application. Therefore, the protection scope of this application should be determined by the appended claims.
Claims
1. A task triggering method, characterized in that, The method includes: In response to a task processing request, the task processing duration is determined based on the task identifier carried in the task processing request, and timer attribute information is obtained; the timer attribute information includes the timer start time, historical execution duration, and the total number of timer slots; the task processing duration refers to the preset time required to process the task. The first execution duration is determined based on the task processing duration and the timer start time; The second execution duration is determined based on the first execution duration and the historical execution duration. The number of task execution rounds is determined based on the second execution duration and the total number of timer slots, and the task execution slot is determined based on the first execution duration and the total number of timer slots. Based on the number of task execution rounds and the task execution slot, create corresponding tasks to be processed; Based on the task execution round number and the task execution slot, the task to be processed is placed in the task list corresponding to the timer slot; the task list is used to maintain the tasks to be processed in the timer slot. When the timer reaches a slot node, obtain the list of target tasks corresponding to the current slot node; Iterate through the target task list to determine the remaining number of operation rounds for each task in the target task list; Find the target task in the target task list that has reached the preset number of remaining operation rounds, and trigger the target task.
2. The method according to claim 1, characterized in that, After traversing the target task list and determining the remaining number of operation rounds for each task in the target task list, the process further includes: When there are no target tasks in the target task list that have reached the preset number of remaining rotations, the remaining number of rotations is deducted and the remaining number of rotations is updated. Jump to the step of obtaining the target task list corresponding to the current slot node when the timer runs to the slot node.
3. The method according to claim 1, characterized in that, The step of determining the number of task execution rounds based on the second execution duration and the total number of timer slots, and determining the task execution slot based on the first execution duration and the total number of timer slots, includes: Calculate the ratio of the second execution duration to the total number of timer slots, use the ratio as the number of task execution rounds, and take the modulo of the total number of timer slots based on the first execution duration to obtain the task execution slot.
4. The method according to claim 1, characterized in that, The step of placing the task to be processed in the task list corresponding to the timer slot according to the task execution round number and the task execution slot includes: Based on the number of task execution rounds and the task execution slot, the task to be processed is written into a local buffer queue. Based on a preset time window, the task to be processed is retrieved from the buffer queue; The task to be processed is loaded into the task list corresponding to the timer slot.
5. The method according to claim 1, characterized in that, The triggering of the target to execute the task includes: The corresponding target message queue is determined based on the target task identifier of the target task to be executed. A timeout notification message is pushed to the target message queue.
6. A task triggering device, characterized in that, The device includes: A response module is used to respond to task processing requests, determine the task processing duration based on the task identifier carried in the task processing request, and obtain timer attribute information. The timer attribute information includes the timer start time, historical execution duration, and the total number of timer slots. The task processing duration refers to the preset time required to process the task. Based on the task processing duration and the timer start time, a first execution duration is determined. Based on the first execution duration and the historical execution duration, a second execution duration is determined. Based on the second execution duration and the total number of timer slots, the number of task execution rounds is determined, and based on the first execution duration and the total number of timer slots, the task execution slot is determined. Based on the number of task execution rounds and the task execution slot, a corresponding task to be processed is created. The placement module is used to place the tasks to be processed into the task list corresponding to the timer slot according to the number of task execution rounds and the task execution slot; the task list is used to maintain the tasks to be processed in the timer slot. The acquisition module is used to obtain the list of target tasks corresponding to the current slot node when the timer runs to the slot node; The traversal module is used to traverse the target task list and determine the number of remaining operation rounds for each task in the target task list. The triggering module is used to find the target execution task in the target task list that has reached a preset number of remaining operation rounds, and trigger the target execution task.
7. The apparatus according to claim 6, characterized in that, The triggering module is also used to: when there is no target task in the target task list that has reached the preset number of remaining rotations, deduct the remaining number of rotations and update the remaining number of rotations; Jump to the step of obtaining the target task list corresponding to the current slot node when the timer runs to the slot node.
8. The apparatus according to claim 6, characterized in that, The response module is further configured to: calculate the ratio of the second execution duration to the total number of timer slots, use the ratio as the number of task execution rounds, and take the modulo of the total number of timer slots based on the first execution duration to obtain the task execution slot.
9. A computer device comprising a memory and a processor, wherein the memory stores a computer program, characterized in that, When the processor executes the computer program, it implements the steps of the method according to any one of claims 1 to 5.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, it implements the steps of the method according to any one of claims 1 to 5.
Citation Information
Patent Citations
Delay task execution method and device and electronic device
CN110032438A