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

By obtaining task execution instructions in the message queue and adding global locks, the task processing is ensured in an orderly manner, and the problem of multiple task execution consumer side processing tasks at the same time is solved, achieving the stability and efficiency of task processing.

CN119917238APending Publication Date: 2025-05-02SHENZHEN KEMAI TECH
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411997068.1
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-12-31
Publication Date
2025-05-02

AI Technical Summary

Technical Problem

In the case of multiple task execution consumer ends, there may be a situation where the same task is processed simultaneously by multiple task execution consumer ends, resulting in confusion and disorderly task processing.

Method used

By obtaining task execution instructions in the message queue, and when a global lock is successfully added to the pending task corresponding to the task execution instructions, the target tasks in the task corresponding to the pending task are executed. After the target task is executed, delete the target task from the task set and release the global lock of the pending task.

Benefits of technology

Ensure the orderliness of the task processing process, avoid the same task being processed by multiple consumer ends at the same time, and improve the stability and efficiency of task execution.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119917238A_ABST
    Figure CN119917238A_ABST
Patent Text Reader

Abstract

The invention relates to a task processing method and device, computer equipment, a computer readable storage medium and a computer program product. The method comprises the following steps: acquiring a task execution instruction from a message queue; under the condition that the global lock is successfully added to the to-be-processed task corresponding to the task execution instruction, executing a target task in a task set corresponding to the to-be-processed task according to the task execution instruction; under the condition that execution of the target task is completed, the target task is deleted from the task set, and a global lock corresponding to the to-be-processed task is released; wherein other tasks except the target task in the task set are executed after the global lock corresponding to the to-be-processed task is released. By adopting the method, the task processing orderliness can be improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of computer data communications, and in particular to a task processing method, apparatus, computer equipment, computer-readable storage medium, and computer program product. Background Art

[0002] With the development of computer technology, multiple task execution consumers can process tasks simultaneously to improve task processing efficiency.

[0003] In traditional technology, RabbitMq message queue middleware is used to achieve orderly processing of tasks through the first-in-first-out order. However, when there are multiple task execution consumers, multiple task execution consumers may try to obtain the same task at the same time, and the same task may be processed by multiple task execution consumers at the same time, which will cause confusion in task processing and lead to disorder in the task processing process. Summary of the invention

[0004] Based on this, it is necessary to provide a task processing method, apparatus, computer equipment, computer-readable storage medium and computer program product that can ensure the orderliness of task processing in response to the above technical problems.

[0005] In a first aspect, the present application provides a task processing method, which is applied to a task execution consumer end, comprising:

[0006] Get task execution instructions from the message queue;

[0007] When a global lock is successfully added to the pending task corresponding to the task execution instruction, executing the target task in the task set corresponding to the pending task according to the task execution instruction;

[0008] When the target task is completed, the target task is deleted from the task set, and the global lock corresponding to the task to be processed is released;

[0009] Among them, other tasks in the task set except the target task are executed after the global lock corresponding to the task to be processed is released.

[0010] In one embodiment, after executing the target task, the following steps are performed:

[0011] Determining a processing status of the target task;

[0012] When the processing status of the target task is execution completed, deleting the target task and the task execution instruction of the target task;

[0013] When the processing status of the target task is execution failure, the task execution instruction is added to the message queue again.

[0014] In one embodiment, the number of the task execution consumer terminals is at least two, and the method includes:

[0015] At least two task execution consumers obtain corresponding task execution instructions from the message queue respectively;

[0016] Determine whether the target task execution consumer end has successfully added a global lock to the pending task corresponding to the task execution instruction among at least two task execution consumer ends;

[0017] If the target execution consumer has successfully added a global lock to the task to be processed, reject the task execution instruction;

[0018] In the absence of the target execution consumer adding a global lock to the pending task, based on each of the task execution consumers, when a global lock is successfully added to the pending task corresponding to the task execution instruction, the target task in the task set corresponding to the pending task is executed according to the task execution instruction.

[0019] In one embodiment, the execution mode in which at least two task execution consumers respectively execute the target task includes at least one of the following modes:

[0020] When the target tasks have the same task type but different task objects, the corresponding target tasks are executed in parallel;

[0021] When the target tasks have different task types but the same task objects, the corresponding target tasks are executed in parallel;

[0022] When the target tasks have different task types and different task objects, the corresponding target tasks are executed in parallel;

[0023] When the target tasks have the same task type and the same task object, the corresponding target tasks are executed in the order of the task set.

[0024] In a second aspect, the present application also provides a task processing method, which is applied to a task collection consumer end, and the method includes:

[0025] When receiving a task, obtaining task information corresponding to each task;

[0026] Each of the tasks is stored in the task set corresponding to the pending task according to the task information, so that when the task execution consumer receives the task execution instruction from the message queue and successfully adds a global lock for the pending task corresponding to the task execution instruction, the target task determined from the task set corresponding to the pending task according to the task execution instruction is executed, wherein other tasks in the task set except the target task are executed after the global lock corresponding to the pending task is released.

[0027] In one embodiment, the task information includes a task object and / or a task type, and storing each task in a task set corresponding to the to-be-processed task according to the task information includes:

[0028] Classify each of the tasks according to the task object and / or task type and store them in a task set corresponding to the task to be processed;

[0029] After storing each of the tasks according to the task information into a task set corresponding to the task to be processed, the method includes:

[0030] A corresponding task execution instruction is generated based on each task in the task set put into the to-be-processed tasks, and the task execution instruction is put into a message queue.

[0031] In a third aspect, the present application further provides a task processing method, which is applied to a consumer end, wherein the consumer end includes a task collection consumer end and a task execution consumer end, and the method includes:

[0032] The task collection and consumption end is used to obtain task information corresponding to each task when receiving the task; and store each task in a task set corresponding to the task to be processed according to the task information;

[0033] The task execution consumer end is used to obtain task execution instructions from a message queue; when a global lock is successfully added to a pending task corresponding to the task execution instruction, a target task in a task set corresponding to the pending task is executed according to the task execution instruction; when the target task is executed, the target task is deleted from the task set and the global lock corresponding to the pending task is released; wherein, other tasks in the task set except the target task are executed after the global lock corresponding to the pending task is released.

[0034] In a fourth aspect, the present application further provides a task processing device, comprising:

[0035] A task execution instruction acquisition module is used to obtain task execution instructions from a message queue;

[0036] A target task execution module, configured to execute a target task in a task set corresponding to the task to be processed according to the task execution instruction when a global lock is successfully added to the task to be processed corresponding to the task execution instruction;

[0037] A global lock release module, used to delete the target task from the task set and release the global lock corresponding to the task to be processed when the target task is executed;

[0038] Among them, other tasks in the task set except the target task are executed after the global lock corresponding to the task to be processed is released.

[0039] In a fifth aspect, the present application further provides a task processing device, including:

[0040] A task information acquisition module, used to acquire task information corresponding to each task when a task is received;

[0041] A task information storage module is used to store each of the tasks in a task set corresponding to the pending task according to the task information, so that when the task execution consumer receives the task execution instruction from the message queue and successfully adds a global lock for the pending task corresponding to the task execution instruction, the target task determined from the task set corresponding to the pending task according to the task execution instruction is executed, wherein other tasks in the task set except the target task are executed after the global lock corresponding to the pending task is released.

[0042] In a sixth aspect, the present application further provides a computer device, wherein the computer device comprises a memory and a processor, wherein the memory stores a computer program, and when the processor executes the computer program, the steps of the above method are implemented.

[0043] In a seventh aspect, the present application further provides a computer-readable storage medium having a computer program stored thereon, and when the computer program is executed by a processor, the steps of the above method are implemented.

[0044] In an eighth aspect, the present application further provides a computer program product, wherein the computer program product comprises a computer program, and when the computer program is executed by a processor, the steps of the above method are implemented.

[0045] The above-mentioned task processing method, device, computer equipment, computer-readable storage medium and computer program product, before the task is processed, the task execution consumer end obtains the task execution instruction from the message queue, and achieves the purpose of executing the task based on the task execution instruction. Compared with the method of directly accepting the task execution instruction to execute the task without the message queue, the orderliness of the task execution processing is greatly improved. Afterwards, the task execution consumer end can try to add a global lock to the pending task corresponding to the task execution instruction. When the pending task corresponding to the task execution instruction has not been processed by other consumer ends except the task execution consumer end, a global lock can be successfully added to the pending task corresponding to the task execution instruction. At this time, it indicates that the pending task can be processed by the task execution consumer end. The task execution consumer end executes the target task in the task set corresponding to the pending task according to the task execution instruction, indicating that the target task in the pending task is in a state of being executed by the task execution consumer end and has not been completed. In the above task processing process, before each task is executed, you can try to add a global lock to the pending task corresponding to the task execution instruction. Under the premise of ensuring that the pending task to be executed is not currently being processed by other consumer ends except the task execution consumer end, you can successfully add a global lock to the pending task, and avoid other subsequent task execution consumer ends from repeatedly processing the task, thereby ensuring the orderliness of the task processing process. Finally, when the target task is executed, delete the target task from the task set, and release the global lock corresponding to the pending task, which can ensure that the target task in the task set corresponding to the pending task has been executed, and the pending task or other tasks in the task set except the target task can be processed by the consumer end (the consumer end includes the task execution consumer end).

[0046] In addition, other tasks in the task set except the target task are executed after the global lock corresponding to the pending task is released, which can ensure that during the processing of the target task, the pending task will not be processed by other task execution consumer ends. Since the target task and other tasks are subtasks in the pending task, the above method can ensure that even when a subtask of the pending task is being processed, other subtasks will not be processed by other task execution consumer ends, thereby achieving the orderliness of the execution order of multiple subtasks. That is, the above method can achieve the purpose of orderly execution of multiple pending tasks and multiple subtasks of the same pending task. BRIEF DESCRIPTION OF THE DRAWINGS

[0047] In order to more clearly illustrate the technical solutions in the embodiments of the present application or related technologies, the drawings required for use in the embodiments of the present application or related technical descriptions will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other related drawings can be obtained based on these drawings without paying creative work.

[0048] Figure 1 An application environment diagram of a task processing method in an embodiment;

[0049] Figure 2 is a flowchart of a task processing method in one embodiment;

[0050] Figure 3 is a diagram of a task set in one embodiment;

[0051] Figure 4 A flowchart of a task processing status determination step in one embodiment;

[0052] Figure 5 A flowchart of a task processing step in an embodiment;

[0053] Figure 6 is a flowchart of a task processing method in another embodiment;

[0054] Figure 7 is a flowchart of a task processing method in yet another embodiment;

[0055] Figure 8 is a specific flow chart of a task processing method in one embodiment;

[0056] Fig. 9 A task flow diagram of a task processing method in one embodiment;

[0057] Fig.10 is a detailed flow chart of a task processing method in an embodiment;

[0058] Fig.11 is a structural block diagram of a task processing device in one embodiment;

[0059] Fig.12 is a structural block diagram of a task processing device in another embodiment;

[0060] Fig.13 FIG. 4 is a diagram showing the internal structure of a computer device in one embodiment. DETAILED DESCRIPTION

[0061] 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.

[0062] The task processing method provided in the embodiment of the present application can be applied to Figure 1 In the application environment shown. Among them, the task execution consumer end 102 communicates with the task collection consumer end 104 through the network, and the consumer end 106 includes the task execution consumer end 102 and the task collection consumer end 104. The task execution consumer end 102 refers to the end that executes the task, which can be understood as the server end or server end program that executes the task. The task collection consumer end 104 is the end that collects tasks, which can be understood as the server end or server end program that collects tasks.

[0063] Optionally, the task processing method provided in the embodiment of the present application can be directly applied to Figure 1 The task execution consumer end 102 in the task execution consumer end 102 obtains the task execution instruction from the message queue during the task processing process; when a global lock is successfully added to the pending task corresponding to the task execution instruction, the target task in the task set corresponding to the pending task is executed according to the task execution instruction; when the target task is executed, the target task is deleted from the task set and the global lock corresponding to the pending task is released; wherein, other tasks in the task set except the target task are executed after the global lock corresponding to the pending task is released.

[0064] Optionally, the task processing method provided in the embodiment of the present application can be directly applied to Figure 1 The task collection consumer end 104 in the task collection consumer end 104, when receiving a task during the task processing process, obtains the task information corresponding to each task; stores each task in the task set corresponding to the task to be processed according to the task information, so that when the task execution consumer end 102 receives the task execution instruction from the message queue and successfully adds a global lock for the task to be processed corresponding to the task execution instruction, executes the target task determined from the task set corresponding to the task to be processed according to the task execution instruction, wherein other tasks in the task set except the target task are executed after the global lock corresponding to the task to be processed is released.

[0065] Optionally, the task processing method provided in the embodiment of the present application can be directly applied to Figure 1The consumer end 106 in the embodiment includes a task collection consumer end 104 and a task execution consumer end 102. When the consumer end 106 is processing tasks, the task collection consumer end 104 is used to obtain the task information corresponding to each task when receiving the task; each task is stored in the task set corresponding to the task to be processed according to the task information; the task execution consumer end 102 is used to obtain the task execution instruction from the message queue; when a global lock is successfully added to the task to be processed corresponding to the task execution instruction, the target task in the task set corresponding to the task to be processed is executed according to the task execution instruction; when the target task is executed, the target task is deleted from the task set and the global lock corresponding to the task to be processed is released; wherein, other tasks in the task set except the target task are executed after the global lock corresponding to the task to be processed is released.

[0066] In an exemplary embodiment, Figure 2 As shown, a task processing method is provided, which is applied to Figure 1 Taking the task execution consumer end 102 in the example as an example, the method includes the following steps S202 to S206. Among them:

[0067] Step S202, obtaining a task execution instruction from a message queue.

[0068] Among them, a message queue is a component that stores and forwards messages in a distributed system, allowing asynchronous communication between different systems or application components. The main purpose of a message queue is to achieve decoupling and asynchronous communication between systems through the sending and receiving of messages, thereby improving the scalability, reliability and flexibility of the system. It can be understood that a message queue is a container for messages, and messages can wait in a message queue before being consumed and processed.

[0069] The task execution instruction refers to a command used to trigger the execution of a task. For example, the task execution instruction is the in-and-out instruction corresponding to the in-and-out task. Specifically, after the task execution consumer obtains the task execution instruction, it successfully adds a global lock to the pending task corresponding to the task execution instruction and executes the target task in the task set corresponding to the pending task according to the task execution instruction.

[0070] In this embodiment, the task execution instruction exists in the message queue in the form of a first-in-first-out message. Optionally, the message queue adopts a message queue based on RabbitMQ, where RabbitMQ can realize asynchronous communication between different applications or services. Exemplarily, in RabbitMQ, the message producer is responsible for generating messages and sending them to the message queue of RabbitMQ, and the task execution consumer receives messages from the message queue and performs consumption processing. It can be understood that this processing mechanism enables RabbitMQ to realize asynchronous communication of messages in a distributed system, thereby decoupling applications and improving the processing power and throughput of the system.

[0071] It should be noted that in order to ensure the orderliness of the task processing process, in actual application scenarios, the task or task message is sent by the message producer to the first message queue, and the orderly collection of each task message is completed based on the first message queue, that is, the orderly tasks to be processed are completed. After the task collection consumer obtains the task from the first message queue, it can place the task in different task sets according to the task information corresponding to the task, and then send the task execution instruction to the second message queue for each task in the task set, so that the task execution consumer can obtain the task execution instruction from the second message queue. It can be understood that the task execution instruction placed in the second message queue first will be obtained by the task execution consumer first. Among them, the message producer can also be called a "message producer", and the task collection consumer can also be called a "task collection consumer".

[0072] Optionally, in some specific embodiments, the method for obtaining the task execution instruction from the message queue, that is, the method for obtaining the task execution instruction from the second message queue can be an active acquisition method, that is, the task execution consumer end can actively obtain the task execution instruction from the second message queue to perform the task execution operation. For example, when it is detected that there is a task execution instruction in the second message queue, the task execution instruction can be actively obtained from the second message queue, or it can be a preset time interval method or a timed acquisition method to actively obtain the task execution instruction from the second message queue; the method for obtaining the task execution instruction from the second message queue can also be a passive acceptance method, that is, the task execution consumer end passively receives the task execution instruction sent from the second message queue and performs the task execution operation. For example, as long as there is a task execution instruction in the second message queue, the task execution instruction is sent to the task execution consumer end, etc. This embodiment does not limit this.

[0073] Optionally, the first message queue adopts a single-active mode queue to ensure the orderliness of the task collection consumer end consuming messages from the first message queue, so as to realize placing the tasks in different task sets in order according to the task information. It can be understood that the messages storing tasks in the first message queue include tasks with different task information and / or tasks with the same task information. Among them, tasks with different task information can be tasks with different task objects, tasks with different task types, or tasks with different task objects and task types. Tasks with the same task information can refer to tasks with the same task type, tasks with the same task object, or tasks with the same task type and task object.

[0074] Optionally, the task collection consumer puts the tasks in different task sets according to the task information corresponding to the tasks, and then sends a task execution instruction to the second message queue corresponding to each message put into the task set. For each message put into the task set, a task execution instruction is sent to the second message queue to ensure that the task execution instruction executes the task that has been put into the task set. Alternatively, when the number of messages put into the task set is greater than or equal to a preset value, the task execution instruction of each message corresponding to the number of messages greater than or equal to the preset value is put into the second message queue. Alternatively, when no message is put into the task set within a preset time period, it indicates that there is no task belonging to the task set at present, and the task execution instruction of each message in the task set is put into the second message queue. There is no limitation on this.

[0075] Optionally, the number of message producers is at least one, and the number of task collection and consumption terminals is at least one.

[0076] Step S204, when a global lock is successfully added to the pending task corresponding to the task execution instruction, a target task in the task set corresponding to the pending task is executed according to the task execution instruction.

[0077] Among them, global lock refers to a mechanism for locking the entire database instance. Specifically, the main function of global lock is to ensure that the database is in a state of consistency and integrity during a specific operation. When a global lock is applied, the entire database instance will become read-only, which means that during this period, other transactions or threads will not be able to execute data update statements (such as INSERT, UPDATE, DELETE, etc.), data definition statements (such as CREATE TABLE, ALTER TABLE, etc.) and commit statements of update transactions.

[0078] For example, after successfully adding a global lock to the pending task corresponding to the task execution instruction, the global lock of the pending task will carry the lock information (task object and task type). Therefore, when the task execution consumer determines whether there is a target task execution consumer that has added a global lock to the pending task, it can make a judgment based on the lock information.

[0079] Specifically, after adding a global lock at the task execution consumer end, it can be determined whether the global lock has been successfully added to the pending task based on the identification value of the lock identifier with lock information. Exemplarily, when the identification value of the lock identifier is the same as the preset identification value, it indicates that the pending task has successfully added a global lock. When the identification value of the lock identifier is different from the preset identification value, it indicates that the pending task has not been added with a global lock. The identification value of the lock identifier is set to the preset identification value to add a global lock to the pending task. Optionally, the preset identification value is a non-zero value. It can be understood that after the task execution consumer end completes the execution of the target task, the global lock will be released. Therefore, the pending task corresponding to the target task can be added with a global lock by other task execution consumers.

[0080] Exemplarily, when there is at least one task execution consumer, after one of the target execution consumer adds a global lock to the pending task, other task execution consumer except the target execution consumer cannot process the pending task to which the global lock has been added. The at least one task execution consumer includes the target execution consumer.

[0081] It should be noted that pending tasks refer to tasks waiting to be processed by the task execution consumer end. The task information of pending tasks includes task objects and / or task types. Among them, the task object can be regarded as a task request object or a task initiation object. Task type refers to the task category divided according to the specific characteristics and requirements of the task. For example, the task types include warehousing tasks, price adjustment tasks, price synchronization push services, inventory synchronization push services, archive life cycle change services, promotion status change services, and incremental data synchronization services. The task set corresponding to the pending tasks refers to a set formed by at least one task with the same task information. Among them, the same task information can refer to the same task type, or it can refer to the same task type and task object, and there is no limitation on this.

[0082] Optionally, the task set of pending tasks can be divided according to the task type, or according to the task object and the task type, and there is no limitation on this. Exemplarily, the task set of pending tasks is divided according to the task object and the task type. Assuming that the task object, i.e., the task request object, is merchant 1, and the task type is an inbound and outbound task, the tasks stored in the task set of pending tasks include outbound tasks and / or inbound tasks.

[0083] It can be understood that tasks are divided into different task sets according to the task information corresponding to the tasks, and the final task set is at least one, wherein a task set refers to a task set containing at least one task. Figure 3 As shown, in the task processing process, there are multiple pending tasks (such as price adjustment tasks and in-and-out-of-warehouse tasks, etc.) and multiple task objects, and each task object will correspond to multiple pending tasks that need to be executed. That is, in the process of task set division, on the one hand, for each pending task, each task object can have a task set corresponding to the pending task; on the other hand, for each pending task, there can also be a task set corresponding to the pending task. For example, corresponding task sets can be established for price adjustment tasks and in-and-out-of-warehouse tasks respectively. For the task set of price adjustment tasks, the task types of the tasks included in the task set are all price adjustment tasks, and the task objects corresponding to each price adjustment task may be different. For another example, a corresponding task set can be established for the price adjustment task of task object 1, and the task set only contains the price adjustment task of task object 1.

[0084] The target task refers to the first task at the head of the task set in the task set of pending tasks. For example, assuming that the task type of the pending task is an inbound and outbound task (including outbound tasks and inbound tasks), and the task object is task object 1, then when the task execution consumer determines that the pending task is an inbound and outbound task based on the task execution instruction, it is also necessary to execute the outbound task or inbound task in the task set corresponding to the inbound and outbound task according to the task execution instruction.

[0085] Specifically, in order to ensure that each pending task is processed by only one task execution consumer, the task execution consumer can attempt to add a global lock to the pending task corresponding to the task execution instruction when it obtains the task execution instruction. If the global lock is added successfully, it indicates that the pending task has not been processed by other task execution consumers before the global lock is successfully added. Therefore, the target task in the task set corresponding to the pending task can be executed according to the task execution instruction. During this period, if other task execution consumers obtain the task execution instruction corresponding to the pending task, since the global lock has been successfully added to the pending task, other task execution consumers cannot add a global lock to the pending task. Exemplarily, if the global lock fails to be added, it indicates that the pending task has been processed by other task execution consumers when trying to add the global lock. At this time, the task execution instruction needs to be re-added to the message queue such as the second message queue. Among them, the instruction information corresponding to the task execution instruction includes the task object and the task type. The task execution consumer end can determine the task set corresponding to the task to be processed based on the instruction information, and determine the target task from the task set. Optionally, the target task refers to the first task located at the head of the task set. The task execution consumer end can always obtain the first task from the head of the task set based on the task execution instruction, so that each task in the task set is executed sequentially and one by one in the order of placement from the head of the task set to the tail of the task set, so as to ensure the orderliness of the execution of each task in the task set.

[0086] Exemplarily, to facilitate understanding of the implementation process of step S204, an example is provided below for explanation. The pending task is a task whose task object is merchant 1 and whose task type is an in-and-out task. The order of tasks placed in the task set corresponding to the pending task from the head of the task set to the tail of the task set is the out-of-warehouse task and the in-warehouse task, that is, the order of obtaining the tasks is to obtain the out-of-warehouse task first and then the in-warehouse task, or the order of executing the tasks is to execute the out-of-warehouse task first and then the in-warehouse task. When the task execution consumer end 1 receives the task execution instruction 1 such as the in-and-out instruction from the message queue such as the second message queue, assuming that the pending task corresponding to the task execution instruction 1 is a task whose task object is merchant 1 and whose task type is an in-and-out task, when the task execution consumer end 1 successfully adds a global lock for the pending task, the out-of-warehouse task in the task set is executed according to the task execution instruction.

[0087] Step S206, when the target task is executed, the target task is deleted from the task set, and the global lock corresponding to the task to be processed is released.

[0088] Among them, other tasks except the target task in the task set are executed after the global lock corresponding to the pending task is released, which means that as long as there is a target task in the task set that is in the executed state, other tasks except the target task in the task set need to wait for the target task to be executed before they can be executed. Combined with the order of placing tasks from the head of the task set to the tail of the task set, they are placed in order according to the time when the tasks are generated, so that each task from the head of the task set to the tail of the task set is executed in order according to the time when the tasks are generated. Exemplarily, the condition for the orderly execution of each task is that after the target task at the head of the task set is completed and the global lock corresponding to the pending task is released, each task is executed in order.

[0089] Exemplarily, when there is only one task execution consumer end, the task execution consumer end deletes the target task from the task set when the target task is executed, and releases the global lock corresponding to the pending task; when there are at least two task execution consumers, each task execution consumer end deletes the target task from the task set when the target task is executed, and releases the global lock corresponding to the pending task;

[0090] Specifically, if the task execution consumer has completed the execution of the target task, in order to ensure the normal execution of other tasks in the pending tasks, it is necessary to delete the target task from the task set and release the global lock corresponding to the pending task. At this time, other task execution consumers can obtain the global lock of the pending task and execute operations on other tasks in the task set except the target task.

[0091] In a specific embodiment, when the number of execution failures of the target task corresponding to the task execution instruction reaches a preset number, it may be that there is an exception in the target task itself, resulting in the target task being unable to be executed successfully. At this time, in order for tasks other than the target task in the task set to be executed, the abnormal target task needs to be deleted from the task set.

[0092] Exemplarily, to facilitate understanding of the specific implementation process of step S206, the above-mentioned pending task is also taken as an example in which the task object is merchant 1 and the task type is an inbound and outbound task. It is easy to understand that when there is only one task execution consumer end, since the task execution consumer end 1 executes the outbound task in the task set according to the task execution instruction, the task execution instruction will only be obtained from the message queue when the outbound task is completed. In other words, each task in the task set corresponding to the pending task is executed in order according to the task generation time, that is, after the outbound task is completed, the inbound task is executed. When there is only one task execution consumer end, there will be no situation in which two tasks in the task set are executed synchronously.

[0093] When there are at least two task execution consumer ends, during the execution of the outbound task, assuming that the pending task corresponding to the task execution instruction 2 received by the task execution consumer end 2 is a task whose task object is merchant 1 and whose task type is an inbound and outbound task, since the pending task has been successfully added with a global lock by the task execution consumer end 1, at this time, the task execution consumer end 2 fails to add a global lock to the pending task, which means that the task execution consumer end 2 cannot execute the inbound task in the task set according to the task execution instruction 2. At this time, the task execution consumer end 2 rejects the task execution instruction 2 and adds the task execution instruction 2 to the message queue again. Column; when the outbound task is completed, the target task is deleted from the task set. At this time, the task at the head of the task set is the inbound task, and the global lock corresponding to the pending task is released, indicating that the pending task is in a state where a global lock can be added. At this time, if the task execution consumer end 3 receives the task execution instruction 2 corresponding to the pending task whose task object is merchant 1 and whose task type is an inbound and outbound task, since the global lock has not been added to the pending task, the task execution consumer end 3 can obtain the inbound task in the task set according to the task execution instruction and execute the inbound task when the global lock is successfully added to the pending task.

[0094] In the above-mentioned task processing method, before task processing, the task execution consumer obtains the task execution instruction from the message queue, and achieves the purpose of executing the task based on the task execution instruction. Compared with the method of directly accepting the task execution instruction to execute the task without using the message queue, the orderliness of task execution processing is greatly improved. Afterwards, the task execution consumer can try to add a global lock to the pending task corresponding to the task execution instruction. When the pending task corresponding to the task execution instruction has not been processed by other consumers except the task execution consumer, a global lock can be successfully added to the pending task corresponding to the task execution instruction. At this time, it indicates that the pending task can be processed by the task execution consumer. The task execution consumer executes the target task in the task set corresponding to the pending task according to the task execution instruction, indicating that the target task in the pending task is in a state of being executed by the task execution consumer and has not been completed. In the above task processing process, before each task is executed, you can try to add a global lock to the pending task corresponding to the task execution instruction. Under the premise of ensuring that the pending task to be executed is not currently being processed by other consumer ends except the task execution consumer end, you can successfully add a global lock to the pending task, and avoid other subsequent task execution consumer ends from repeatedly processing the task, thereby ensuring the orderliness of the task processing process. Finally, when the target task is executed, delete the target task from the task set, and release the global lock corresponding to the pending task, which can ensure that the target task in the task set corresponding to the pending task has been executed, and the pending task or other tasks in the task set except the target task can be processed by the consumer end (the consumer end includes the task execution consumer end).

[0095] In addition, other tasks in the task set except the target task are executed after the global lock corresponding to the pending task is released, which can ensure that during the processing of the target task, the pending task will not be processed by other task execution consumer ends. Since the target task and other tasks are subtasks in the pending task, the above method can ensure that even when a subtask of the pending task is being processed, other subtasks will not be processed by other task execution consumer ends, thereby achieving the orderliness of the execution order of multiple subtasks. That is, the above method can achieve the purpose of orderly execution of multiple pending tasks and multiple subtasks of the same pending task.

[0096] In an exemplary embodiment, Figure 4 As shown, after executing the target task, it includes:

[0097] Step S402, determining the processing status of the target task;

[0098] Step S404, when the processing status of the target task is execution completed, deleting the target task and the task execution instruction of the target task;

[0099] Step S406: when the processing status of the target task is execution failure, the task execution instruction is added to the message queue again.

[0100] The processing status can be used to characterize the processing status of the target task, and the processing status includes two states: execution completion and execution failure.

[0101] Specifically, after the task execution consumer executes the target task, in order to ensure the orderly progress of the task execution process, it is also necessary to confirm the processing status of the target task, so as to facilitate the normal progress of the subsequent task execution process. If the processing status of the target task is completed, it means that the task execution consumer has completed the processing of the target task. Therefore, the target task and the task execution instruction corresponding to the target task can be deleted, which means that the processing process of the target task is completed. If the processing status of the target task is failed to execute, it means that the task execution consumer may have an error in the process of executing the target task, resulting in the task not being executed successfully, but the target task still needs to be executed. Therefore, the task execution instruction of the target task needs to be re-added to the message queue and wait to be re-acquired.

[0102] In this embodiment, after executing the target task, the processing status of the target task is also determined, which is conducive to ensuring the stable progress of the subsequent task execution process. When the processing status of the target task is completed, the target task and the task execution instruction of the target task are deleted in time to avoid overload caused by the stacking of task sets and message queue data. When the processing status of the target task is failed execution, the task execution instruction is re-added to the message queue, so that the failed target task can be reprocessed in time, thereby improving the efficiency of task processing.

[0103] In an exemplary embodiment, the number of task execution consumers is at least two, such as Figure 5 As shown, the task processing method includes:

[0104] Step S502, at least two task execution consumers respectively obtain corresponding task execution instructions from the message queue;

[0105] Step S504, determining whether the target task execution consumer end has successfully added a global lock to the pending task corresponding to the task execution instruction among the at least two task execution consumer ends;

[0106] Step S506, if the target execution consumer has successfully added a global lock to the task to be processed, reject the task execution instruction;

[0107] Step S508, in the case that there is no target execution consumer end adding a global lock to the pending task, based on each task execution consumer end, when a global lock is successfully added to the pending task corresponding to the task execution instruction, the target task in the task set corresponding to the pending task is executed according to the task execution instruction.

[0108] The target execution consumer is one of the at least two task execution consumers, and refers to the task execution consumer that has successfully added a global lock to the pending task corresponding to the task execution instruction.

[0109] Specifically, when the number of task execution consumer ends is at least two, at this time, at least two task execution consumer ends respectively obtain the corresponding task execution instructions from the message queue, and need to judge whether the pending task corresponding to each task execution instruction has been added with a global lock based on the lock identifier that carries the lock information (task object and task type) of the global lock. That is, it is necessary to judge whether there is a target task execution consumer end in the task execution consumer end that has successfully added a global lock to the pending task corresponding to the task execution instruction. If so, it indicates that the pending task has been processed by the target task execution consumer end, and therefore, the task execution instruction needs to be rejected; if there is no target task execution consumer end that has successfully added a global lock to the pending task corresponding to the task execution instruction, it indicates that the task execution consumer end can add a global lock to the pending task corresponding to the task execution instruction. At this time, the task execution consumer end can successfully add a global lock to the pending task corresponding to the task execution instruction, and execute the target task in the task set corresponding to the pending task according to the task execution instruction.

[0110] Exemplarily, the task information of the pending tasks corresponding to the task execution instructions may be the same or different. When the task information of the pending tasks corresponding to the task execution instructions is the same, at least two task execution consumers execute the pending tasks in sequence according to the order in which they obtain the corresponding task execution instructions. For example, the first task execution consumer preferentially obtains the task execution instruction from the second message queue, and the first task execution consumer preferentially processes the pending task, and the second task execution consumer processes the pending task after the first task execution consumer completes the execution. When the task information of the pending tasks corresponding to the task execution instructions is different, at least two task execution consumers each execute the pending tasks in parallel. That is, at least two task execution consumers can respectively and simultaneously obtain their respective corresponding task execution instructions, and simultaneously execute their respective pending tasks.

[0111] Based on the lock identifier of the global lock that carries lock information (task object and task type), it is determined whether the pending task corresponding to each task execution instruction has been added with a global lock. Specifically, the pending task corresponding to each task execution instruction can be determined, and the task information of the pending task, such as the task object and task type, can be obtained. When the identification value of the lock identifier is the same as the preset identification value, and the lock information carried by the lock identifier is the same as the task information of the pending task, it indicates that the pending task corresponding to the task execution instruction has been added with a global lock, and the target task execution consumer end has successfully added a global lock to the pending task; when the identification value of the lock identifier is different from the preset identification value, and the lock information carried by the lock identifier is the same as the task information of the pending task, it indicates that the pending task corresponding to the task execution instruction has not been added with a global lock, and there is no task in the task set corresponding to the pending task executed by the target task execution consumer end.

[0112] For example, assuming that the lock identifier carrying lock information has a corresponding identification value of 1, the task object in the lock information is merchant 1, the task type is an in-and-out warehouse task, the preset identification value is 1, and the task information of the pending task corresponding to the task execution instruction: the task object is merchant 1, and the task type is an in-and-out warehouse type, then it indicates that the pending task corresponding to the task execution instruction has been added with a global lock, and there is a task in the task set corresponding to the pending task that is executed by the target task execution consumer end.

[0113] In this embodiment, when the number of task execution consumer ends is at least two, it is possible to first determine whether there is a target task execution consumer end among the task execution consumer ends that has successfully added a global lock to the pending task corresponding to the task execution instruction. The two situations of existence and non-existence are processed separately. When there is a target task execution consumer end, the task execution instruction can be rejected in time to facilitate the normal execution of tasks by other subsequent task execution consumers. When there is no target task execution consumer end, a global lock can be added to the pending task in time and task processing can be performed. At this time, other tasks in the pending task cannot be executed, which can ensure the orderliness of task execution and thereby improve task processing efficiency.

[0114] In an exemplary embodiment, the execution mode in which at least two task execution consumers respectively execute the target tasks includes at least one of the following modes: when the task types of the target tasks are the same but the task objects are different, the corresponding target tasks are executed in parallel; when the task types of the target tasks are different but the task objects are the same, the corresponding target tasks are executed in parallel; when the task types of the target tasks are different but the task objects are different, the corresponding target tasks are executed in parallel; when the task types of the target tasks are the same but the task objects are the same, the corresponding target tasks are executed in the order of the task set.

[0115] It should be noted that in the actual application process, taking the warehousing and outbound tasks as an example, there are many cost accounting methods, but no matter whether it is batch accounting, mobile weighting or the last purchase price method, the order of warehousing and outbound will affect the merchant's cost or gross profit. If the merchant uses the mobile weighting mode, the current inventory quantity of merchant product A is 1, the cost price is 1 yuan, and the cost amount is 1 yuan. The merchant first performs the warehousing operation, the warehousing quantity is 2, the unit price is 2.5 yuan, and the cost amount is 5 yuan, and then performs the outbound operation, the outbound quantity is 1, the outbound unit price is 3 yuan, and the outbound amount is 3 yuan.

[0116] Calculated in the normal order: after the goods are put into storage, the actual inventory of the merchant is 3 (pieces) = 1 (piece) + 2 (pieces), the cost amount is 6 (yuan) = 1 (yuan) + 5 (yuan), and the cost unit price is recalculated as 2 (yuan) = 6 (yuan) ÷ 3 (yuan). The gross profit generated by the outbound shipment is calculated according to the formula of 1 (yuan) = 3 (yuan) - 1 (yuan) * 2 (yuan) (gross profit = outbound amount - quantity * cost unit price). The merchant obtains a positive gross profit of 1 yuan. Calculated according to the outbound operation before the inbound operation: the gross profit generated after the outbound shipment is 2 (yuan) = 3 (yuan) - 1 (yuan) * 1 (yuan) (gross profit = outbound amount - quantity * cost unit price). At this time, the inventory is 0. If the inbound operation is performed again, the inventory is 2 (pieces) after the inbound operation is successful, the cost amount is 5 (yuan), and the cost unit price is 2.5 (yuan).

[0117] According to the above examples, it can be seen that for tasks of the same task type, and / or the same task object, and the same type of tasks, there are strict requirements for the execution order of tasks. The execution order of tasks for inbound and outbound tasks will affect the merchant's cost and gross profit calculation. It can be understood that different merchants and the same task type have no effect on the execution order of tasks, that is, different merchants can perform the same task at the same time. For example, for task objects such as merchant 1, merchant 2, and merchant 3, merchant 1, merchant 2, and merchant 3 can perform their respective inbound and outbound tasks at the same time. Among them, the task type includes but is not limited to inbound and outbound tasks, price adjustment tasks, price synchronization push services, inventory synchronization push services, archive life cycle change services, promotion status change services, and incremental data synchronization services. Among them, the task type refers to the task category or business type divided according to the specific characteristics and requirements of the task. For example, the task type can include inbound and outbound tasks and resource mobilization tasks. The task object refers to the object of the task, which can be understood as the task request object, task requester, task initiator object, or task initiator.

[0118] To facilitate understanding of the solution in this embodiment, example X is used for specific explanation below. Example X is as follows: Assume that at least two task execution consumer ends include task execution consumer end 1, task execution consumer end 2 and task execution consumer end 3, and the task execution instructions placed from the head of the queue to the tail of the queue in the message queue are, in sequence, the in / out instruction 1 of task object 1, the in / out instruction of task object 2, the in / out instruction 2 of task object 1, the price adjustment instruction of task object 3, the in / out instruction of task object 3 and the price adjustment instruction of task object 1, wherein the messages in the message queue, such as the task execution instructions, are consumed in a "first in, first out" order, that is, after the message is put into the tail of the message queue, it is obtained from the head of the queue.

[0119] In addition, the pending tasks corresponding to the above task execution instructions are: the inbound and outbound tasks of task object 1, the inbound and outbound tasks of task object 2, the inbound and outbound tasks of task object 1, the price adjustment task of task object 3, the inbound and outbound tasks of task object 3, and the price adjustment task of task object 1.

[0120] At least two task execution consumer ends obtain corresponding task execution instructions from the message queue respectively. Assume that task execution consumer end 1 obtains the in / out instruction 1 of task object 1 from the message queue, task execution consumer end 2 obtains the in / out instruction 1 of task object 2 from the message queue, and task execution consumer end 3 obtains the in / out instruction 2 of task object 1 from the message queue.

[0121] Determine whether there is a target task execution consumer end in at least two task execution consumer ends that has successfully added a global lock to the pending task corresponding to the task execution instruction;

[0122] If the target execution consumer has successfully added a global lock to the task to be processed, the task execution instruction is rejected;

[0123] In the absence of a target execution consumer adding a global lock to the pending task, based on each task execution consumer, when a global lock is successfully added to the pending task corresponding to the task execution instruction, the target task in the task set corresponding to the pending task is executed according to the task execution instruction.

[0124] Assuming that task execution consumer end 1 has successfully added a global lock to the in-and-out tasks of task object 1, task execution consumer end 1 will execute the target task in the task set corresponding to the in-and-out tasks of task object 1; since there is no target execution consumer end to process the in-and-out tasks of task object 2, that is, there is no target execution consumer end to add a global lock to the in-and-out tasks of task object 2, task execution consumer end 2 can also successfully add a global lock to the in-and-out tasks of task object 2, and execute the target task in the task set corresponding to the in-and-out tasks of task object 2; and since there is a target task execution consumer end, that is, task execution consumer end 1, to process the in-and-out tasks of task object 1, task execution consumer end 3 cannot add a global lock to the in-and-out tasks of task object 1 before task execution consumer end 1 completes the execution of the in-and-out tasks of task object 1, and will reject the in-and-out instruction 2 of task object 1, and re-add the in-and-out instruction 2 of task object 1 to the message queue, and needs to wait again to obtain a new task execution instruction. Optionally, when the target tasks have the same task type but different task objects, the corresponding target tasks are executed in parallel.

[0125] Corresponding to the above example X, when the task types of the target tasks are the same but the task objects are different, the corresponding target tasks are executed in parallel, that is, the target tasks in the task set corresponding to the inbound and outbound tasks of task object 1 executed by the task execution consumer end 1 and the target tasks in the task set corresponding to the inbound and outbound tasks of task object 2 executed by the task execution consumer end 2 can be executed in parallel to improve the task execution efficiency.

[0126] Optionally, when the target tasks have different task types but the same task objects, the corresponding target tasks are executed in parallel.

[0127] Corresponding to the above-mentioned example X, when the task types of the target tasks are different but the task objects are the same, the corresponding target tasks are executed in parallel, that is, the target task in the task set corresponding to the warehousing task of task object 1 and the target task in the task set corresponding to the price adjustment task of task object 1 can be executed in parallel, or, the target task in the task set corresponding to the price adjustment task of task object 3 and the target task in the task set corresponding to the warehousing task of task object 3 can be executed in parallel to improve the task execution efficiency.

[0128] Optionally, when the target tasks have different task types and different task objects, the corresponding target tasks are executed in parallel.

[0129] Corresponding to the above example X, when the target tasks have different task types and different task objects, the corresponding target tasks are executed in parallel, that is, the target tasks in the task set corresponding to the warehousing and warehousing tasks of task object 1 and the target tasks in the task set corresponding to the price adjustment tasks of task object 3 can be executed in parallel to improve the task execution efficiency.

[0130] Optionally, when the target tasks have the same task type and the same task object, the corresponding target tasks are executed in the order of the task set.

[0131] Corresponding to the above example X, when the task type and task object of the target task are the same, the corresponding target tasks are executed in the order of the task set. Assume that the order of tasks in the task set of pending tasks of task object 1 from the head of the task set to the tail of the task set is outbound tasks and inbound tasks. Based on the inbound and outbound instruction 1 of task object 1, if the global lock has been successfully added to the inbound and outbound tasks of task object 1, task execution consumer end 1 will execute the target task in the task set corresponding to the inbound and outbound tasks of task object 1. The target task is also the outbound task. During the execution of the outbound task by task execution consumer end 1, task execution consumer end 2 and task execution consumer end 3 cannot add a global lock to the inbound and outbound tasks of task object 1, and both will reject the inbound and outbound instruction 2 of task object 1.

[0132] When the task execution consumer end 1 completes the outbound task and releases the global lock of the inbound and outbound task of task object 1, at this time, if the task execution consumer end 3 receives the inbound and outbound instruction 2 of task object 1, it can successfully add a global lock to the inbound and outbound task of task object 1, and execute the target task in the task set corresponding to the inbound and outbound task of task object 1, that is, the inbound task, so as to achieve the purpose of executing the corresponding target tasks in the order of the task set when the task type and task object of the target task are the same, ensuring the orderly execution of each task in the task set corresponding to the same task type, the same task object or the same task type.

[0133] In this embodiment, the execution process of at least two task execution consumption ends respectively executing the target task covers four scenarios with different or same task types and task objects, and fully realizes the purpose of orderly execution of task processing.

[0134] In an exemplary embodiment, Figure 6 As shown, a task processing method is also provided, which is applied to the task collection and consumption end, and the method includes:

[0135] Step S602, when a task is received, obtaining task information corresponding to each task;

[0136] Step S604, stores each task in the task set corresponding to the pending task according to the task information, so that when the task execution consumer receives the task execution instruction from the message queue and successfully adds a global lock for the pending task corresponding to the task execution instruction, execute the target task determined from the task set corresponding to the pending task according to the task execution instruction, wherein other tasks in the task set except the target task are executed after the global lock corresponding to the pending task is released.

[0137] The task information refers to task related information required for task processing, for example, the task information may include a task object and a task type, etc. The task object may be represented by a unique code of the task object, for example.

[0138] Specifically, when the task collection consumer receives a task, in order to determine the task set stored for each task, it is necessary to first obtain the task information corresponding to each task. For each task, it is necessary to store the task in the task set corresponding to the task to be processed based on the task information of the task, so that when the task execution consumer receives the task execution instruction from the message queue and successfully adds a global lock to the task to be processed corresponding to the task execution instruction, it executes the target task determined from the task set corresponding to the task to be processed according to the task execution instruction.

[0139] Optionally, the task set of pending tasks can be divided according to the task type, or according to the task object and the task type, and there is no limitation on this. Exemplarily, the task set of pending tasks is divided according to the task object and the task type. Assuming that the task object, i.e., the task request object, is merchant 1, and the task type is an inbound and outbound task, the tasks stored in the task set of pending tasks include outbound tasks and / or inbound tasks.

[0140] Optionally, based on the task information, the tasks are classified and stored in a task set of corresponding tasks to be processed. The List data type in Redis can be used to store the tasks to form a task set.

[0141] Exemplarily, the task collection consumer can use the List data type in Redis to store tasks. When receiving the task, the task collection consumer obtains the task information corresponding to the task. Assuming that the task identifier of the task object in the task information is 9001, and the task type is an in-and-out task, the task is stored in the task set corresponding to the task to be processed according to the task information. This can be achieved through the instruction inout_business:9001.

[0142] The same is true for the way that other tasks are classified into the corresponding task set of pending tasks according to the task information, which is not limited here. It can be understood that the tasks with the same task information are put into the task set from the end of the task set in the order of the time when the tasks were generated, and the tasks in the task set are executed in the order of "first in, first out", which ensures the orderliness of task execution.

[0143] Exemplarily, the task collection consumer can also design a key for the task based on the task identifier and task type (in-and-out warehouse task, price adjustment task, etc.), that is, when receiving a task, obtain the task information corresponding to the task. Assuming that the task identifier of the task object in the task information is 9001, and the task type is an in-and-out warehouse task, then design a corresponding key for the task based on the above task identifier and task type. For example: inout_business:9001, where inout_business represents an in-and-out warehouse task, and 9001 is the unique code of the task object. Execute the command lpush inout_business:9001 [specific task information] (lpush is a redis command, which is used to put specific values ​​from the left (the end of the task set) into a certain set. inout_business represents the in-and-out task, and 9001 is the unique code of the task object. Executing the lpush inout_business:9001'XXX in-warehouse task' command means putting the specific 'XXX in-warehouse task' from the left into the task set of the in-and-out task of the task object 9001), and continuously storing tasks from the left to the corresponding task set of redis, thereby achieving the purpose of placing tasks in different task sets according to task types and task objects.

[0144] In this embodiment, the task collection consumer end is the executor of task processing. When a task is received, the task is stored in order in the task set of the corresponding to-be-processed tasks based on the task information of the task. The tasks can be accurately classified and placed in the corresponding task set in order according to the task information. When the subsequent task execution consumer end obtains the to-be-processed tasks based on the task execution instructions, it can also execute them in order according to the task placement order in the task set based on the task execution instructions.

[0145] In an exemplary embodiment, task information includes task objects and / or task types, and storing each task in a task set corresponding to tasks to be processed according to the task information includes: storing each task in a task set corresponding to tasks to be processed according to the task object and / or task type classification; after storing each task in the task set corresponding to tasks to be processed according to the task information, it includes: generating corresponding task execution instructions based on each task placed in the task set of tasks to be processed, and placing the task execution instructions in a message queue.

[0146] Specifically, task information includes task objects and / or task types. After receiving the tasks and obtaining the task objects and task types corresponding to each task, the task collection consumer can classify each task according to the task object and / or task type and store it in the task set corresponding to the task to be processed.

[0147] Optionally, the task collection consumer can only classify and store each task into the task set corresponding to the task to be processed according to the task type, so as to facilitate the execution of the task by the task execution consumer when the task types of the target tasks are the same but the task objects are different. In this case, since the tasks themselves are stored in the corresponding task set according to the task type, and the task storage process follows the time of task distribution, the task execution consumer can also obtain the tasks in the order of the tasks when obtaining the tasks.

[0148] The task collection consumer can also classify each task and store it in the task set corresponding to the task to be processed according to the task type and task object, so as to facilitate the execution of the task by the task execution consumer when the task type and task object of each target task are different. In this case, since the tasks themselves are stored in the corresponding task set according to the task type, and the task storage process follows the time of task distribution, the task execution consumer can also obtain the tasks in the order of the tasks when obtaining the tasks.

[0149] Specifically, after storing each task in the task set corresponding to the task to be processed according to the task information, the task collection consumer end can generate corresponding task execution instructions based on each task in the task set of the task to be processed, and put the task execution instructions into the message queue. It can be understood that the process of storing each task in the task set corresponding to the task to be processed according to the task information is completed in the time sequence of task initiation, and the process of generating corresponding task execution instructions based on each task in the task set of the task to be processed by the task collection consumer end is also generated in the order in which the tasks are placed. Therefore, after storing each task in the task set corresponding to the task to be processed according to the task information, the task collection consumer end generates corresponding task execution instructions based on each task in the task set of the task to be processed, which can ensure the orderly execution of tasks.

[0150] It is understandable that once the task execution instruction is placed in a message queue such as the second message queue, the task execution instruction may be immediately executed by the task execution consumer. In order to avoid the task being consumed by the task execution consumer before it is placed in the task set corresponding to the pending tasks, resulting in a disordered task execution order, each task needs to be stored in the task set corresponding to the pending tasks according to the task information. Only then will the task collection consumer generate the corresponding task execution instruction based on each task in the task set of the pending tasks, and place the task execution instruction in the message queue.

[0151] Optionally, the task collection consumer may classify each task in a task set and then generate a task execution instruction corresponding to each task, or may generate a task execution instruction corresponding to each task after each task is placed in the task set.

[0152] In this embodiment, the task collection consumer end can classify and store each task according to the task type and task object, or the task type, which can improve the flexibility of task set division; after each task in a task set is classified and placed in the task set, the task execution instructions corresponding to each task are generated respectively, or after each task is placed in the task set, the corresponding task execution instructions are generated for the task, and the appropriate task execution instruction method can be selected based on the actual situation to improve the flexibility of the task execution instruction generation process.

[0153] In an exemplary embodiment, a task processing method is also provided, which is applied to a consumer end, and the consumer end includes a task collection consumer end and a task execution consumer end, such as Figure 7 As shown, the method includes:

[0154] Step S702, when the task collection consumer receives the task, it obtains the task information corresponding to each task; and stores each task in the task set corresponding to the task to be processed according to the task information;

[0155] Step S704, the task execution consumer end is used to obtain the task execution instruction from the message queue; when the global lock is successfully added to the pending task corresponding to the task execution instruction, the target task in the task set corresponding to the pending task is executed according to the task execution instruction; when the target task is executed, the target task is deleted from the task set and the global lock corresponding to the pending task is released; wherein, other tasks in the task set except the target task are executed after the global lock corresponding to the pending task is released.

[0156] Specifically, the task collection consumer end can also execute the above-mentioned steps of classifying each task according to the task object and / or task type and storing it in the task set corresponding to the task to be processed; generating corresponding task execution instructions based on each task in the task set of the task to be processed, and placing the task execution instructions in the message queue.

[0157] The task execution consumer end may also perform the above-mentioned steps of determining the processing status of the target task; when the processing status of the target task is execution completion, deleting the target task and the task execution instruction of the target task; when the processing status of the target task is execution failure, re-adding the task execution instruction to the message queue;

[0158] At least two task execution consumer ends respectively obtain corresponding task execution instructions from the message queue; determine whether a target task execution consumer end among the at least two task execution consumer ends has successfully added a global lock to the pending task corresponding to the task execution instruction; if a target execution consumer end has successfully added a global lock to the pending task, reject the task execution instruction; if no target execution consumer end has added a global lock to the pending task, based on each task execution consumer end, when a global lock is successfully added to the pending task corresponding to the task execution instruction, execute the target task in the task set corresponding to the pending task according to the task execution instruction;

[0159] Among them, when the task types of each target task are the same but the task objects are different, the corresponding target tasks are executed in parallel; when the task types of each target task are different but the task objects are the same, the corresponding target tasks are executed in parallel; when the task types of each target task are different but the task objects are different, the corresponding target tasks are executed in parallel; when the task types of each target task are the same but the task objects are the same, the corresponding target tasks are executed in the order of the task set.

[0160] The specific implementation method of the steps has been described in detail and will not be described in detail in this embodiment.

[0161] Specifically, when the task collection consumer receives a task, in order to determine the task set stored for each task, it needs to first obtain the task information corresponding to each task. For each task, it needs to store the task in the task set corresponding to the pending task based on the task information of the task. After that, the task execution consumer can obtain the task execution instruction from the message queue, and when the global lock is successfully added to the pending task corresponding to the task execution instruction, the target task in the task set corresponding to the pending task is executed according to the task execution instruction. When the target task is executed, the target task is deleted from the task set and the global lock corresponding to the pending task is released.

[0162] It should be noted that the message producer puts the tasks or task messages into the first message queue in the order of task generation. Based on the "first in, first out" consumption order of the messages in the message queue, the task collection and consumption end obtains the tasks from the first message queue in sequence, and puts the tasks into the corresponding task set according to the task information. It can be understood that at this time, the tasks put into the task set are also sorted in the order of task generation. When executing the target tasks in the task set based on the task execution instructions in the second message queue, the execution order of each task in the task set is in the order of task generation.

[0163] For example, assume that the task objects include Merchant 1 and Merchant 2, and the task types include inbound and outbound tasks (including outbound tasks and / or inbound tasks), price adjustment tasks, and promotion status change tasks. The specific order of task generation is as follows:

[0164] Merchant 1 initiates warehousing task 1 at 13:01 on December 24, 2024;

[0165] Merchant 2 initiates warehousing task 1 at 13:30 on December 24, 2024;

[0166] Merchant 1 initiates outbound task 2 at 13:40 on December 24, 2024;

[0167] Merchant 1 initiates price adjustment task 1 at 14:00 on December 24, 2024;

[0168] Merchant 2 initiates promotion status change task 1 at 14:30 on December 24, 2024.

[0169] The message producer places the messages into the first message queue in the order in which the tasks are generated. The order in which the task messages are placed in the first message queue is: merchant 1's incoming task 1, merchant 2's incoming task 1, merchant 1's outgoing task 2, merchant 1's price adjustment task 1, and merchant 2's promotion status change task 1.

[0170] The task collection consumer obtains messages from the first message queue in sequence, and puts the messages into the corresponding task set according to task information such as task correspondence and task type. The obtained task set specifically includes the following:

[0171] In the task set corresponding to the inbound and outbound tasks initiated by merchant 1, the order of placement of tasks is: inbound task 1, outbound task 2;

[0172] In the task set corresponding to the inbound and outbound tasks initiated by merchant 2, the order of placement of tasks is as follows: inbound task 1;

[0173] In the task set corresponding to the price adjustment task initiated by merchant 1, the order of placement of tasks is as follows: price adjustment task 1;

[0174] In the task set corresponding to the promotion status change task initiated by merchant 2, the order of placement of tasks is: promotion status change task 1.

[0175] It is easy to understand that the order in which tasks are placed in the task set is the same as the order in which tasks are executed. For example, in the task set corresponding to the inbound and outbound tasks of merchant 1, when a global lock is successfully added to the task to be processed, that is, the inbound and outbound tasks of merchant 1, after successfully executing inbound task 1, inbound task 1 is deleted from the task set corresponding to the inbound and outbound tasks, and the global lock added to the inbound and outbound tasks of merchant 1 is released. Until a task execution instruction is received, such as an inbound and outbound instruction for merchant 1, when a global lock is successfully added to the task to be processed, that is, the inbound and outbound tasks of merchant 1, outbound task 2 is executed. After the successful execution of outbound task 2, outbound task 2 is deleted from the task set corresponding to the inbound and outbound tasks, and the global lock added to the inbound and outbound tasks of merchant 1 is released.

[0176] In the above-mentioned task processing method, when the task collection consumer receives the task, it stores the task in the task set corresponding to the task to be processed based on the task information of the task, so that the tasks can be accurately classified. When the subsequent task execution consumer obtains the task to be processed based on the task execution instruction, it can also accurately obtain the corresponding task, which is conducive to maintaining the orderly progress of the task processing process. The task execution consumer obtains the task execution instruction from the message queue, which can achieve the purpose of executing tasks based on the task execution instruction. Compared with the method of directly obtaining tasks, the orderliness of task execution processing is greatly improved. Afterwards, the task execution consumer can try to add a global lock for the pending task corresponding to the task execution instruction. When the global lock is successfully added to the pending task corresponding to the task execution instruction, it indicates that the pending task has not been processed by other task execution consumers. Therefore, the task execution consumer can execute the target task in the task set corresponding to the pending task according to the task execution instruction. In the above steps, before each task execution, an attempt is made to add a global lock to the pending task corresponding to the task execution instruction, which can ensure that the task to be executed by the task execution consumer is not being processed by other task execution consumers at this time, and can avoid other subsequent task execution consumers from repeatedly processing the task, which can ensure the orderliness of the task processing process. Finally, when the target task is executed, the target task is deleted from the task set and the global lock corresponding to the pending task is released, which means that the target task of the pending task has been completed, and the pending task is in a state that can be processed by other task execution consumers. In addition, other tasks in the task set except the target task are executed after the global lock corresponding to the pending task is released, which ensures that during the processing of the target task, the pending task will not be processed by other task execution consumers. Since the target task and other tasks can be considered as subtasks in the pending task, the above method can ensure that even during the processing of a subtask of a pending task, other subtasks will not be processed by other task execution consumers. Since multiple subtasks need to be executed in sequence, the purpose of orderly execution between pending tasks and orderly execution of multiple subtasks of the same pending task can be achieved.

[0177] In a specific embodiment, a task processing method in a specific application scenario is also provided. Figure 8 The detailed process is as follows:

[0178] The message containing the task is sent by the message producer to the first message queue, such as the RabbitMq queue. The messages need to be collected in order and put into the task set. At this time, a single-active mode queue is needed to ensure the order of the message when it is consumed by the task collection consumer. After receiving the message, the task collection consumer puts the task into different task sets according to the task type and task object.

[0179] After placing the tasks in each task set, the task execution instruction is sent to the second message queue.

[0180] Among them, the message producer refers to the source of the task. For example, the task document of the outbound task needs to be deducted when reviewing the document. At the same time, the production flow is also required. Some scenarios will also affect the inventory cost price.

[0181] In this embodiment, the task collection consumer can use the List data type in Redis to store tasks. When receiving the task, the task collection consumer designs a key according to the task object and the task type (in and out of storage task, price adjustment task, etc.), for example: inout_business:9001, where inout_business represents the in and out of storage task, and 9001 is the unique code of the task object. Execute the command lpush inout_business:9001 [specific task information] (lpush is a redis command, which is used to put the specific value from the left into a certain set, inout_business represents the in and out of storage task, and 9001 is the unique code of the task object. Executing the lpush inout_business:9001 'XXX in-warehouse task' command means putting the specific 'XXX in-warehouse task' from the left into the task set of the in and out of storage task of the task object 9001), and continuously storing the tasks from the left into the corresponding task set of redis, thereby achieving the purpose of placing the tasks in different task sets according to the task type and task object.

[0182] like Fig. 9 As shown, after receiving the task execution instruction, the task execution consumer executes the command lrange inout_business:9001 -1-1 (lrange is a Redis command, which is used to obtain the target task from a task set. Executing the lrange inout_business:9001 -1-1 command means obtaining the first target task from the rightmost side of the task set of the 9001 task object in and out of the warehouse task) and continues to obtain the first task from the right side of the corresponding task set.

[0183] When the task is executed successfully, set this task as completed and execute the command set inout_business:9001:[task ID]true (set is a redis command, which is used to put information into redis. The purpose of executing set inout_business:9001:[task 1]true is to mark task 1 of the 9001 task object's in-and-out task as completed, indicating that this task has been processed).

[0184] Execute the command rpop inout_business:9001 (rpop is a redis command, which is used to take out and delete the first task on the far right of a specific task set (that is, the head of the task set). The purpose of executing rpop inout_business:9001 is to delete the first task on the far right of the task set of the task object with task identifier 9001) to delete the task from the task set and acknowledge that the task message has been completed (channel.basicAck(tag,false), rabbitmq syntax, manually acknowledge that the message has been received and completed, and rabbitmq will delete the message from the queue after receiving the acknowledgement); if the task fails to execute, the task execution instruction will be re-delivered to the second message queue (channel.basicReject(tag,true), rabbitmq syntax, reject the task execution instruction, and re-deliver the task execution instruction to the second message queue), waiting for the next task to be triggered and executed, where the task is still saved in the task set.

[0185] When the task execution consumer receives the task execution instruction, it obtains the first task from the rightmost side of the task set, executes the task, and deletes the task after completion. When the task fails, the task execution instruction is directly rejected and the task execution instruction is re-delivered to the second message queue.

[0186] like Fig.10As shown, when the task execution consumer ① gets the task execution instruction of task object 1, it first adds a global lock to task object 1001, where the global lock carries lock information such as the task identifier and task type of the task object. It should be noted that one task execution instruction corresponds to one task (such as task object 1 task 1). After the task is completed, the global lock is released (the global lock is released after the task is executed to allow other tasks in the pending tasks corresponding to the task to continue to execute. The global lock needs to be acquired before each task execution instruction is executed in order to reduce the possibility of large task objects affecting small task objects when multiple task objects are concurrent. For example, task execution consumer 1 gets task object 1001 The global lock of the in-and-out tasks is obtained, and the global lock is held until all the in-and-out tasks of task object 1001 are completed. At this time, if task object 1001 continues to have in-and-out tasks, then task execution consumer end 1 will be occupied and execute the tasks of task object 1001. When the number of concurrent task objects is greater than the number of consumers (the number of service nodes), the tasks of other task objects will be blocked. In order to reduce the possibility of large task objects affecting small task objects, we will let the task execution instructions be executed in the order they are sent (the order of instructions does not need to be guaranteed here), so each time a task execution instruction is received, it will try to obtain the global lock, and release the corresponding global lock after execution).

[0187] ① Failed to obtain the global lock: This indicates that there is already a task execution consumer that is processing this pending task. In order to ensure order, this task execution instruction is directly rejected and waits for the next task to be triggered for execution.

[0188] ② Obtaining the global lock successfully: Execute the command lrange inout_business:task object 1 -1-1, which means getting the first task from the right side of the task set of Redis task object 1. Execute the command get inout_business:task object 1:taskId to determine whether this task has been completed (when the task is completed, the command set inout_business:9001:[task 1]true will be executed to mark [task 1] as completed. Execute the command get inout_business:9001:[Task 1] is to get the mark of whether [Task 1] has been completed. If the value is true, it means that it has been successfully executed). If it has been completed, it means that the execution instruction of this task has been executed, but an error occurred in the subsequent deletion task, causing this task to still be in the task set (after the task is completed, it will continue to execute the following two steps: 1. The rpop command will be used to delete the task from redis, and 2. It is necessary to reply to rabbitmq that the execution instruction of this task has been completed. If step 1 is still in the execution process or has not been executed, the server restarts or crashes (with a very small probability), then this task is still in the task set. When the service is restored or other consumer nodes get the task execution instruction again, when they get this task again, they need to determine whether this task has been executed to avoid the situation where the same task is executed repeatedly.), execute the command rpop inout_business:9001 to delete the task and reply that the task message has been completed (channel.basicAck(tag,false)).

[0189] If the task is not completed, continue to execute the corresponding task flow. After successful execution, set the task to complete, execute rpop inout_business:9001 to delete the task, and receive a receipt that the instruction has been completed. If the task fails to execute, since the task still exists in the task set, the task execution instruction is rejected and re-delivered to the second message queue.

[0190] In a specific embodiment, a task processing method is also provided, which is applied to a task execution consumer end, and the method includes:

[0191] Get task execution instructions from the message queue;

[0192] When a global lock is successfully added to the pending task corresponding to the task execution instruction, the target task in the task set corresponding to the pending task is executed according to the task execution instruction;

[0193] Determine the processing status of the target task;

[0194] When the processing status of the target task is execution failure, the task execution instruction is added to the message queue again;

[0195] When the processing status of the target task is execution completed, the target task and the task execution instruction of the target task are deleted from the task set, and the global lock corresponding to the task to be processed is released;

[0196] Among them, other tasks in the task set except the target task are executed after the global lock corresponding to the pending task is released;

[0197] When the number of task execution consumer ends is at least two, the method further includes:

[0198] At least two task execution consumers obtain corresponding task execution instructions from the message queue respectively;

[0199] Determine whether there is a target task execution consumer end in at least two task execution consumer ends that has successfully added a global lock to the pending task corresponding to the task execution instruction;

[0200] If the target execution consumer has successfully added a global lock to the task to be processed, the task execution instruction is rejected;

[0201] In the case that there is no target execution consumer end adding a global lock to the pending task, based on each task execution consumer end, when a global lock is successfully added to the pending task corresponding to the task execution instruction, the target task in the task set corresponding to the pending task is executed according to the task execution instruction;

[0202] The execution mode in which at least two task execution consumers respectively execute the target tasks includes at least one of the following modes:

[0203] When the task types of target tasks are the same but the task objects are different, the corresponding target tasks are executed in parallel;

[0204] When the task types of target tasks are different but the task objects are the same, the corresponding target tasks are executed in parallel;

[0205] When the task types and task objects of the target tasks are different, the corresponding target tasks are executed in parallel;

[0206] When the task types and task objects of the target tasks are the same, the corresponding target tasks are executed in the order of the task set.

[0207] It should be understood that, although the steps in the flowcharts involved in the above embodiments are displayed in sequence according to the indication of the arrows, these steps are not necessarily executed in sequence according to the order indicated by the arrows. Unless there is a clear explanation 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 part of the steps in the flowcharts involved in the above embodiments can 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 carried out in sequence, but can be executed in turn or alternately with other steps or at least a part of the steps or stages in other steps.

[0208] Based on the same inventive concept, the embodiment of the present application also provides a task processing device for implementing the task processing method involved above. The implementation scheme for solving the problem provided by the device is similar to the implementation scheme recorded in the above method, so the specific limitations in one or more task processing device embodiments provided below can refer to the limitations on the task processing method above, and will not be repeated here.

[0209] In an exemplary embodiment, Fig.11 As shown, a task processing device 1100 is provided, comprising: a task execution instruction acquisition module 1102, a target task execution module 1104 and a global lock release module 1106, wherein:

[0210] The task execution instruction acquisition module 1102 is used to acquire the task execution instruction from the message queue;

[0211] The target task execution module 1104 is used to execute the target task in the task set corresponding to the task execution instruction according to the task execution instruction when a global lock is successfully added to the task to be processed corresponding to the task execution instruction;

[0212] The global lock release module 1106 is used to delete the target task from the task set and release the global lock corresponding to the task to be processed when the target task is executed.

[0213] Among them, other tasks in the task set except the target task are executed after the global lock corresponding to the task to be processed is released.

[0214] In an exemplary embodiment, after executing the target task, the task processing device 1100 further includes a processing state determination module, which is specifically used to:

[0215] Determine the processing status of the target task;

[0216] When the processing status of the target task is execution completed, deleting the target task and the task execution instruction of the target task;

[0217] When the processing status of the target task is execution failure, the task execution instruction is added back to the message queue.

[0218] In an exemplary embodiment, the number of task execution consumer terminals is at least two. In this embodiment, the task processing device 1100 further includes a multi-task processing module, which is specifically used to:

[0219] At least two task execution consumers obtain corresponding task execution instructions from the message queue respectively;

[0220] Determine whether there is a target task execution consumer end in at least two task execution consumer ends that has successfully added a global lock to the pending task corresponding to the task execution instruction;

[0221] If the target execution consumer has successfully added a global lock to the task to be processed, the task execution instruction is rejected;

[0222] In the absence of a target execution consumer adding a global lock to the pending task, based on each task execution consumer, when a global lock is successfully added to the pending task corresponding to the task execution instruction, the target task in the task set corresponding to the pending task is executed according to the task execution instruction.

[0223] In an exemplary embodiment, the execution mode in which at least two task execution consumers respectively execute the target tasks includes at least one of the following modes:

[0224] When the task types of target tasks are the same but the task objects are different, the corresponding target tasks are executed in parallel;

[0225] When the task types of target tasks are different but the task objects are the same, the corresponding target tasks are executed in parallel;

[0226] When the task types and task objects of the target tasks are different, the corresponding target tasks are executed in parallel;

[0227] When the task types and task objects of the target tasks are the same, the corresponding target tasks are executed in the order of the task set.

[0228] In an exemplary embodiment, Fig.12 As shown, a task processing device 1200 is provided, including: a task information acquisition module 1202 and a task information storage module 1204, wherein:

[0229] The task information acquisition module 1202 is used to acquire the task information corresponding to each task when receiving the task;

[0230] The task information storage module 1204 is used to store each task in the task set corresponding to the pending task according to the task information, so that when the task execution consumer receives the task execution instruction from the message queue and successfully adds a global lock for the pending task corresponding to the task execution instruction, the target task determined from the task set corresponding to the pending task according to the task execution instruction is executed, wherein other tasks in the task set except the target task are executed after the global lock corresponding to the pending task is released.

[0231] In an exemplary embodiment, the task information includes a task object and / or a task type. In this embodiment, the task information storage module 1204 is used to:

[0232] Classify each task according to the task object and / or task type and store it in a task set corresponding to the task to be processed;

[0233] The task information storage module 1204 is also used for:

[0234] Based on each task in the task set put into the to-be-processed tasks, a corresponding task execution instruction is generated, and the task execution instruction is put into the message queue.

[0235] In an exemplary embodiment, a task processing device is provided, which is applied to a consumer end, and the consumer end includes a task collection consumer end and a task execution consumer end, wherein:

[0236] The task collection consumer end is used to obtain the task information corresponding to each task when receiving the task; and store each task in the task set corresponding to the task to be processed according to the task information;

[0237] The task execution consumer end is used to obtain task execution instructions from the message queue; when a global lock is successfully added to the pending task corresponding to the task execution instruction, the target task in the task set corresponding to the pending task is executed according to the task execution instruction; when the target task is executed, the target task is deleted from the task set and the global lock corresponding to the pending task is released; among them, other tasks in the task set except the target task are executed after the global lock corresponding to the pending task is released.

[0238] Each module in the above task processing device can be implemented in whole or in part by software, hardware or a combination thereof. Each module can be embedded in or independent of a processor in a computer device in the form of hardware, or can be stored in a memory in a computer device in the form of software, so that the processor can call and execute operations corresponding to each module.

[0239] In an exemplary embodiment, a computer device is provided. The computer device may be a terminal, and its internal structure diagram may be as shown in FIG. Fig.13 As shown. The computer device includes a processor, a memory, an input / output interface, a communication interface, a display unit and an input device. Among them, the processor, the memory and the input / output interface are connected through a system bus, and the communication interface, the display unit and the input device are connected to the system bus through the input / output interface. 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 and a computer program. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The input / output interface of the computer device is used to exchange information between the processor and an external device. The communication interface of the computer device is used to communicate with an external terminal in a wired or wireless manner, and the wireless manner can be implemented through WIFI, a mobile cellular network, near field communication (Near Field Communication, NFC) or other technologies. When the computer program is executed by the processor, a task processing method is implemented. The display unit of the computer device is used to form a visually visible picture, which can be a display screen, a projection device or a virtual reality imaging device. The display screen can be a liquid crystal display screen or an electronic ink display screen, and the input device of the computer device can be a touch layer covering the display screen, or a button, trackball or touchpad set on the computer device shell, or an external keyboard, touchpad or mouse.

[0240] Those skilled in the art will understand that Fig.13 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.

[0241] In one embodiment, a computer device is provided, including a memory and a processor, wherein a computer program is stored in the memory, and the processor implements the steps of the above method when executing the computer program.

[0242] In one embodiment, a computer-readable storage medium is provided, on which a computer program is stored, and when the computer program is executed by a processor, the steps of the above method are implemented.

[0243] In one embodiment, a computer program product is provided, comprising a computer program, which implements the steps of the above method when executed by a processor.

[0244] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of relevant data must comply with relevant regulations.

[0245] 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 the memory, database or other medium used in the embodiments provided in the present application can include at least one of non-volatile memory and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetic random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. 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). The database involved in each embodiment provided in this application may include at least one of a relational database and a non-relational database. Non-relational databases may include distributed databases based on blockchains, etc., but are not limited to this. The processor involved in each embodiment provided in this application may be a general-purpose processor, a central processing unit, a graphics processor, a digital signal processor, a programmable logic device, a data processing logic device based on quantum computing, an artificial intelligence (AI) processor, etc., but are not limited to this.

[0246] 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 application.

[0247] The above-described 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 present application. 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 present application shall be subject to the attached claims.

Claims

1. A task processing method, characterized in that: Applied to the task execution consumer end, the method includes: Get task execution instructions from the message queue; When a global lock is successfully added to the pending task corresponding to the task execution instruction, executing the target task in the task set corresponding to the pending task according to the task execution instruction; When the target task is completed, the target task is deleted from the task set, and the global lock corresponding to the task to be processed is released; Among them, other tasks in the task set except the target task are executed after the global lock corresponding to the task to be processed is released.

2. The method according to claim 1, characterized in that After executing the target task, it includes: Determining a processing status of the target task; When the processing status of the target task is execution completed, deleting the target task and the task execution instruction of the target task; When the processing status of the target task is execution failure, the task execution instruction is added to the message queue again.

3. The method according to claim 1 or 2, characterized in that: The number of the task execution consumer ends is at least two, and the method includes: At least two task execution consumers obtain corresponding task execution instructions from the message queue respectively; Determine whether the target task execution consumer end has successfully added a global lock to the pending task corresponding to the task execution instruction among at least two task execution consumer ends; If the target execution consumer has successfully added a global lock to the task to be processed, reject the task execution instruction; In the absence of the target execution consumer adding a global lock to the pending task, based on each of the task execution consumers, when a global lock is successfully added to the pending task corresponding to the task execution instruction, the target task in the task set corresponding to the pending task is executed according to the task execution instruction.

4. The method according to claim 3, characterized in that The execution mode in which at least two task execution consumers respectively execute the target task includes at least one of the following modes: When the target tasks have the same task type but different task objects, the corresponding target tasks are executed in parallel; When the target tasks have different task types but the same task objects, the corresponding target tasks are executed in parallel; When the target tasks have different task types and different task objects, the corresponding target tasks are executed in parallel; When the target tasks have the same task type and the same task object, the corresponding target tasks are executed in the order of the task set.

5. A task processing method, characterized in that: Applied to the task collection consumer end, the method includes: When receiving a task, obtaining task information corresponding to each task; Each of the tasks is stored in the task set corresponding to the pending task according to the task information, so that when the task execution consumer receives the task execution instruction from the message queue and successfully adds a global lock for the pending task corresponding to the task execution instruction, the target task determined from the task set corresponding to the pending task according to the task execution instruction is executed, wherein other tasks in the task set except the target task are executed after the global lock corresponding to the pending task is released.

6. The method according to claim 5, characterized in that The task information includes a task object and / or a task type, and storing each task in a task set corresponding to the to-be-processed task according to the task information includes: Classify each of the tasks according to the task object and / or task type and store them in a task set corresponding to the task to be processed; After storing each of the tasks according to the task information into a task set corresponding to the task to be processed, the method includes: Based on each of the tasks in the task set put into the to-be-processed tasks, a corresponding task execution instruction is generated, and the task execution instruction is put into a message queue.

7. A task processing method, characterized in that: Applied to a consumer end, the consumer end includes a task collection consumer end and a task execution consumer end, and the method includes: The task collection and consumption end is used to obtain task information corresponding to each task when receiving the task; and store each task in a task set corresponding to the task to be processed according to the task information; The task execution consumer end is used to obtain task execution instructions from a message queue; when a global lock is successfully added to a pending task corresponding to the task execution instruction, a target task in a task set corresponding to the pending task is executed according to the task execution instruction; when the target task is executed, the target task is deleted from the task set and the global lock corresponding to the pending task is released; wherein, other tasks in the task set except the target task are executed after the global lock corresponding to the pending task is released.

8. A task processing device, characterized in that: Applied to the task execution consumer end, the device comprises: A task execution instruction acquisition module is used to obtain task execution instructions from a message queue; A target task execution module, configured to execute a target task in a task set corresponding to the task to be processed according to the task execution instruction when a global lock is successfully added to the task to be processed corresponding to the task execution instruction; A global lock release module, used to delete the target task from the task set and release the global lock corresponding to the task to be processed when the target task is executed; Among them, other tasks in the task set except the target task are executed after the global lock corresponding to the task to be processed is released.

9. A task processing device, characterized in that: Applied to the task collection consumer end, the device includes: A task information acquisition module, used to acquire task information corresponding to each task when a task is received; A task information storage module is used to store each of the tasks in a task set corresponding to the pending task according to the task information, so that when the task execution consumer receives the task execution instruction from the message queue and successfully adds a global lock for the pending task corresponding to the task execution instruction, the target task determined from the task set corresponding to the pending task according to the task execution instruction is executed, wherein other tasks in the task set except the target task are executed after the global lock corresponding to the pending task is released.

10. A computer program product, comprising a computer program, 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 7 are implemented.