A task processing method and device
By setting lock resources and judging task status in task processing, the problem of mutual exclusion in multi-node task execution in the fintech field is solved, improving the efficiency and accuracy of task processing and simplifying the task processing process.
Patent Information
- Application Number
- CN201910555830.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2019-06-25
- Publication Date
- 2026-01-23
- Estimated Expiration
- 2039-06-25
AI Technical Summary
In the fintech field, when multiple nodes in a distributed system execute the same task, there is a problem of mutual exclusion in task execution, which leads to duplicate processing or waste of resources. Existing technologies such as Quartz system have complex logic and are difficult to meet timeliness requirements, affecting task processing efficiency.
By setting lock resources corresponding to tasks, determining the lock status and start time of tasks, and deciding whether to execute tasks, duplicate processing and resource waste are avoided. Simple logical judgment methods are used to improve task processing efficiency.
It improves the accuracy and efficiency of task processing, simplifies the task processing flow, reduces system pressure, and enhances the flexibility and accuracy of task processing.
Smart Images

Figure CN110275766B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of financial technology (Fintech), and more particularly to a task processing method and apparatus. Background Technology
[0002] With the development of computer technology, more and more technologies are being applied in the financial sector, and the traditional financial industry is gradually transforming into Fintech. However, due to the security and real-time requirements of the financial industry, Fintech places higher demands on technology. The financial industry typically involves batch processing jobs. Due to the nature of the financial industry, it is necessary to ensure the accuracy, security, and non-loss of processing tasks as much as possible. This requires the financial industry to flexibly adjust the tasks to be processed according to actual operational requirements when executing batch processing jobs. Therefore, designing a horizontally scalable and highly fault-tolerant task processing method is crucial for the development of the financial industry.
[0003] Generally, distributed systems can be used in the financial sector to process batch data. Since distributed systems have multiple nodes, situations inevitably arise where multiple nodes execute the same task. However, many scenarios in the financial sector require ensuring the mutual exclusion of task execution, such as batch deduction tasks and account reconciliation tasks. In batch deduction tasks, if multiple nodes do not execute the batch deduction task mutually exclusively, they may deduct money from the same account repeatedly, leading to errors. Similarly, in account reconciliation tasks, if multiple nodes do not execute the reconciliation task mutually exclusively, they may execute the reconciliation simultaneously. However, the resources for account reconciliation tasks are limited. Therefore, multiple nodes may need to compete for resources, and nodes that fail to acquire resources must wait for other nodes to complete their reconciliation tasks before repeating them, potentially leading to resource waste.
[0004] Quartz is a commonly used system for resolving the aforementioned mutual exclusion problem. Specifically, Quartz allows configuring timer information in a database and supports setting up multiple nodes in a cluster. By creating a complex scheduling schedule, multiple nodes compete for resources, ensuring one task corresponds to one node. Conversely, if a node in the Quartz system fails at a certain time, Quartz can call other nodes to handle the tasks associated with the failed node, ensuring each task completes successfully. Thus, by setting timer information and a scheduling schedule for each task, Quartz ensures one task corresponds to one node, resolving the mutual exclusion problem caused by multiple nodes processing the same task. However, Quartz's implementation logic is complex, and the fintech field involves a large number of batch tasks. Using such complex logic for timing and scheduling each task individually might fail to meet timeliness requirements, leading to poor task processing efficiency.
[0005] In summary, there is an urgent need for a task processing method to improve the efficiency of task processing. Summary of the Invention
[0006] This invention provides a task processing method to improve task processing efficiency.
[0007] In a first aspect, an embodiment of the present invention provides a task processing method, the method comprising:
[0008] The system receives a call request for a first task, which includes an identifier for the first task. Further, it acquires at least one task from a preset database and the lock resources corresponding to each task. If a target task matching the identifier of the first task exists among the at least one task, it determines whether to execute the first task based on the lock resources corresponding to the target task. The lock resources corresponding to the at least one task are used to indicate the state of the at least one task, which is either locked or unlocked.
[0009] In the above design, by setting the lock resource corresponding to the task, it is possible to determine whether the task is currently in a locked or unlocked state based on the lock resource corresponding to the task, and then determine whether to execute the task based on the task's state. Using this method, when the call request of the first task is received, it is only necessary to acquire the lock resource corresponding to the first task to determine whether to execute the first task. The operation is simple and easy to implement. By using simple logic to implement the task processing process, the efficiency of task processing can be improved.
[0010] In one possible design, determining whether to execute the first task based on the lock resource corresponding to the target task includes: determining the state of the target task based on the lock resource corresponding to the target task; if the state of the target task is unlocked, and if the lock resource corresponding to the target task is an initial lock resource, then execute the first task; if the lock resource corresponding to the target task is a lock resource set for the target task when executing the target task, then determining whether to execute the first task based on the start time of the target task and the start time of the first task; if the state of the target task is locked, obtaining the preset termination time corresponding to the target task from the lock resource corresponding to the target task; if the current time is greater than the preset termination time corresponding to the target task, then execute the first task.
[0011] In the above design, if the target task is in a locked state, it means that the target task is currently being executed. Therefore, the preset termination time of the target task and the current time can be used to determine whether the target task has timed out (timeout means that it should have been completed but has not yet been completed). If the target task times out, it means that the target task execution is abnormal, and the first task can be executed. If the target task does not time out, it means that the target task is being executed normally, and the first task does not need to be executed. If the target task is in an unlocked state, it means that the target task is not currently being executed. Therefore, the lock resource corresponding to the target task can be used to determine whether the target task has been executed before. If the target task has not been executed before, the first task can be executed. If the target task has been executed and completed, the start time of the target task and the start time of the first task can be used to determine whether the first task should be executed. By adopting the logical judgment method in the above design, the processing of the first task can be controlled, and the implementation process of the logical judgment method is relatively simple and easy to implement.
[0012] In one possible design, determining whether to execute the first task based on the start time of the target task and the start time of the first task includes: determining the start time difference between the target task and the first task based on the start time of the target task and the start time of the first task; if the start time difference between the target task and the first task is greater than a preset duration, then the first task is executed.
[0013] In the above design, if the target task has been completed, the start time difference between the first task and the target task can be determined based on the start time of the first task and the start time of the target task. If the start time difference is short, the first task is not executed; if the start time difference is long, the first task can be executed. In this way, by judging the length of the start time difference between two identical tasks, the problem of two tasks being called at the same time with different start times due to network latency can be avoided, thereby avoiding the repeated processing of the same tasks, reducing system pressure, and improving task processing efficiency.
[0014] In one possible design, the method further includes: updating the state of the target task in the lock resource corresponding to the target task to a locked state, and updating the node identifier, start time, and preset termination time of the target task in the lock resource corresponding to the target task according to the node identifier of the first task, the start time of the first task, and the preset execution duration of the first task.
[0015] In the above design, the lock resources corresponding to the target task can be updated while the first task is being executed. This ensures the real-time availability of the lock resources for the target task, and the accuracy of task processing can be improved by executing subsequent task processing based on the real-time lock resources.
[0016] In one possible design, the method further includes: if the first task is completed before the preset termination time of the target task, then the state of the target task in the lock resource corresponding to the target task is updated to an unlocked state.
[0017] In the above design, if the first task is completed before the preset termination time, the lock resource corresponding to the target task can be released (that is, the state of the target task in the lock resource corresponding to the target task is updated to the unlocked state). In this way, flexible management of lock resources can be achieved and the accuracy of lock resources can be improved.
[0018] In one possible design, the method further includes: if there is no target task matching the identifier of the first task among the at least one task, then execute the first task and set the lock resource corresponding to the first task.
[0019] Secondly, an embodiment of the present invention provides a task processing apparatus, the apparatus comprising:
[0020] The transceiver module is used to receive the invocation request of the first task, wherein the invocation request of the first task includes the identifier of the first task.
[0021] The processing module is used to obtain at least one task and the lock resources corresponding to the at least one task from a preset database. If there is a target task in the at least one task that matches the identifier of the first task, then it is determined whether to execute the first task based on the lock resources corresponding to the target task.
[0022] Optionally, the processing module is specifically configured to: determine the state of the target task based on the lock resource corresponding to the target task, wherein the state of the target task is locked or unlocked; further, when the state of the target task is unlocked, if the lock resource corresponding to the target task is an initial lock resource, then execute the first task; if the lock resource corresponding to the target task is a lock resource set for the target task when executing the target task, then determine whether to execute the first task based on the start time of the target task and the start time of the first task; when the state of the target task is locked, obtain the preset termination time corresponding to the target task from the lock resource corresponding to the target task, and if the current time is greater than the preset termination time corresponding to the target task, then execute the first task.
[0023] In one possible design, the processing module is specifically used to: determine the start time difference between the target task and the first task based on the start time of the target task and the start time of the first task; if the start time difference between the target task and the first task is greater than a preset duration, then execute the first task.
[0024] In one possible design, the device further includes an update module, which is used to: update the state of the target task in the lock resource corresponding to the target task to a locked state, and update the node identifier, start time, and preset termination time of the target task in the lock resource corresponding to the target task according to the node identifier of the first task, the start time of the first task, and the preset execution duration of the first task.
[0025] In one possible design, the update module is further configured to: if the first task is completed before the preset termination time of the target task, update the state of the target task in the lock resource corresponding to the target task to an unlocked state.
[0026] In one possible design, the processing module is further configured to: if there is no target task matching the identifier of the first task among the at least one task, then execute the first task and set the lock resource corresponding to the first task.
[0027] Thirdly, embodiments of the present invention provide a computer-readable storage medium including instructions that, when executed on a computer, cause the computer to perform the task processing method as described in the first aspect or any of the first aspects above.
[0028] Fourthly, an embodiment of the present invention provides a computer program product that, when run on a computer, causes the computer to perform the task processing method as described in the first aspect or any of the first aspects above.
[0029] These or other aspects of the invention will become more apparent from the following description of the embodiments. Attached Figure Description
[0030] To more clearly illustrate the technical solutions in the embodiments of the present invention, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0031] Figure 1a This is a schematic diagram of the system architecture of a server cluster system provided in an embodiment of the present invention;
[0032] Figure 1b This is a schematic diagram of the system architecture of another server cluster system provided in an embodiment of the present invention;
[0033] Figure 2 This is a flowchart illustrating a task processing method provided in an embodiment of the present invention.
[0034] Figure 3 A schematic diagram of the hardware implementation process of a task processing method provided in an embodiment of the present invention;
[0035] Figure 4 This is a schematic diagram of a task processing device provided in an embodiment of the present invention. Detailed Implementation
[0036] To make the objectives, technical solutions, and advantages of this invention clearer, the invention will be further described in detail below with reference to the accompanying drawings. Obviously, the described embodiments are only a part of the embodiments of this invention, and not all of them. Based on the embodiments of this invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this invention.
[0037] Fintech refers to a new innovative technology that integrates information technology into the financial field. By using advanced information technology to assist in financial operations, transaction execution, and financial system improvements, it can enhance the processing efficiency and business scale of the financial system, while reducing costs and financial risks.
[0038] In the fintech field, multiple business systems are typically set up, such as marketing systems, loan systems, and insurance systems. Each system is responsible for executing its related business. Taking a marketing system as an example, it can generally generate thousands or even tens of thousands of transactions daily. Consequently, the marketing system needs to manage a large number of transactions, such as verifying daily inflows and validating user information. Therefore, each business system may need to handle a large number of tasks daily. Thus, the fintech field requires batch processing to handle these large volumes of tasks. Due to the large number of tasks processed by batch processing and the wide range of financial applications, it is essential to ensure that the tasks processed by batch processing are accurate, secure, and without data loss.
[0039] Generally, in order to accurately process a large number of tasks, the fintech field can set up server cluster systems. By using multiple servers in the server cluster system to process a large number of tasks in parallel, the efficiency of task processing can be improved.
[0040] Figure 1a This is a schematic diagram of the system architecture of a server cluster system provided in an embodiment of the present invention, such as... Figure 1a As shown, the server cluster system may include at least one server, such as server 101, server 102, server 103, and server 104. Any two servers among servers 101 to 104 can be connected. Taking servers 101 and 102 as an example, server 101 can connect to server 102 via a wired connection or a wireless connection; the specific connection method is not limited.
[0041] Taking the marketing business system's processing of tasks one through five as an example, in specific implementation, the marketing business system can send tasks one through five to the server cluster system. Correspondingly, if the server cluster system receives tasks one through five, it can allocate them to any one or more servers among servers 101 through 104 according to a first preset allocation mechanism, so that tasks one through five can be processed by the server cluster system. The first preset allocation mechanism can be an allocation mechanism set by those skilled in the art based on experience, or it can be an allocation mechanism set by the user according to actual circumstances; no specific limitation is made.
[0042] In one example, Table 1 is a schematic table of a first preset allocation mechanism provided by an embodiment of the present invention.
[0043] Table 1: Schematic diagram of a first preset allocation mechanism
[0044]
[0045] As shown in Table 1, the first preset allocation mechanism can include the correspondence between the data volume of a task and the target server. If the data volume of a task is determined to be less than or equal to 50M, the task can be allocated to server 101 for processing; if the data volume of a task is determined to be greater than 50M and less than or equal to 120M, the task can be allocated to servers 101 and 103 for processing; if the data volume of a task is determined to be greater than 120M and less than or equal to 200M, the task can be allocated to servers 102 and 103 for processing; if the data volume of a task is determined to be greater than 200M and less than or equal to 500M, the task can be allocated to servers 102, 103, and 104 for processing; if the data volume of a task is determined to be greater than 500M and less than or equal to 700M, the task can be allocated to servers 101 through 104 for processing. Accordingly, if there are multiple target servers, after the multiple target servers have completed their respective tasks, the processing results of the tasks corresponding to the multiple target servers can be obtained and merged to obtain the processing results of the tasks corresponding to the server cluster system.
[0046] Furthermore, taking server 101 processing the first task as an example, if the first task cannot be processed due to a malfunction of server 101 during the processing of the first task, then the first task can be allocated to any one or more servers among servers 102 to 104 according to the second preset allocation mechanism. The second preset allocation mechanism can be an allocation mechanism set by those skilled in the art based on experience, or it can be an allocation mechanism set by the user according to actual circumstances; no specific limitation is made. In this embodiment of the invention, the execution process of the second preset allocation mechanism can be implemented according to the execution process of the first allocation mechanism, which will not be elaborated here.
[0047] It should be noted that, Figure 1a The first and second preset allocation mechanisms shown can be implemented manually. For example, if the server cluster system receives processing requests for tasks one through five, tasks one through five can be manually allocated to the corresponding target servers.
[0048] Figure 1bThis is a schematic diagram of another server cluster system architecture provided in an embodiment of the present invention, such as... Figure 1b As shown, a server cluster system may include at least one server (such as...) Figure 1b The illustrated servers 105, 106, 107, and 108) are connected to a central server 110, which manages at least one of the servers. The central server 110 can connect to each of the at least one server, thereby enabling communication with each server.
[0049] In practical implementation, the marketing business system can send the first to fifth tasks to the central server 110. Correspondingly, the central server 110 can store preset allocation mechanisms (such as a first preset allocation mechanism and a second preset allocation mechanism). In one example, the central server 110 can be connected to servers 105 to 108 via wired connections (such as network cables or fiber optic cables). Thus, if the central server 110 receives processing requests for the first to fifth tasks, it can determine the target servers corresponding to the first to fifth tasks based on the data volume of the tasks and the preset allocation mechanisms. For example, if the target server for the first task is determined to be server 105, the central server 110 can send the first task to server 105 via network cable or fiber optic cable, and can also receive the processing results obtained by server 105 from processing the first task via network cable or fiber optic cable. Correspondingly, if the central server 110 detects a failure in server 105 during the processing of the first task, it can determine the backup servers corresponding to server 105 (such as servers 106 and 107) according to the preset allocation mechanisms. The central server 110 can then send the first task currently being processed by server 105 to servers 106 and 107. In another example, the central server 110 can be connected to servers 105 to 108 wirelessly (e.g., microwave communication, satellite communication). In this way, the central server 110 can transmit the first task to the server 105 by sending a signal at a preset frequency, and can receive a signal at a preset frequency sent by the server 105, which includes the processing result of the first task.
[0050] It should be noted that, Figure 1a and Figure 1b This is merely a simple example, and the number of tasks listed is only for the purpose of illustrating the solution and does not constitute a limitation on the solution. In actual implementation, the number of tasks can be much greater than 5, for example, 100 or more.
[0051] The following is based on Figure 1b The illustrated server cluster system describes the task processing method in this embodiment of the invention. It can be understood that it is based on... Figure 1aThe task processing procedure of the server cluster system shown can be implemented by referring to this method, and the details will not be elaborated further.
[0052] based on Figure 1b The server cluster system shown Figure 2 This is a flowchart illustrating a task processing method according to an embodiment of the present invention. The execution entity of this method can be a task processor, which can be located in any one or more servers among servers 105 to 108, or it can be located within the process of any one or more servers; the specific implementation is not limited. In this embodiment of the present invention, one task processor can be set in each of the servers 105 to 108, so that the task processing processes of servers 105 to 108 can be independent of each other, thereby improving the flexibility of task processing.
[0053] The following embodiments of the present invention use server 105 as an example to describe the specific implementation process of task processing, such as... Figure 2 As shown, the method includes:
[0054] Step 201: Receive the call request for the first task.
[0055] In one example, if server 105 receives a first task sent by central server 110, it can determine the invocation conditions of the first task according to preset configuration rules. These preset configuration rules can be rules pre-configured in server 105, and may include identifiers of one or more tasks and corresponding invocation conditions. For example, Table 2 is a schematic table of preset configuration rules provided in an embodiment of the present invention.
[0056] Table 2: Illustration of a preset configuration rule
[0057] Task identification Task description Call-in condition Reconciliation a1 Perform reconciliation at 10:00 every day Current time = 10:00 Reconciliation a2 Perform reconciliation at 12:00 and 0:00 every day Current time = 12:00, or current time = 0:00 Serial number b Generate serial number after transaction is completed Transaction trigger Monitor c Monitor running environment at 2:00 every day Current time = 2:00
[0058] As shown in Table 2, the preset configuration rules can include one or more task identifiers, one or more task descriptions, and one or more task initiation conditions. Tasks identified as "Reconciliation a1," "Reconciliation a2," and "Monitoring c" (hereinafter referred to as Reconciliation a1, Reconciliation a2, and Monitoring c, respectively) can be scheduled tasks. If the current time meets the initiation time of Reconciliation a1 (i.e., 10:00), reconciliation can be performed. If the current time meets the initiation time of Reconciliation a2 (i.e., 12:00 or 0:00), reconciliation can be performed. If the current time meets the initiation time of Monitoring c (i.e., 2:00), the operating environment can be monitored. Correspondingly, the transaction log (b) task can be a real-time task. Once a transaction is determined to be completed, a transaction log number corresponding to that transaction can be generated.
[0059] Taking the first task as reconciliation task a1 as an example, after receiving the first task sent by the central server 110, server 105 can query the preset configuration rules shown in Table 2 to obtain the call-up conditions corresponding to the first task. Further, server 105 can obtain the system's clock information according to a preset period or in real time, and determine the current time based on the system's clock information; if the current time is determined to be 10:00, a call-up request for the first task can be generated and sent to the task processor set in server 105. The call-up request corresponding to the first task can include the identifier of the first task, i.e., reconciliation a1.
[0060] Step 202: Obtain at least one task from the preset database and the lock resources corresponding to each of the at least one task.
[0061] In specific implementation, after receiving the invocation request of the first task, the task processor can query a preset database to obtain at least one task and its corresponding lock resources stored in the preset database. The lock resources corresponding to the at least one task can be used to indicate the status of the at least one task, which can be either locked or unlocked. Table 3 is a schematic table of a preset database provided in an embodiment of the present invention.
[0062] Table 3: Schematic diagram of a pre-defined database
[0063] Lock identification Task identification Status Start time Pre-set end time Node identification [M1] Reconciliation a1 Locked 10:00 10:30 Server 106 [M2] Reconciliation a2 Unlocked 0:00 0:30 Server 108 [M3] Monitor c Unlocked 2:00 2:15
[0064] As shown in Table 3, the preset database can store reconciliation task a1, reconciliation task a2, monitoring task c, and lock resources corresponding to each of these tasks. The lock resources for each task can include the task identifier, status, start time, preset termination time, and the node identifier of the executing task. Taking reconciliation task a1 as an example, the status of reconciliation task a1 is locked, the start time is 10:00, the preset termination time is 10:30, and the node identifier is server 106. This indicates that the task processor set in server 106 successfully invoked reconciliation task a1 at 10:00, meaning server 106 started reconciliation at 10:00, and the preset end time for reconciliation is 10:30.
[0065] It should be noted that Table 3 is only a simple example, and the database storage formats listed are only for the purpose of illustrating the scheme and do not constitute a limitation on the scheme. In specific implementation, the lock resources of the task can be stored in any one or more of the following forms: database, file, and cache, without any specific limitation.
[0066] In one possible implementation, the task processor can obtain lock resources for at least one task from a preset database on the central server 110. For example, if the central server 110 stores the preset database on a disk, the task processor can access the disk of the central server 110 via File Transfer Protocol (FTP) to obtain lock resources for at least one task in the preset database. In this implementation, by storing the preset database on the central server 110, servers 105 to 108 can obtain unified lock resources, thus ensuring the uniformity of task processing. In another possible implementation, the task processor can obtain lock resources for at least one task from the preset database on server 105. Specifically, server 105 can access the disk of the central server 110 at preset intervals and store the preset database from the disk in a preset storage space (e.g., memory) on server 105. In this implementation, the task processor can obtain lock resources for at least one task by querying the preset storage space of server 105, improving the timeliness of task processing.
[0067] Step 203: Determine whether there is a target task in at least one task that matches the identifier of the first task.
[0068] In practice, it can be determined whether a target task matching the identifier of the first task exists in the preset database based on the identifier of the first task and the identifier of at least one task in the preset database. If no target task exists, step 204a can be executed; if a target task exists, step 204b can be executed. For example, based on the preset database shown in Table 3, if the first task is a transaction task b, it can be determined that no target task matching the first task exists in the preset database, and step 204a can be executed; if the first task is a reconciliation task a1, a reconciliation task a2, or a monitoring task c, it can be determined that a target task matching the first task exists in the preset database, and step 204b can be executed.
[0069] Step 204a: Execute the first task and set the lock resources corresponding to the first task.
[0070] In specific implementation, if the first task is task b, since the lock resource corresponding to task b does not exist in the preset database, it means that task b has not been executed yet. Therefore, the task processor can execute task b. In one example, while executing task b, the task processor can also set the lock resource corresponding to task b and update the preset database based on the lock resource. For example, if the preset database is only stored in central server 110, the task processor can send the lock resource corresponding to task b to central server 110 after generating it, so that central server 110 adds the lock resource to the preset database. Alternatively, if the preset database is stored in both central server 110 and server 105, the task processor can add the lock resource corresponding to task b to the preset database of server 105 after generating it, and can also send the lock resource corresponding to task b to central server 110, so that central server 110 adds the lock resource to its preset database.
[0071] For example, if servers 105 and 106 determine that a certain transaction has been completed, they can each generate a request to initiate the transaction task 'b'. If server 105 initiates the task at 9:00 and server 106 initiates it at 9:05, server 105 will query the preset database to determine that no other server has yet executed the transaction task 'b'. Therefore, server 105 can execute the transaction task 'b' and can update the preset database after generating the lock resources corresponding to the transaction task 'b'. In one example, server 105 can update the preset database shown in Table 3 to the preset database in Table 4.
[0072] Table 4: A schematic diagram of an updated preset database
[0073]
[0074]
[0075] As shown in Table 4, the lock resources corresponding to the task b can include the identifier, status, start time, preset termination time and node identifier of the task b. Since server 105 executes the task b at 9:00, the status of the task b can be locked, the start time of the task b can be 9:00, and the node identifier of the task b can be server 105.
[0076] In this embodiment of the invention, by updating the preset database while executing the task, the real-time nature of the lock resources corresponding to the task in the preset database can be achieved, so that the accuracy of task processing can be improved by executing subsequent task processing based on real-time lock resources.
[0077] Accordingly, when server 106 initiates the pipeline task b at 9:05, since server 105 has already started executing the pipeline task b at 9:00, the preset database that server 106 sees can be the preset database shown in Table 4. Since the preset database contains the lock resource corresponding to the pipeline task b, it indicates that the pipeline task b has been executed. Therefore, step 204b can be executed.
[0078] In one possible implementation, as shown in Table 4, the preset termination time for pipeline task b is 9:30. If the task processor determines that pipeline task b has been successfully completed before 9:30, it can update the status of pipeline task b in the lock resource corresponding to pipeline task b to the unlocked state. If the task processor determines that pipeline task b has not been completed after 9:30, it can generate an alarm message and push the alarm message to the operation and maintenance personnel in various ways, such as through WeChat, DingTalk, or WeChat groups for enterprises, without any specific limitation.
[0079] In this embodiment of the invention, if the first task is completed before the preset termination time, the lock resource corresponding to the target task can be released (that is, the state of the target task in the lock resource corresponding to the target task is updated to an unlocked state). In this way, flexible management of lock resources can be achieved and the accuracy of lock resources can be improved.
[0080] Step 204b: Determine whether the target task is in a locked state.
[0081] In practice, if a lock resource corresponding to the first task exists in the preset database, the task processor can obtain the status of the first task based on the lock resource. The status of the first task can be locked or unlocked. For example, based on the preset database shown in Table 3, if the first task is reconciliation task a2 or monitoring task c, it can be determined that reconciliation task a2 and monitoring task c are in an unlocked state based on the lock resource corresponding to reconciliation task a2 and monitoring task c, and step 205a can be executed. If the first task is reconciliation task a1, it can be determined that reconciliation task a1 is in a locked state based on the lock resource corresponding to reconciliation task a1, and step 205b can be executed.
[0082] Step 205a: If the startup time difference is greater than the preset time, then execute the first task; if the startup time difference is less than or equal to the preset time, then do not execute the first task.
[0083] In this embodiment of the invention, if the status of the first task in the preset database is unlocked, it means that the first task is not currently being executed. This situation can exist in the following two scenarios.
[0084] Scenario 1
[0085] In scenario one, the first task has not been performed before.
[0086] Taking monitoring task c as an example, in one instance, after receiving the monitoring task c sent by the business system, the central server 110 can generate the initial lock resource corresponding to the monitoring task c before assigning it to servers 105 to 108. The initial lock resource corresponding to the monitoring task c can be as shown in Table 3. The node identifier in the lock resource corresponding to monitoring c can be empty, indicating that the monitoring task c has not been executed before.
[0087] In specific implementation, if the central server 110 sends the monitoring task c to the server 107, the server 107 can send a call-up request to the task processor set in the server 107 at 2:00. Accordingly, after receiving the call-up request, the task processor can determine that the monitoring task c has not been executed before by checking the preset database shown in Table 3. In this way, the task processor can execute the monitoring task c (i.e., check whether the running environment is normal), and can update the status of the monitoring task c in the lock resource corresponding to the monitoring task c to the locked state, and can update the node identifier corresponding to the monitoring task c in the lock resource corresponding to the monitoring task c to the server 107.
[0088] Scenario 2
[0089] In scenario two, the reconciliation task a2 has already been executed and completed.
[0090] Taking the reconciliation task a2 initiated by server 107 as an example, the task processor in server 107 can obtain the preset database shown in Table 3. Based on the lock resources corresponding to the reconciliation task a2, it can be determined that the reconciliation task a2 was executed by server 108 at 0:00. Since the state of the reconciliation task a2 is unlocked, it indicates that server 108 has completed the execution of the reconciliation task a2. Thus, in one possible implementation, the task processor in server 107 can obtain the time when server 107 initiated the reconciliation task a2 and the time when server 108 initiated the reconciliation task a2 (i.e., the start time), and can obtain the start time difference corresponding to the reconciliation task a2 based on the time when server 107 initiated the reconciliation task a2 and server 108 initiated the reconciliation task a2. Furthermore, if the start time difference corresponding to the reconciliation task a2 is greater than the preset duration, the task processor in server 107 can execute the reconciliation task a2; if the start time difference corresponding to the reconciliation task a2 is less than or equal to the preset duration, the task processor in server 107 can choose not to execute the reconciliation task a2.
[0091] The preset duration can be set by those skilled in the art based on experience, or it can be determined experimentally; no specific limitation is made. In this embodiment of the invention, the preset duration can be a basic attribute attached to the task. That is, when the business system sends a task request to the central server 110, it can set the preset duration corresponding to the task in the task request. In this way, by setting the preset duration through the business system, different preset durations can be set according to different application scenarios, thereby making the preset duration more in line with the actual situation and improving user satisfaction.
[0092] Based on the preset database shown in Table 3, taking a preset duration of 20 minutes as an example, in one example, if server 107 calls up the reconciliation task a2 to the task processor in server 107 at 12:00, since server 108 calls up the reconciliation task a2 at 0:00, the time difference between server 107 and server 108 calling up the reconciliation task a2 is 12 hours (>20 minutes). Therefore, the task processor in server 107 can execute the reconciliation task a2 and update the preset database shown in Table 3 to the one shown in Table 5.
[0093] Table 5: A schematic diagram of an updated preset database
[0094] Lock identification Task identification Status Start time Pre-set end time Node identification M1 Reconciliation a1 Locked 10:00 10:30 Server 106 [M2] Reconciliation a2 Locked 12:00 12:30 Server 107 [M3] Monitor c Unlocked 2:00 2:15
[0095] Referring to Tables 3 and 5, the task processor in server 107 can update the status of reconciliation task a2 in the lock resource corresponding to reconciliation task a2 to the locked state, update the node identifier of the node executing reconciliation task a2 in server 107, update the start time of reconciliation task a2 to 12:00, and update the preset termination time of reconciliation task a2 to 12:30.
[0096] In another example, if server 107 invokes the reconciliation task a2 at 0:03, and server 108 invokes the reconciliation task a2 at 0:00, the time difference between the invocation of the reconciliation task a2 by server 107 and server 108 is 3 minutes (<20 minutes). This indicates that server 107 and server 108 are executing the same task, but due to some reasons (such as network latency of server 107), the invocation time of server 107 is later than that of server 108. Therefore, the task processor in server 107 cannot execute the reconciliation task a2.
[0097] In this embodiment of the invention, by adopting the logical judgment method in the above design, the processing of the first task can be controlled, and the implementation process of the logical judgment method is relatively simple and easy to implement; moreover, by judging the length of the start time difference between two identical tasks, the problem of different start times for two tasks called at the same time due to network latency can be avoided, thereby avoiding the repeated processing of the same task, reducing the pressure on the system, and improving the efficiency of task processing.
[0098] Step 205b: If the target task times out, execute the first task; if the target task does not time out, do not execute the first task.
[0099] In this embodiment of the invention, if the state of the first task in the preset database is locked, it means that the first task is currently being executed. This situation can exist in the following two scenarios.
[0100] Scenario 3
[0101] In scenario three, the first task has timed out.
[0102] If server 107 invokes reconciliation task a1 at 10:40, the task processor in server 107 can obtain the preset database shown in Table 3. Based on the lock resources corresponding to reconciliation task a1, it can be determined that reconciliation task a1 was executed by server 106 at 10:00. Since the state of reconciliation task a1 is locked, it means that server 106 is currently executing reconciliation task a1, that is, reconciliation task a1 has not yet been completed.
[0103] Furthermore, the task processor in server 107 can determine, through the lock resources corresponding to the reconciliation task a1, that the preset termination time for server 106 to execute the reconciliation task a1 is 10:30. The current time (10:40) has exceeded the preset termination time, indicating that the execution of the reconciliation task a1 by server 106 has timed out. Thus, the task processor in server 107 can execute the reconciliation task a1 and update the start time, preset termination time, and node identifier of the reconciliation task a1 in the lock resources corresponding to the reconciliation task a1, as shown in Table 6.
[0104] Table 6: A schematic diagram of an updated preset database
[0105] Lock identification Task identification Status Start time Pre-set end time Node identification M1 Reconciliation a1 Locked 10:40 11:10 Server 107 [M2] Reconciliation a2 Locked 12:00 12:30 Server 107 [M3] Monitor c Unlocked 2:00 2:15
[0106] In one example, if the task processor in server 107 determines that the reconciliation task a1 has timed out, it can generate an alarm message and send the alarm message to the central server 110 so that the central server 110 can display the alarm message to the operation and maintenance personnel.
[0107] Scenario 4
[0108] In scenario four, the first task did not time out.
[0109] If server 107 invokes reconciliation task a1 at 10:20, the task processor in server 107 can obtain the preset database shown in Table 3. Based on the lock resources corresponding to reconciliation task a1, it can be determined that reconciliation task a1 was executed by server 106 at 10:00. Since the state of reconciliation task a1 is locked, it means that server 106 is currently executing reconciliation task a1, that is, reconciliation task a1 has not yet been completed.
[0110] Furthermore, the task processor in server 107 can determine, through the lock resources corresponding to the reconciliation task a1, that the preset termination time for server 106 to execute the reconciliation task a1 is 10:30. Since the current time (10:20) has not exceeded the preset termination time, it indicates that server 106 is executing the reconciliation task a1 normally. Therefore, the task processor in server 107 does not need to execute the reconciliation task a1.
[0111] In this embodiment of the invention, if the target task is in a locked state, it means that the target task is currently being executed. Therefore, the target task can be determined by the preset termination time of the target task and the current time (timeout means that it should have been completed but has not been completed). If the target task times out, it means that the target task is executing abnormally, so the first task can be executed. If the target task does not time out, it means that the target task is being executed normally, so the first task does not need to be executed.
[0112] In the above embodiments of the present invention, a call request for a first task is received, the call request for the first task including an identifier of the first task; further, at least one task in a preset database and lock resources corresponding to the at least one task are obtained respectively; if there is a target task in the at least one task that matches the identifier of the first task, then it is determined whether to execute the first task according to the lock resource corresponding to the target task; wherein, the lock resource corresponding to the at least one task is used to indicate the state of the at least one task, the state of the at least one task being a locked state or an unlocked state. In the embodiments of the present invention, by setting lock resources corresponding to tasks, it is possible to determine whether the task is currently in a locked state or an unlocked state according to the lock resources corresponding to the task, and then determine whether to execute the task according to the state of the task; using this method, when a call request for the first task is received, it is only necessary to obtain the lock resource corresponding to the first task to determine whether to execute the first task, which is simple to operate and easy to implement. By using simple logic to implement the task processing process, the efficiency of task processing can be improved.
[0113] The following describes the process from a hardware implementation perspective. Figure 2 The task processing method shown.
[0114] Figure 3 This is a hardware implementation diagram of a task processing method provided in an embodiment of the present invention, such as... Figure 3 As shown, each server executing the processing task can have the same structure. Taking server 105 as an example, server 105 can be equipped with a service interface, a task processor, and a scheduler. Any two components among the service interface, task processor, and scheduler can be interconnected, for example, through a wired connection or a wireless connection, without any specific limitation.
[0115] In this embodiment of the invention, the business interface can be connected to the business system to obtain task requests sent by the business system to the server 105. Thus, the server 105 can obtain at least one task to be processed through the business interface. Correspondingly, the scheduler can be configured with a preset configuration rule base, which stores preset rules corresponding to one or more tasks (as shown in Table 2). If the scheduler determines that a task to be processed in the server 105 has triggered the preset rule corresponding to that task, it can generate a call request corresponding to that task and send the call request to the task processor. Further, the task processor can determine whether to execute the task to be processed.
[0116] In one possible implementation, such as Figure 3As shown, the task processor can include a task manager, a task executor, and a lock resource manager. The task executor can connect to both the task manager and the lock resource manager, for example, via a wired connection or a wireless connection; the specific connection method is not limited.
[0117] In practice, the task manager can have a task management database. This database stores all pending tasks received by server 105. For example, if server 105 receives 100 pending tasks from central server 110 (or tasks entered manually), it can store these 100 tasks in the task management database. The task manager can then perform CRUD operations on these tasks. For instance, if a request to activate a pending task is received, the task manager can update the status of that task in the task management database to "activated." If the user cancels the request, the task can be deleted from the database. If a user requests to query the status of a pending task, the task manager can retrieve the status from the database and display it to the user via central server 110, and so on.
[0118] In one example, the task manager can support automatic task initiation. For instance, the task manager can connect to the scheduler, and if the scheduler determines to initiate a pending task, it can send the initiation request for that task to the task manager. The task manager can then update the status of that pending task in the task management database to "initiated." In another example, the task manager can support manual task initiation. For instance, server 105 can be equipped with a World Wide Web (web) browser, allowing users to access the task initiation management interface by entering a preset link. Correspondingly, the task manager can connect to the web browser, and if it detects that a user has entered an identifier for a pending task in the initiation management interface, it can update the status of that pending task in the task management database to "initiated."
[0119] Furthermore, the task executor can check the status of multiple pending tasks in the task management database at preset intervals. If, during a certain check, it is determined that the status of a pending task has been updated to the invoked state, a request message can be sent to the lock resource manager. This request message can include the identifier of the pending task and is used to acquire the lock resource corresponding to that pending task.
[0120] Accordingly, after receiving the request message from the task executor, the lock resource manager can query one or more tasks in the lock resource library. If it is determined that there is no target task among the one or more tasks that matches the identifier of the pending task, the lock resource manager can send a first type of response message to the task executor; the first type of response message is used to instruct the task executor to process the pending task. In one example, the lock resource manager can also generate lock resources corresponding to the pending task and add the lock resources corresponding to the pending task to the lock resource library. Accordingly, if it is determined that there is a target task among the one or more tasks that matches the identifier of the pending task, the lock resource manager can determine whether to execute the pending task based on the lock resources corresponding to the target task. If it is determined to execute the pending task, it can send a first type of response message to the task executor and update the lock resource library; if it is determined not to execute the pending task, it can send a second type of response message to the task executor; the second type of response message is used to instruct the task executor not to process the pending task.
[0121] like Figure 3 As shown in the embodiments of the present invention, the lock resources of the task can be stored in any one or more forms of database, file, or cache, without any specific limitation.
[0122] It should be noted that the process by which the lock resource manager determines whether to execute the pending task based on the lock resource corresponding to the target task can be implemented by referring to steps 204b and 205a, or steps 204b and 205b, which will not be elaborated here. In this embodiment of the invention, the effect of distributed mutual exclusion can be achieved with minimal dependency on components, making it simple and lightweight to use.
[0123] In accordance with the above method and process, this embodiment of the invention also provides a task processing device, the specific contents of which can be implemented with reference to the above method.
[0124] Figure 4 A task processing apparatus provided in an embodiment of the present invention includes:
[0125] The transceiver module 401 is used to receive a call-up request for the first task, wherein the call-up request for the first task includes the identifier of the first task.
[0126] The processing module 402 is used to obtain at least one task in a preset database and the lock resources corresponding to the at least one task respectively. If there is a target task in the at least one task that matches the identifier of the first task, then determine whether to execute the first task according to the lock resource corresponding to the target task. The lock resource corresponding to the at least one task is used to indicate the status of the at least one task, and the status of the at least one task is a locked state or an unlocked state.
[0127] Optionally, the processing module 402 is specifically used for:
[0128] The state of the target task is determined based on the lock resources corresponding to the target task.
[0129] When the target task is in an unlocked state, if the lock resource corresponding to the target task is an initial lock resource, then the first task is executed; if the lock resource corresponding to the target task is a lock resource set for the target task when executing the target task, then it is determined whether to execute the first task based on the start time of the target task and the start time of the first task. When the target task is in a locked state, the preset termination time corresponding to the target task is obtained from the lock resource corresponding to the target task. If the current time is greater than the preset termination time corresponding to the target task, then the first task is executed.
[0130] Optionally, the processing module 402 is specifically used for:
[0131] The start time difference between the target task and the first task is determined based on the start time of the target task and the start time of the first task.
[0132] If the start time difference between the target task and the first task is greater than a preset time, then the first task is executed.
[0133] Optionally, the device further includes an update module 403, the update module 403 being used for:
[0134] Update the status of the target task in the lock resource corresponding to the target task to the locked state, and update the node identifier, start time, and preset termination time of the target task in the lock resource corresponding to the target task according to the node identifier of the first task, the start time of the first task, and the preset execution duration of the first task.
[0135] Optionally, the update module 403 is further configured to:
[0136] If the first task is completed before the preset termination time of the target task, the status of the target task in the lock resource corresponding to the target task is updated to an unlocked state.
[0137] Optionally, the processing module 402 is further configured to:
[0138] If there is no target task among the at least one task that matches the identifier of the first task, then the first task is executed, and the lock resource corresponding to the first task is set.
[0139] As can be seen from the above, in the embodiments of the present invention, a call request for a first task is received, the call request for the first task including the identifier of the first task; further, at least one task in a preset database and the lock resources corresponding to the at least one task are obtained respectively; if there is a target task in the at least one task that matches the identifier of the first task, then it is determined whether to execute the first task according to the lock resource corresponding to the target task; wherein, the lock resource corresponding to the at least one task is used to indicate the state of the at least one task, the state of the at least one task being locked or unlocked. In the embodiments of the present invention, by setting the lock resource corresponding to the task, it is possible to determine whether the task is currently locked or unlocked according to the lock resource corresponding to the task, and then determine whether to execute the task according to the state of the task; using this method, when a call request for the first task is received, it is only necessary to obtain the lock resource corresponding to the first task to determine whether to execute the first task, which is simple to operate and easy to implement. By using simple logic to implement the task processing process, the efficiency of task processing can be improved.
[0140] Based on the same inventive concept, embodiments of the present invention also provide a computer-readable storage medium, including instructions that, when executed on a computer, cause the computer to perform the following... Figure 2 or Figure 2 The task processing method described in any one of the above.
[0141] Based on the same inventive concept, embodiments of the present invention also provide a computer program product that, when run on a computer, causes the computer to perform actions such as... Figure 2 or Figure 2 The task processing method described in any one of the above.
[0142] Those skilled in the art will understand that embodiments of the present invention can be provided as methods or computer program products. Therefore, the present invention can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, the present invention can take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0143] This invention is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the invention. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create means for implementing the functions specified in one or more blocks of the flowchart illustrations and / or one or more blocks of the block diagrams.
[0144] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing device to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means that implement the functions specified in one or more flowcharts and / or one or more block diagrams.
[0145] These computer program instructions may also be loaded onto a computer or other programmable data processing apparatus to cause a series of operational steps to be performed on the computer or other programmable apparatus to produce a computer-implemented process, such that the instructions, which execute on the computer or other programmable apparatus, provide steps for implementing the functions specified in one or more flowcharts and / or one or more block diagrams.
[0146] Although preferred embodiments of the invention have been described, those skilled in the art, upon learning the basic inventive concept, can make other changes and modifications to these embodiments. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments as well as all changes and modifications falling within the scope of the invention.
[0147] Obviously, those skilled in the art can make various modifications and variations to this invention without departing from its spirit and scope. Therefore, if these modifications and variations fall within the scope of the claims of this invention and their equivalents, this invention also intends to include these modifications and variations.
Claims
1. A task processing method, characterized in that, The method includes: Receive a call request for the first task, wherein the call request for the first task includes the identifier of the first task; Obtain at least one task from a preset database and the lock resources corresponding to the at least one task respectively. If there is a target task in the at least one task that matches the identifier of the first task, determine whether to execute the first task based on the lock resources corresponding to the target task. The lock resources corresponding to the at least one task are used to indicate the status of the at least one task, and the status of the at least one task is locked or unlocked. If there is no target task matching the identifier of the first task among the at least one task, then the first task is executed, the lock resource corresponding to the first task is set, and the preset database is updated according to the lock resource corresponding to the first task. The step of determining whether to execute the first task based on the lock resource corresponding to the target task includes: The state of the target task is determined based on the lock resources corresponding to the target task. When the target task is in an unlocked state, if the lock resource corresponding to the target task is an initial lock resource, then the first task is executed; if the lock resource corresponding to the target task is a lock resource set for the target task when executing the target task, then it is determined whether to execute the first task based on the start time of the target task and the start time of the first task. When the target task is in a locked state, the preset termination time corresponding to the target task is obtained from the lock resource corresponding to the target task. If the current time is greater than the preset termination time corresponding to the target task, then the first task is executed.
2. The method according to claim 1, characterized in that, The step of determining whether to execute the first task based on the start time of the target task and the start time of the first task includes: The start time difference between the target task and the first task is determined based on the start time of the target task and the start time of the first task. If the start time difference between the target task and the first task is greater than a preset time, then the first task is executed.
3. The method according to claim 1, characterized in that, The method further includes: Update the status of the target task in the lock resource corresponding to the target task to the locked state, and update the node identifier, start time, and preset termination time of the target task in the lock resource corresponding to the target task according to the node identifier of the first task, the start time of the first task, and the preset execution duration of the first task.
4. The method according to claim 3, characterized in that, The method further includes: If the first task is completed before the preset termination time of the target task, the status of the target task in the lock resource corresponding to the target task is updated to an unlocked state.
5. A task processing device, characterized in that, The device includes: The transceiver module is used to receive the invocation request of the first task, wherein the invocation request of the first task includes the identifier of the first task. The processing module is used to obtain at least one task and the lock resources corresponding to the at least one task from a preset database. If there is a target task in the at least one task that matches the identifier of the first task, then it is determined whether to execute the first task based on the lock resources corresponding to the target task. The lock resources corresponding to the at least one task are used to indicate the status of the at least one task, and the status of the at least one task is locked or unlocked. The processing module is further configured to: if there is no target task matching the identifier of the first task among the at least one task, execute the first task, set the lock resource corresponding to the first task, and update the preset database according to the lock resource corresponding to the first task; The processing module is specifically used for: determining the state of the target task based on the lock resource corresponding to the target task; when the state of the target task is unlocked, if the lock resource corresponding to the target task is an initial lock resource, then executing the first task; if the lock resource corresponding to the target task is a lock resource set for the target task when executing the target task, then determining whether to execute the first task based on the start time of the target task and the start time of the first task; when the state of the target task is locked, obtaining the preset termination time corresponding to the target task from the lock resource corresponding to the target task; if the current time is greater than the preset termination time corresponding to the target task, then executing the first task.
6. The apparatus according to claim 5, characterized in that, The processing module is specifically used for: The start time difference between the target task and the first task is determined based on the start time of the target task and the start time of the first task. If the start time difference between the target task and the first task is greater than a preset time, then the first task is executed.
7. The apparatus according to claim 5, characterized in that, The device further includes an update module, the update module being used for: Update the status of the target task in the lock resource corresponding to the target task to the locked state, and update the node identifier, start time, and preset termination time of the target task in the lock resource corresponding to the target task according to the node identifier of the first task, the start time of the first task, and the preset execution duration of the first task.
8. The apparatus according to claim 7, characterized in that, The update module is also used for: If the first task is completed before the preset termination time of the target task, the status of the target task in the lock resource corresponding to the target task is updated to an unlocked state.
9. A computer-readable storage medium, characterized in that, Includes instructions that, when executed on a computer's processor, cause the computer's processor to perform the method as described in any one of claims 1 to 4.
10. A computer program product, characterized in that, When it is run on a computer, it causes the computer to perform the method as described in any one of claims 1 to 4.
Citation Information
Patent Citations
Execution method and device for timed task
CN108710541A
Distributed timing method and system and server
CN108733459A
Task processing method and system
CN109800070A