Background task processing method, device, computer equipment and storage medium
By obtaining background task information from the database and judging the running status, exception tasks are added to the list of target task running threads, solving the problem of low manual operation processing efficiency in traditional technology, and automatic takeover and efficient processing of background tasks are realized.
Patent Information
- Application Number
- CN202111294195.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-11-03
- Publication Date
- 2025-02-11
- Estimated Expiration
- 2041-11-03
AI Technical Summary
Traditional background task processing methods require operation and maintenance personnel to manually operate when background tasks run abnormally, resulting in low processing efficiency.
The decision thread obtains the task information of the target background task from the database, judges the task running status, and when the task runs abnormally and the running thread is not the target task running thread corresponding to the decision thread, adds the task to the task list of the target task running thread to achieve Active takeover of the task.
It improves the processing efficiency of running abnormal tasks, reduces manual operations by operation and maintenance personnel, and realizes automatic task takeover and processing.
Smart Images

Figure CN114020512B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of Internet technology, and in particular to a background task processing method, device, computer equipment and storage medium. Background Art
[0002] With the development of Internet technology, a technology that uses a distributed system to process background tasks has emerged. This technology can achieve parallel processing of multiple background tasks by distributing background tasks to different task processing servers.
[0003] In the traditional technology, when a background task runs abnormally on the server, the operation and maintenance personnel need to manually restart the server, and the restarted server continues to run the abnormal background task. However, the above-mentioned background task processing method requires manual operation by the operation and maintenance personnel to realize the processing of the abnormal background task. Therefore, in the current background task processing method, the processing efficiency of the abnormal task is low. Summary of the invention
[0004] Based on this, it is necessary to provide a background task processing method, device, computer equipment and storage medium to address the above technical problems.
[0005] A background task processing method, applied to a decision thread, comprising:
[0006] Acquire task information of the target background task to be processed from the database; the task information includes the task running thread corresponding to the target background task;
[0007] Determine the task running status of the target background task according to the task information;
[0008] When the task running status is that the target background task runs abnormally, and the task running thread is not the target task running thread corresponding to the decision thread, the target background task is added to the task list of the target task running thread so that the target task running thread can process the target background task in the task list.
[0009] In one of the embodiments, the task information includes the task update time of the target background task; determining the task running status of the target background task based on the task information includes: obtaining the thread start time corresponding to the decision thread, and taking the time interval between the thread start time and the task update time as the task update time interval; if the task update time interval is greater than a preset time interval threshold, determining that the task running status is that the target background task is running abnormally.
[0010] In one of the embodiments, after determining that the task running status is that the target background task is running abnormally, it also includes: when the task running status is that the target background task is running abnormally and the task running thread is the target task running thread, deleting the target background task from the task list of the target task running thread, so that the target task running thread cancels processing the target background task in the task list.
[0011] In one of the embodiments, after taking the time interval between the thread start time and the task update time as the task update time interval, it also includes: if the task update time interval is less than or equal to the time interval threshold, determining that the task running status is that the target background task is running normally; when the task running status is that the target background task is running normally, and the task running thread is not the target task running thread corresponding to the decision thread, detecting whether the target background task is carried in the task list of the target task running thread; if the target background task is carried in the task list of the target task running thread, deleting the target background task from the task list of the target task running thread, so that the target task running thread cancels processing the target background task in the task list.
[0012] In one of the embodiments, the task information also includes: the task update time of the target background task and the running breakpoint information of the target background task; before adding the target background task to the task list of the target task running thread, it also includes: updating the task update time of the target background task and the task running thread of the target background task to obtain the updated task information corresponding to the target background task; sending the updated task information to the database so that the database stores the updated task information; adding the target background task to the task list of the target task running thread so that the target task running thread processes the target background task in the task list, includes: adding the target background task to the task list of the target task running thread so that the target task running thread processes the target background task in the task list according to the running breakpoint information.
[0013] In one of the embodiments, determining the task running status of the target background task based on the task information includes: obtaining the thread startup count of the decision thread; judging, based on the thread startup count, whether the decision thread is the first startup of the decision thread after its corresponding task processing server is started; if the decision thread is not the first startup after the task processing server is started, determining the task running status of the target background task based on the task information.
[0014] In one of the embodiments, the determination of whether the decision thread is the first startup of the decision thread after its corresponding task processing server is started also includes: if the decision thread is the first startup after the task processing server is started, then, based on the task running thread, filtering out local background tasks whose task running threads are the target task running threads from the target background tasks; adding the local background tasks to the task list of the target task running thread so that the target task running thread processes the local background tasks in the task list.
[0015] A background task processing device, applied to a decision thread, comprising:
[0016] A task information acquisition module is used to acquire task information of a target background task to be processed from a database; the task information includes a task running thread corresponding to the target background task;
[0017] A running status determination module, used to determine the task running status of the target background task according to the task information;
[0018] A task list processing module is used to add the target background task to the task list of the target task running thread when the task running status is that the target background task runs abnormally and the task running thread is not the target task running thread corresponding to the decision thread, so that the target task running thread can process the target background task in the task list.
[0019] A computer device comprises a memory and a processor, wherein the memory stores a computer program, and the processor implements the steps of the above method when executing the computer program.
[0020] A computer-readable storage medium stores a computer program, which implements the steps of the above method when executed by a processor.
[0021] The above-mentioned background task processing method, device, computer equipment and storage medium obtain the task information of the target background task to be processed from the database through the decision thread; the task information includes the task running thread corresponding to the target background task; the task running status of the target background task is determined according to the task information; when the task running status is that the target background task runs abnormally, and the task running thread is not the target task running thread corresponding to the decision thread, the target background task is added to the task list of the target task running thread, so that the target task running thread can process the target background task in the task list. The present application can determine the running status of the task according to the task information of the target background task through the decision thread. If the task runs abnormally and its running thread is not the target task running thread corresponding to the decision thread, the task can be added to the running list of the target task running thread to take over the processing of the task. Compared with the traditional technology that requires manual operation and processing by operation and maintenance personnel when the background task runs abnormally, the background task processing method of the present application can realize the active takeover of the abnormal running task, thereby improving the processing efficiency of the abnormal running task. BRIEF DESCRIPTION OF THE DRAWINGS
[0022] Figure 1 An application environment diagram of a background task processing method in an embodiment;
[0023] Figure 2 A schematic diagram of a process flow of a background task processing method in one embodiment;
[0024] Figure 3 A schematic diagram of a process for determining a task running state of a target background task in one embodiment;
[0025] Figure 4 A schematic diagram of a process of deleting a target background task from a task list in one embodiment;
[0026] Figure 5 A schematic diagram of a process for determining a task running state of a target background task in one embodiment;
[0027] Figure 6 A schematic diagram of the system architecture of a background task processing system in an application example;
[0028] Figure 7 A schematic diagram of the control flow of a high-availability decision-making thread in an application instance;
[0029] Figure 8 A schematic diagram of the control flow of a background task processing thread in an application instance;
[0030] Fig. 9 is a structural block diagram of a background task processing device in one embodiment;
[0031] Fig.10 FIG. 4 is a diagram showing the internal structure of a computer device in one embodiment. DETAILED DESCRIPTION
[0032] In order to make the purpose, technical solution and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.
[0033] 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.
[0034] The background task processing method provided in this application can be applied to Figure 1 In the application environment shown. Among them, the task processing server 101 communicates with the database 102 through the network, wherein the task processing server 101 includes a target task running thread 1011 for processing background tasks, and a decision thread 1012 for providing decisions for the target task running thread 1011. Specifically, the decision thread 1012 can obtain the task information of the target background task that needs to be processed from the database 102, and the task information can include the task running thread corresponding to the target background task. At the same time, the decision thread 1012 can further use the task information to determine the running state of the target background task. If the target background task runs abnormally and its corresponding task running thread is not the target task running thread 1011, the target background task can be added to the task list of the target task running thread 1011, and the target task running thread 1011 will execute it on its behalf. Among them, the task processing server 101 and the database 102 can be implemented by an independent server or a server cluster composed of multiple servers.
[0035] In one embodiment, Figure 2 As shown, a background task processing method is provided, which is applied to Figure 1 Taking the decision thread 1012 in the example as an example, the following steps are included:
[0036] Step S201 , the decision thread 1012 obtains task information of a target background task to be processed from the database 102 ; the task information includes a task running thread corresponding to the target background task.
[0037] Among them, the decision thread 1012 refers to a thread used to provide decisions for the background task running process. In this embodiment, the task processing server 101 used to process the background task can be composed of the decision thread 1012 and the task running thread corresponding to the decision thread, that is, the target task running thread 1011. The target task running thread 1011 is mainly used to realize the running process of the background task, and the decision thread 1012 is mainly used to provide decisions for the task processing of the target task running thread 1011. For example, which background tasks the target task running thread 1011 needs to execute can be determined by the decision thread 1012. The target background task refers to the background task that needs to be processed. The task-related information of the background task can be stored in the database 102. The task information can include the task running thread corresponding to the target background task. Since the number of task processing servers used to process the background task can be multiple, there can also be multiple task running threads. The database 102 can store the corresponding relationship between each background task and the task running thread used to run the background task as part of the task information of the background task.
[0038] Specifically, the decision thread 1012 can obtain the task information of the target background task that needs to be processed through the database 102. For example, the decision thread 1012 can be started at a certain time interval. When the decision thread 1012 is started, the task information of the target background task that needs to be processed can be read from the database 102, and the task running thread for processing the target background task can be obtained therefrom as the task running thread corresponding to the target background task.
[0039] Step S202: determining the task running status of the target background task according to the task information.
[0040] The task running status refers to the task status of the target background task, which may include whether the target background task is running normally or abnormally. After the decision thread 102 obtains the task information, it can analyze the task information to determine whether the task running status of the target background task is running normally.
[0041] Step S203, when the task running status is that the target background task runs abnormally, and the task running thread is not the target task running thread 1011 corresponding to the decision thread 1012, the target background task is added to the task list of the target task running thread 1011 so that the target task running thread 1011 can run the target background task in the task list.
[0042] The target task running thread 1011 refers to the task running thread for which the decision is provided by the decision thread 1012. Since there are multiple task processing servers for running background tasks in this embodiment, and each task processing server can carry corresponding decision threads and task running threads, the target task running thread 1011 is the task running thread in the same task processing server as the decision thread 1012. For example, the task processing servers connected to the database 102 may include: server A, server B and server C, wherein server A includes decision thread A and task running thread A, server B includes decision thread B and task running thread B, and server C includes decision thread C and task running thread C, then if decision thread A is used as decision thread 1012, then the target task running thread corresponding to decision thread 1012 is task running thread A, and if decision thread B is used as decision thread 1012, then the target task running thread corresponding to decision thread 1012 is task running thread B, and so on. The task list refers to the list of tasks that the target task running thread 1011 needs to execute. The target task running thread 1011 can process the background tasks carried in the task list, but the target task running thread 1011 does not process the background tasks not carried in the task list.
[0043] Specifically, if the task running status is that the target background task runs abnormally, and the task running thread is not the target task running thread 1011 corresponding to the decision thread 1012, that is, the target background task runs abnormally on the original task running thread, then the decision thread 1012 can add the above-mentioned target background task to the running task list of the target task running thread 1011, and the target task running thread 1011 will process the target background task.
[0044] For example, a target background task runs abnormally on task running thread B. When decision thread A detects that the running status of the target background task is task running abnormality, since task running thread B is not the target task running thread corresponding to decision thread A, decision thread A can add the target background task to the task list of the target task running thread, that is, add it to the task list of task running thread A, and task running thread A will process the target background task on its behalf.
[0045] In the above-mentioned background task processing method, the decision thread 1012 obtains the task information of the target background task to be processed from the database 102; the task information includes the task running thread corresponding to the target background task; the task running state of the target background task is determined according to the task information; when the task running state is that the target background task runs abnormally, and the task running thread is not the target task running thread 1011 corresponding to the decision thread 1012, the target background task is added to the task list of the target task running thread 1011, so that the target task running thread 1011 can process the target background task in the task list. The present application can determine the running state of the task according to the task information of the target background task through the decision thread 1012. If the task runs abnormally and its running thread is not the target task running thread 1011 corresponding to the decision thread 1012, the task can be added to the running list of the target task running thread 1011 to take over the running of the task. Compared with the traditional technology that requires manual operation and processing by operation and maintenance personnel when the background task runs abnormally, the background task processing method of the present application can realize the active takeover of the abnormal running task, thereby improving the processing efficiency of the abnormal running task.
[0046] In one embodiment, the task information includes the task update time of the target background task; Figure 3 As shown, step S202 further includes:
[0047] Step S301, obtaining the thread start time corresponding to the decision thread 1012, and taking the time interval between the thread start time and the task update time as the task update time interval.
[0048] The task update time refers to the update time that the task running thread returns to the database 102 for the last time when the background task is processed by the task running thread, which can be used to indicate that at the time point of the task update time, the background task is still being processed in the task running thread. The thread start time refers to the start time of the decision thread 1012. In this embodiment, the task information is obtained only when the decision thread 1012 is started, so the thread start time can also be used to indicate the current time.
[0049] Specifically, when the decision thread 1012 is started, the current time can be obtained as the thread start time, and the update time of the last feedback of the target background task can be obtained from the target background task. Then, the decision thread 1012 can calculate the time interval between the thread start time and the task update time as the task update time interval, that is, the interval between the current time and the last update time of the target background task.
[0050] Step S302: If the task update time interval is greater than a preset time interval threshold, the task running status is determined to be that the target background task is running abnormally.
[0051] If the task update time interval is greater than a pre-set time interval threshold, it may indicate that the task running thread used to process the target background task has not updated the target background task for a long time, which may indicate that the target background task cannot continue to be processed in the task running thread, that is, the task running processing of the target background task by the task running thread is in an abnormal state. Therefore, the decision thread 1012 can determine that the task running status of the target background task is abnormal target background task operation.
[0052] In the above embodiment, the decision thread 1012 can determine the task running status of the target background task through the relationship between the task update time interval and the time interval threshold, and the task update time interval can be determined by the task update time of the target background task, thereby realizing intelligent detection of the task running status and improving the efficiency of obtaining the abnormal task running status.
[0053] Furthermore, after step S302, it may also include: when the task running status is that the target background task runs abnormally, and the task running thread is the target task running thread, deleting the target background task from the task list of the target task running thread, so that the target task running thread cancels the target background task in the processing task list.
[0054] After determining that the target background task is running abnormally, if the task running thread responsible for processing the target background task is the target task running thread 1011 corresponding to the decision thread 1012, it indicates that the target background task is running and processing abnormally on the target task running thread 1011. Therefore, the processing of the target background task on the target task running thread 1011 can be canceled, and other task running threads can take over the processing. By deleting the above-mentioned target background task from the task list of the target task running thread 1011, the target task running thread 1011 can be canceled from continuing to process the target background task.
[0055] In this embodiment, if the decision thread 1012 determines that the target background task with abnormal task execution is being processed on the target task execution thread 1011 corresponding to the decision thread 1012, the target background task can be deleted from the task list of the target task execution thread 1011, thereby canceling the task processing of the target background task by the target task execution thread 1011, thereby saving the computing resources of the target task execution thread 1011.
[0056] In one embodiment, Figure 4 As shown, after step S301, the following steps may also be included:
[0057] Step S401: If the task update time interval is less than or equal to the time interval threshold, it is determined that the task running status is that the target background task runs normally.
[0058] If the task update time interval is less than or equal to the time interval threshold, it indicates that the task running thread processing the target background task is updating the target background task normally. At this time, the decision thread 1012 can determine that the task running status of the target background task is normal task running.
[0059] Step S402, when the task running status is that the target background task is running normally, and the task running thread is not the target task running thread corresponding to the decision thread, detect whether the task list of the target task running thread carries the target background task;
[0060] Step S403: if the target task running thread has a target background task in its task list, the target background task is deleted from the target task running thread's task list, so that the target task running thread cancels the target background task in the task list.
[0061] If the target background task runs normally and the task running thread is not the target task running thread 1011 corresponding to the decision thread 1012, it indicates that the target background task is processed normally in other task running threads. At this time, in order to avoid the same target background task being processed by multiple task running threads, the decision thread 1012 can query whether the task list of the target task running thread 1011 contains the above-mentioned target background task. If the task list carries the target background task, the decision thread 1012 can delete the above-mentioned target background task from the task list, so that the target task running thread can cancel the processing of the above-mentioned target background task.
[0062] In addition, if the target background task runs normally and the task running thread is the target task running thread 1011 corresponding to the decision thread 1012, it indicates that the target background task is being processed normally on the target task running thread 1011. At this time, the decision thread 1012 does not need to perform any processing on the target background task, thereby obtaining the task information of the next target background task to be processed.
[0063] In this embodiment, if it is determined that the target background task is running normally and the task running thread is not the target task running thread 1011 corresponding to the decision thread 1012, it can be detected whether the task list of the target task running thread 1011 contains the above-mentioned target background task. If it is contained, the target background task is deleted from the task list to ensure that the target background task is not repeatedly processed by multiple task running threads, thereby saving the computing resources of the target task running thread 1011.
[0064] In one embodiment, the task information also includes: the task update time of the target background task and the running breakpoint information of the target background task; before step S203 adds the target background task to the task list of the target task running thread, it can also include: updating the task update time of the target background task and the task running thread of the target background task to obtain the updated task information corresponding to the target background task; sending the updated task information to the database 102 so that the database 102 stores the updated task information; step S203 can further include: adding the target background task to the task list of the target task running thread 1011, so that the target task running thread 1011 processes the target background task in the task list according to the running breakpoint information.
[0065] The running breakpoint information refers to the breakpoint information of the target background task, which can be used to indicate the task processing progress of the target background task. In this embodiment, the task information of the target background task can also include the running breakpoint information. In step S203, when the decision thread 1012 determines that the target background task is running abnormally and the task running thread is not the target task running thread 1011, the decision thread 1012 can take over the target background task. When taking over, the decision thread 1012 first needs to update the task information stored in the database 102, that is, by refreshing the task update time and task running thread of the target background task, the updated character information is obtained, that is, after the task information is updated, it is sent to the database 102 for storage. After the task information is updated, the decision thread 1012 adds the above-mentioned target background task to the task list of the target task running thread 1011, and the target task running thread 1011 continues to process the target background task according to the breakpoint information.
[0066] In the above embodiment, when the decision thread 1012 takes over the target background task, the task information of the target background task can also be updated, and the updated task information obtained after the update is sent to the database 102 for storage, so that the database 102 can store the latest task information of the target background task at any time, and then the target background task is processed by the target task running thread 1011. At this time, the target task running thread 1011 can also use the breakpoint information of the target background task to realize the takeover processing of the target background task, so that the breakpoint continuation processing of the target background task can be realized without reprocessing the target background task, thereby further improving the processing efficiency of the target background task.
[0067] In one embodiment, Figure 5 As shown, step S202 may further include:
[0068] Step S501, obtaining the thread startup times of the decision thread 1012;
[0069] Step S502 , judging whether the decision thread 1012 is started for the first time after its corresponding task processing server 101 is started, based on the number of thread startups.
[0070] Among them, the thread startup number refers to the number of startups of the decision thread 1012. In this embodiment, each time the decision thread 1012 is started, the startup number of the decision thread 1012 will be recorded and counted. Each time it is started, the startup number of the decision thread 1012 is added by 1 and stored. After the task processing server 101 is shut down, the thread startup number can be cleared. Therefore, the thread startup number can be used to determine whether the decision thread 1012 is started for the first time after the task processing server 101 is started. If the thread startup number is 1, it indicates that the decision thread 1012 is started for the first time after the task processing server 101 is started, and if the thread startup number is 2, it indicates that the decision thread 1012 is not started for the first time after the task processing server 101 is started.
[0071] Step S503, if the decision thread 1012 is not started for the first time after the task processing server 101 is started, the task running state of the target background task is determined according to the task information.
[0072] In step S502, the decision thread 1012 determines that this is not the first startup of the task processing server 101, then the process of determining the task running status of the target background task according to the task information in step S202 can be executed to determine whether it is necessary to take over the processing of the target background task.
[0073] In this embodiment, the decision thread 1012 can determine whether the decision thread 1012 is started for the first time after the task processing server 101 is started by the number of times the thread is started. If not, the step of determining the task running status of the target background task is executed, thereby improving the intelligence of the target background task supervision.
[0074] Furthermore, after step S502, it can also include: if the decision thread 1012 is started for the first time after the task processing server 101 is started, then according to the task running thread, the local background task whose task running thread is the target task running thread is filtered out from the target background tasks; the local background task is added to the task list of the target task running thread, so that the target task running thread 1011 runs the local background task in the task list.
[0075] Local background tasks refer to background tasks that need to be processed by the target task running thread 1011 after the task processing server 101 is started. In this embodiment, if the decision thread 1012 is started for the first time after the task processing server 101 is started, then there is no need to take over the target background task. Therefore, at this time, the decision thread 1012 can directly filter out the target background task whose task running thread is the target task running thread 1011 from the task information of multiple target background tasks that need to be executed, as the local background task, and take over the local background task. The task information of the local background task can be updated first, for example, the task update time and task running thread of the local background task can be updated, and the updated task information can be stored in the database 102, and then the target background task is added to the task list of the target task running thread 1011, so that the target task running thread 1011 can process the target background task in the above task list.
[0076] In this embodiment, if the decision thread 1012 is started for the first time after the task processing server 101 is started, then the decision thread 1012 does not need to consider the takeover of background tasks, so there is no need to determine the task running status of the target background task, but to filter out the local background tasks that need to be processed by the target task running thread 1011 from the target background tasks, and by adding the local background tasks to the task list of the target task running thread 1011, the target task running thread 1011 can process the above-mentioned local background tasks to ensure the normal processing of the local background tasks.
[0077] In an application example, a distributed resident background task high-availability system and method is also provided. Through the heartbeat connection between the background tasks of each server in the cluster and the high-availability decision thread, the survival status of each background task in the cluster is intelligently detected, the background tasks in the thread pool are started and stopped, and the tasks are taken over and exited, thereby improving the continuity of the tasks.
[0078] First, create a background task information table in the database, and use the background task name + running node as the unique index to store the background task information. The main fields of this table are shown in Table 1:
[0079] Field Chinese name Remark Background task name PK Running a Node PK, marking the server where the background task runs Breakpoint information Record the breakpoint information of background tasks so that they can be resumed when taking over. Last updated The last update time of the task information, which is also the last heartbeat time of the task.
[0080] Table 1 Background task information field diagram
[0081] At the same time, this application example also provides two main control processes: high-availability decision thread and background task processing thread. The high-availability decision process is mainly used for the heartbeat of background tasks and intelligent decision-making takeover. The background task processing thread mainly sends heartbeat data for use by the decision process, which can be applied to Figure 6In the background task processing system shown, the specific control is as follows:
[0082] (1) High availability decision thread:
[0083] Step 1: Control process such as Figure 7 As shown, the thread is started once at a certain interval. After starting, the number of starts is recorded to determine whether it is the first start, and the task information is obtained from the database, and each task is processed in a loop.
[0084] Step 2: When the thread is started for the first time after the server is started, it will not take over the tasks of other servers, but only process the tasks of the server whose running node is this server.
[0085] If there are tasks that need to be started, first refresh the running nodes of the database task information, and finally update the time to ensure that the update is successful before taking over and starting the local task.
[0086] After startup, add the task name to the task running list in local memory.
[0087] Step 3: If the thread is not started for the first time after the server is started, determine whether the running node is the local machine.
[0088] If it is the local machine and the last update time is within a certain interval, it means that the task is normal. Skip the task processing and process the next task.
[0089] If it is the local machine, but the last update time exceeds the specified interval, it means that the task has not updated the heartbeat for a long time. It is necessary to cancel the local task and wait for other servers to take over. Therefore, cancel the task from the task thread pool and delete the task from the task list in the local memory.
[0090] If the running node is not the local machine and the last update time is within a certain interval, it means that the task is running normally on other servers. Then you need to check the task list in the local memory to see if the task exists. If so, you need to cancel the local task and delete it from the list. If not, skip it.
[0091] If the running node is not local and the last update time exceeds the specified interval, it means that an exception has occurred on the task on another server and task takeover is required. When taking over, first refresh the running node of the database task information and the last update time to ensure that the update is successful, and then start the local task according to the breakpoint information. After starting, add the task name to the task running list in the local memory.
[0092] (2) Background task processing thread:
[0093] Control process such as Figure 8As shown, before starting the business processing of the background task, it is necessary to check the task running list in the local memory.
[0094] If the task is not in the running list, it means that the machine cannot continue to process the task, and the task will exit normally.
[0095] If the task is in the running list, it means that the machine can continue to process the task, and business processing will be carried out.
[0096] After the processing is completed, the heartbeat information (last update time) and breakpoint information are updated to the task information table. Please note that the WHERE condition needs to carry the local flag as the condition for running the node to confirm that the task is still being processed locally at the current moment. If the update fails, the task is exited. If the update is successful, the control flow of the background task continues.
[0097] The above-mentioned distributed resident background task high availability system and method can intelligently take over the servers in the cluster when the background task fails abnormally, thereby improving its continuity solution. Compared with the traditional background task monitoring and manual restart by operation and maintenance personnel in the event of an abnormality, the emergency response time is significantly improved and the manual operation of operation and maintenance personnel is also reduced. At the same time, intelligent takeover supports breakpoint continuation, which also reduces the work of repairing and adjusting data in many background task abnormal scenarios.
[0098] It should be understood that, although the various steps in the flowchart of the present application are displayed in sequence according to the indication of the arrows, these steps are not necessarily executed in sequence in the order indicated by the arrows. Unless there is a clear description in this article, the execution of these steps is not strictly limited in order, and these steps can be executed in other orders. Moreover, at least a portion of the steps in the figure may include multiple steps or multiple stages, and these steps or stages are not necessarily executed at the same time, but can be executed at different times, and the execution order of these steps or stages is not necessarily to be carried out in sequence, but can be executed in turn or alternately with other steps or at least a portion of the steps or stages in other steps.
[0099] In one embodiment, Fig. 9 As shown, a background task processing device is provided, which is applied to a decision thread, and includes: a task information acquisition module 901, a running state determination module 902 and a task list processing module 903, wherein:
[0100] The task information acquisition module 901 is used to acquire the task information of the target background task to be processed from the database; the task information includes the task running thread corresponding to the target background task;
[0101] The running state determination module 902 is used to determine the task running state of the target background task according to the task information;
[0102] The task list processing module 903 is used to add the target background task to the task list of the target task running thread when the task running status is that the target background task runs abnormally and the task running thread is not the target task running thread corresponding to the decision thread, so that the target task running thread can process the target background task in the task list.
[0103] In one embodiment, the task information includes the task update time of the target background task; the running status determination module 902 is further used to obtain the thread start time corresponding to the decision thread, and use the time interval between the thread start time and the task update time as the task update time interval; if the task update time interval is greater than the preset time interval threshold, the task running status is determined to be that the target background task is running abnormally.
[0104] In one embodiment, the task list processing module 903 is also used to delete the target background task from the task list of the target task running thread when the task running status is that the target background task runs abnormally and the task running thread is the target task running thread, so that the target task running thread cancels the processing of the target background task in the task list.
[0105] In one embodiment, the running status determination module 902 is also used to determine that the task running status is that the target background task is running normally if the task update time interval is less than or equal to the time interval threshold; the task list processing module 903 is also used to detect whether the task list of the target task running thread carries the target background task when the task running status is that the target background task is running normally and the task running thread is not the target task running thread corresponding to the decision thread; if the task list of the target task running thread carries the target background task, the target background task is deleted from the task list of the target task running thread, so that the target task running thread cancels the processing of the target background task in the task list.
[0106] In one embodiment, the task information also includes: the task update time of the target background task and the running breakpoint information of the target background task; the task list processing module 903 is also used to update the task update time of the target background task and the task running thread of the target background task to obtain the updated task information corresponding to the target background task; send the updated task information to the database so that the database stores the updated task information; add the target background task to the task list of the target task running thread, so that the target task running thread processes the target background task in the task list according to the running breakpoint information.
[0107] In one embodiment, the running status determination module 902 is further used to obtain the thread startup times of the decision thread; based on the thread startup times, determine whether the decision thread is the first startup of the decision thread after its corresponding task processing server is started; if the decision thread is not the first startup after the task processing server is started, determine the task running status of the target background task based on the task information.
[0108] In one embodiment, the task list processing module 903 is also used to filter out local background tasks whose task running threads are target task running threads from the target background tasks according to the task running threads if the decision thread is started for the first time after the task processing server is started; and add the local background tasks to the task list of the target task running thread so that the target task running thread processes the local background tasks in the task list.
[0109] For the specific definition of the background task processing device, please refer to the definition of the background task processing method above, which will not be repeated here. The various modules in the above-mentioned background task processing device can be implemented in whole or in part by software, hardware and a combination thereof. The above-mentioned modules can be embedded in or independent of the processor in the computer device in the form of hardware, or can be stored in the memory of the computer device in the form of software, so that the processor can call and execute the operations corresponding to the above modules.
[0110] In one embodiment, a computer device is provided. The computer device may be a server, and its internal structure diagram may be as follows: Fig.10 As shown. The computer device includes a processor, a memory and a network interface connected through a system bus. Among them, the processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program and a database. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The database of the computer device is used to store task information data. The network interface of the computer device is used to communicate with an external terminal through a network connection. When the computer program is executed by the processor, a background task processing method is implemented.
[0111] Those skilled in the art will understand that Fig.10 The structure shown in the figure is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.
[0112] In one embodiment, a computer device is further provided, including a memory and a processor, wherein a computer program is stored in the memory, and the processor implements the steps in the above method embodiments when executing the computer program.
[0113] In one embodiment, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the steps in the above-mentioned method embodiments are implemented.
[0114] Those of ordinary skill in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to memory, storage, database 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 or optical memory, etc. Volatile memory can include random access memory (RAM) or external cache memory. As an illustration and not limitation, RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM).
[0115] The technical features of the above embodiments may be combined arbitrarily. To make the description concise, 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.
[0116] The above-mentioned embodiments only express several implementation methods of the present application, and the descriptions thereof are relatively specific and detailed, but they cannot be understood as limiting the scope of the invention patent. It should be pointed out that, for a person of ordinary skill in the art, several variations and improvements can be made without departing from the concept of the present application, and these all belong to the protection scope of the present application. Therefore, the protection scope of the patent of the present application shall be subject to the attached claims.
Claims
1. A background task processing method, characterized in that: Applied to a decision thread, the task processing server includes the decision thread and a target task running thread corresponding to the decision thread, and the method includes: Acquire task information of the target background task to be processed from the database; the task information includes the task running thread corresponding to the target background task and the task update time of the target background task; Determining the task running state of the target background task according to the task information, including: obtaining the thread start time corresponding to the decision thread, and taking the time interval between the thread start time and the task update time as the task update time interval; if the task update time interval is greater than a preset time interval threshold, determining that the task running state is that the target background task is running abnormally; When the task running status is that the target background task runs abnormally, and the task running thread is not the target task running thread corresponding to the decision thread, the target background task is added to the task list of the target task running thread, so that the target task running thread can process the target background task in the task list; When the task running status is that the target background task runs abnormally, and the task running thread is the target task running thread, the target background task is deleted from the task list of the target task running thread, so that the target task running thread cancels processing of the target background task in the task list.
2. The method according to claim 1, characterized in that After taking the time interval between the thread start time and the task update time as the task update time interval, the method further includes: If the task update time interval is less than or equal to the time interval threshold, determining that the task running status is that the target background task runs normally; When the task running status is that the target background task is running normally, and the task running thread is not the target task running thread corresponding to the decision thread, detecting whether the target background task is carried in the task list of the target task running thread; If the target background task is included in the task list of the target task running thread, the target background task is deleted from the task list of the target task running thread, so that the target task running thread cancels the processing of the target background task in the task list.
3. The method according to claim 1, characterized in that: The task information also includes the running breakpoint information of the target background task; Before adding the target background task to the task list of the target task running thread, the method further includes: The task update time of the target background task and the task running thread of the target background task are updated to obtain the updated task information corresponding to the target background task; Sending the update task information to the database so that the database stores the update task information; The step of adding the target background task to the task list of the target task running thread so that the target task running thread can process the target background task in the task list includes: The target background task is added to the task list of the target task running thread, so that the target task running thread processes the target background task in the task list according to the running breakpoint information.
4. The method according to claim 1, characterized in that The step of determining the task running state of the target background task according to the task information further includes: Obtaining the number of times the decision thread is started; According to the number of times the thread is started, determining whether the decision thread is started for the first time after the corresponding task processing server is started; If the decision thread is not started for the first time after the task processing server is started, the task running state of the target background task is determined according to the task information.
5. The method according to claim 4, characterized in that The determining whether the decision thread is started for the first time after the corresponding task processing server is started also includes: If the decision thread is started for the first time after the task processing server is started, then according to the task running thread, a local background task whose task running thread is the target task running thread is selected from the target background tasks; The local background task is added to the task list of the target task running thread, so that the target task running thread processes the local background tasks in the task list.
6. A background task processing device, characterized in that: Applied to a decision thread, the task processing server includes the decision thread and a target task running thread corresponding to the decision thread, and the device includes: A task information acquisition module is used to acquire task information of a target background task to be processed from a database; the task information includes a task running thread corresponding to the target background task and a task update time of the target background task; A running status determination module, used to determine the task running status of the target background task according to the task information; The running state determination module is specifically used to obtain the thread start time corresponding to the decision thread, and use the time interval between the thread start time and the task update time as the task update time interval; if the task update time interval is greater than a preset time interval threshold, then determine that the task running state is that the target background task is running abnormally; Task list processing module, used to: When the task running status is that the target background task runs abnormally, and the task running thread is not the target task running thread corresponding to the decision thread, the target background task is added to the task list of the target task running thread, so that the target task running thread can process the target background task in the task list; When the task running status is that the target background task runs abnormally, and the task running thread is the target task running thread, the target background task is deleted from the task list of the target task running thread, so that the target task running thread cancels processing of the target background task in the task list.
7. 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, the steps of the method according to any one of claims 1 to 5 are implemented.
8. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 5 are implemented.
Citation Information
Patent Citations
Task running status information acquisition method and device
CN106649053A
Abnormal node task processing method and device based on cluster node mutual inspection
CN112035326A