Task execution method and device, electronic equipment and storage medium
By generating the expected value and binary operation of the target task, determining the task execution status, and ensuring that asynchronous tasks are executed as expected in multiple nodes, the problem of multiple execution or missed execution is solved, and the task processing efficiency and resource utilization are improved.
Patent Information
- Application Number
- CN202510776533.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-06-11
- Publication Date
- 2025-09-16
AI Technical Summary
In the process of processing the target task, the existing technology has the problem of multiple execution or missed execution, resulting in poor processing effect, especially the lack of exception handling in asynchronous task processing.
By generating the expected value of the target task, determining the execution status of the task based on the attribute information of the event, and continuing to execute in multiple task nodes until the expected result is achieved, binary operations are used to optimize task execution.
Ensure that all events of the target task are completed as expected, reduce resource waste, improve task processing efficiency, and avoid over-execution or missed execution.
Smart Images

Figure CN120653396A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of data processing technology, and in particular to a task execution method, device, electronic device and storage medium. Background Art
[0002] Currently, when processing target tasks (e.g., asynchronous tasks), multiple executions or missed executions often occur, impacting the performance of the target task. For example, methods such as thread asynchrony, future asynchrony, and annotation asynchrony only allow asynchronous processing of asynchronous tasks, but lack the ability to address exceptions (e.g., missed executions) that arise during this asynchronous processing. Therefore, ensuring the proper processing of target tasks is a pressing issue. Summary of the Invention
[0003] The embodiments of the present application provide a task execution method, device, electronic device and storage medium to ensure the normal processing of the target task.
[0004] In a first aspect, an embodiment of the present application provides a task execution method, the method comprising:
[0005] In response to a release operation of the first task node for a target task to be executed, generating an expected value of the target task based on attribute information corresponding to each event included in the target task; the expected value is used to indicate an expected execution result of the target task;
[0006] Determining an execution state of the target task based on the expected value and the execution values when the target task is executed in the plurality of second task nodes; the execution state is used to indicate whether an actual execution result of the target task corresponding to the execution value is an expected execution result corresponding to the expected value;
[0007] If the execution status indicates that the actual execution result is not the expected execution result, the target task is continued to be executed in the plurality of second task nodes until the actual execution result is the expected execution result.
[0008] In an optional implementation, generating an expected value of the target task based on attribute information corresponding to each event included in the target task includes:
[0009] Obtaining first attribute values and second attribute values corresponding to each event from each attribute information; wherein each first attribute value uniquely identifies the corresponding event, and each second attribute value indicates whether the corresponding event is a to-be-executed event;
[0010] Based on the obtained second attribute values, select from each event a plurality of events corresponding to the events to be executed;
[0011] An expected value is generated based on first attribute values respectively corresponding to a plurality of events.
[0012] In an optional implementation, the first attribute value is binary data, and different first attribute values have different bits with values of 1;
[0013] Then, the expected value is generated based on the first attribute values corresponding to the multiple events, including:
[0014] Performing an OR operation or an XOR operation on the first attribute values corresponding to the multiple events to obtain an operation result;
[0015] The result of the operation is taken as the expected value.
[0016] In an optional implementation, determining the execution status of the target task based on the expected value and the execution values when the target task is executed in the plurality of second task nodes includes:
[0017] For multiple second task nodes, perform the following operations respectively:
[0018] Determining at least one first event corresponding to a second task node, and obtaining an initial execution value generated based on first attribute values corresponding to at least one executed second event in the plurality of events;
[0019] An initial execution value is updated based on first attribute values respectively corresponding to at least one first event to obtain a target execution value, and an execution state is determined based on the expected value and the target execution value.
[0020] In an optional implementation, the method further includes:
[0021] For multiple third events to be executed in the multiple events, perform the following operations respectively:
[0022] Determining first event execution information of a third event based on an AND operation result of a first attribute value and an expected value of a third event; the first event execution information is used to indicate whether a third event needs to be executed in a second task node;
[0023] And, based on the AND operation result of the first attribute value and the initial execution value of a third event, second event execution information of a third event is determined; the second event execution information is used to indicate whether a third event has been executed in a second task node.
[0024] In an optional implementation, determining the execution status based on the expected value and the target execution value includes:
[0025] If the expected value is greater than the target execution value, then the execution status is determined to indicate that the actual execution result is not the expected execution result;
[0026] If the expected value is equal to the target execution value, then the execution status is determined to represent that the actual execution result is the expected execution result.
[0027] In an optional implementation, after determining the execution status of the target task based on the expected value and the execution values when the target task is executed in the plurality of second task nodes, the method further includes:
[0028] If the execution status indicates that the actual execution result is the expected execution result, it is determined that the task execution operation for the target task has been completed.
[0029] In a second aspect, an embodiment of the present application further provides a task execution device, the device comprising:
[0030] an information processing module, configured to generate, in response to a release operation of a target task to be executed by the first task node, an expected value of the target task based on attribute information corresponding to each event included in the target task; the expected value is used to indicate an expected execution result of the target task;
[0031] a state determination module, configured to determine an execution state of a target task based on an expected value and an execution value when the target task is executed in a plurality of second task nodes; the execution state is configured to indicate whether an actual execution result of the target task corresponding to the execution value is an expected execution result corresponding to the expected value;
[0032] The task execution module is configured to continue executing the target task in a plurality of second task nodes until the actual execution result is the expected execution result if the execution status indicates that the actual execution result is not the expected execution result.
[0033] In an optional implementation, when generating the expected value of the target task based on the attribute information corresponding to each event included in the target task, the information processing module is specifically configured to:
[0034] Obtaining first attribute values and second attribute values corresponding to each event from each attribute information; wherein each first attribute value uniquely identifies the corresponding event, and each second attribute value indicates whether the corresponding event is a to-be-executed event;
[0035] Based on the obtained second attribute values, select from each event a plurality of events corresponding to the events to be executed;
[0036] An expected value is generated based on first attribute values respectively corresponding to a plurality of events.
[0037] In an optional implementation, the first attribute value is binary data, and different first attribute values have different bits with values of 1;
[0038] When generating expected values based on the first attribute values corresponding to the multiple events, the information processing module is specifically configured to:
[0039] Performing an OR operation or an XOR operation on the first attribute values corresponding to the multiple events to obtain an operation result;
[0040] The result of the operation is taken as the expected value.
[0041] In an optional implementation, when determining the execution status of the target task based on the expected value and the execution values when the target task is executed in the plurality of second task nodes, the status determination module is specifically configured to:
[0042] For multiple second task nodes, perform the following operations respectively:
[0043] Determining at least one first event corresponding to a second task node, and obtaining an initial execution value generated based on first attribute values corresponding to at least one executed second event in the plurality of events;
[0044] An initial execution value is updated based on first attribute values respectively corresponding to at least one first event to obtain a target execution value, and an execution state is determined based on the expected value and the target execution value.
[0045] In an optional implementation, the state determination module is further configured to:
[0046] For multiple third events to be executed in the multiple events, perform the following operations respectively:
[0047] Determining first event execution information of a third event based on an AND operation result of a first attribute value and an expected value of a third event; the first event execution information is used to indicate whether a third event needs to be executed in a second task node;
[0048] And, based on the AND operation result of the first attribute value and the initial execution value of a third event, second event execution information of a third event is determined; the second event execution information is used to indicate whether a third event has been executed in a second task node.
[0049] In an optional implementation, when determining the execution state based on the expected value and the target execution value, the state determination module is specifically configured to:
[0050] If the expected value is greater than the target execution value, then the execution status is determined to indicate that the actual execution result is not the expected execution result;
[0051] If the expected value is equal to the target execution value, then the execution status is determined to represent that the actual execution result is the expected execution result.
[0052] In an optional implementation, after determining the execution status of the target task based on the expected value and the execution values when the target task is executed in the plurality of second task nodes, the task execution module is further configured to:
[0053] If the execution status indicates that the actual execution result is the expected execution result, it is determined that the task execution operation for the target task has been completed.
[0054] In a third aspect, an embodiment of the present application further provides an electronic device, including:
[0055] processor; and
[0056] Memory for storing programs,
[0057] The program includes instructions, and when the instructions are executed by the processor, the processor executes the task execution method as described in the first aspect.
[0058] In a fourth aspect, an embodiment of the present application further provides a non-transitory computer-readable storage medium storing computer instructions, wherein the computer instructions are used to enable a computer to execute the task execution method as described in the first aspect.
[0059] In a fifth aspect, the present application provides a computer program product, which, when called by a computer, enables the computer to execute the steps of the task execution method as described in the first aspect.
[0060] The beneficial effects of this application are as follows:
[0061] In the task execution method provided in the embodiment of the present application, in response to the release operation of the first task node for the target task to be executed, the expected value of the target task is generated based on the attribute information corresponding to each event included in the target task; the expected value can be used to indicate the expected execution result of the target task; then, based on the expected value and the execution value when the target task is executed in multiple second task nodes, the execution status of the target task is determined; the execution status can be used to indicate whether the actual execution result of the target task corresponding to the execution value is the expected execution result corresponding to the expected value; finally, if the execution status characterizes that the actual execution result is not the expected execution result, the target task is continued to be executed in multiple second task nodes until the actual execution result is the expected execution result. It can be seen that by determining the execution status of the target task through the expected value that can characterize the expected execution result of the target task and the execution value that characterizes the actual execution result of the target task, it is possible to timely determine whether the various events included in the target task are executed as expected and completed, thereby ensuring the normal processing of the target task.
[0062] In addition, other features and advantages of the present application will be described in the following description, and in part will become apparent from the description, or may be understood by practicing the present application. The objectives and other advantages of the present application can be realized and obtained through the structures particularly pointed out in the written description, claims, and drawings. BRIEF DESCRIPTION OF THE DRAWINGS
[0063] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the following briefly introduces the drawings required for describing the embodiments. Obviously, the drawings described here are used to provide a further understanding of the present application, constitute a part of the present application, and do not constitute an improper limitation of the present application. In the drawings:
[0064] Figure 1 A schematic diagram of an optional system architecture applicable to the embodiments of the present application;
[0065] Figure 2 A schematic diagram of an implementation flow of a task execution method provided in an embodiment of the present application;
[0066] Figure 3 A schematic diagram of a specific application scenario of a target task provided in an embodiment of the present application;
[0067] Figure 4 A flowchart of a method for determining the execution status of a target task provided in an embodiment of the present application;
[0068] Figure 5 A schematic diagram of an application scenario for executing a target task provided by an embodiment of the present application;
[0069] Figure 6 A schematic diagram of the structure of a task execution device provided in an embodiment of the present application;
[0070] Figure 7 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0071] The following describes embodiments of the present application in more detail with reference to the accompanying drawings. Although certain embodiments of the present application are shown in the accompanying drawings, it should be understood that the present application can be implemented in various forms and should not be construed as limited to the embodiments described herein. Instead, these embodiments are provided to provide a more thorough and complete understanding of the present application. It should be understood that the drawings and embodiments of the present application are for illustrative purposes only and are not intended to limit the scope of protection of the present application.
[0072] It should be understood that the various steps described in the method embodiments of the present application can be performed in different orders and / or in parallel. In addition, the method embodiments may include additional steps and / or omit the steps shown. The scope of the present application is not limited in this respect.
[0073] The term "including" and its variations used in this document are open inclusions, that is, "including but not limited to". The term "based on" means "based at least in part on". The term "one embodiment" means "at least one embodiment"; the term "another embodiment" means "at least one other embodiment"; the term "some embodiments" means "at least some embodiments". The relevant definitions of other terms will be given in the description below. It should be noted that the concepts of "first", "second", etc. mentioned in this application are only used to distinguish different devices, modules or units, and are not used to limit the order or interdependence of the functions performed by these devices, modules or units.
[0074] It should be noted that the modifications of "one" and "multiple" mentioned in this application are illustrative rather than restrictive. Those skilled in the art should understand that unless otherwise clearly indicated in the context, they should be understood as "one or more".
[0075] The names of the messages or information exchanged between multiple devices in the embodiments of the present application are only used for illustrative purposes and are not used to limit the scope of these messages or information.
[0076] The following is a brief introduction to the design concept of the embodiment of this application:
[0077] In distributed services, the processing of target tasks (e.g., asynchronous tasks) often results in multiple executions or missed executions, impacting the performance of the target tasks. For example, thread asynchrony, future asynchrony, and annotation asynchrony (e.g., the @Async annotation) only allow asynchronous processing of asynchronous tasks, but lacks the ability to address exceptions (e.g., missed executions) that arise during this asynchronous processing. Thread asynchrony involves frequent creation and destruction, wasting system resources. Future asynchrony is primarily used in result-focused scenarios. Asynchronous annotations primarily represent asynchronous loading methods. By default, a thread is created each time, potentially leading to out-of-memory (OOM) issues.
[0078] It should be noted that asynchronous tasks usually refer to tasks that do not enter the main thread, but enter the task queue. Only when the task queue notifies the main thread that an asynchronous task can be executed can it enter the main thread process for execution.
[0079] In view of this, in order to solve or improve the above-mentioned problems and to ensure that all events of a task are executed and completed as expected under distributed services, an embodiment of the present application proposes a task execution method, which may specifically include: in response to the release operation of the first task node for the target task to be executed, generating an expected value of the target task based on the attribute information corresponding to each event included in the target task; the expected value can be used to indicate the expected execution result of the target task; then, based on the expected value and the execution value when the target task is executed in multiple second task nodes, the execution status of the target task is determined; the execution status can be used to indicate whether the actual execution result of the target task corresponding to the execution value is the expected execution result corresponding to the expected value; finally, if the execution status indicates that the actual execution result is not the expected execution result, the target task continues to be executed in multiple second task nodes until the actual execution result is the expected execution result.
[0080] In particular, the preferred embodiments of the present application are described below in conjunction with the drawings in the specification. It should be understood that the preferred embodiments described herein are only used to illustrate and explain the present application and are not used to limit the present application. In addition, the embodiments of the present application and the features in the embodiments may be combined with each other if there is no conflict.
[0081] See Figure 1 As shown, it is a schematic diagram of an optional system architecture applicable to an embodiment of the present application. The system architecture may include: a first task node 101, a second task node (102a, 102b) and a server 103. The first task node 101, the second task node (102a, 102b) and the server 103 can exchange information with each other through a communication network, wherein the communication mode adopted by the aforementioned communication network may include: wireless communication mode and wired communication mode.
[0082] Exemplarily, the first task node 101 can access the network through cellular mobile communication technology to communicate with the second task node (102a, 102b) and the server 103. The cellular mobile communication technology, for example, includes fifth generation mobile networks (5G) technology or next generation mobile communication technology.
[0083] Optionally, the first task node 101 can access the network through short-range wireless communication to communicate with the second task node (102a, 102b) and the server 103. The short-range wireless communication method includes, for example, wireless fidelity (Wi-Fi) technology.
[0084] The embodiment of the present application does not impose any restrictions on the number of communication devices involved in the above system architecture. For example, the above system architecture may include more second task nodes, or may include fewer second task nodes, or may also include other network devices. Figure 1 As shown, only the first task node 101, the second task node (102a, 102b) and the server 103 are described as examples, and the above-mentioned communication devices and their respective functions are briefly introduced below.
[0085] The first task node 101 is used to publish a target task to be executed, that is, to perform a publishing operation for the target task. The second task nodes (102a, 102b) can be used to execute one or more events to be executed included in the target task. It should be understood that the target task can include events that do not require the second task processing nodes (102a, 102b) to execute.
[0086] It should be noted that, in the embodiment of the present application, the working mode of the first task node 101 and the second task node (102a, 102b) can be a Publisher-Listener mode. When the task node acts as a Publisher, the node is responsible for publishing events, and when the task node acts as a Listener, it is responsible for listening to these events and responding.
[0087] Server 102 can be an independent physical server, or a server cluster or distributed system composed of multiple physical servers. It can also be a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, content delivery networks (CDNs), and big data and artificial intelligence platforms.
[0088] For example, in a distributed service scenario, the server 102 in the embodiment of the present application can be a (cloud) database. The database can be used to generate an expected value of the target task based on the attribute information corresponding to each event included in the target task in response to the release operation of the first task node for the target task to be executed; then, based on the expected value and the execution value when the target task is executed in multiple second task nodes, the execution status of the target task is determined; finally, if the execution status indicates that the actual execution result is not the expected execution result, the target task is continued to be executed in multiple second task nodes until the actual execution result is the expected execution result, so as to ensure the normal processing of the target task.
[0089] The following describes the task execution method provided by the exemplary embodiment of the present application in combination with the above-mentioned system architecture and with reference to the accompanying drawings. It should be noted that the above-mentioned system architecture is only shown to facilitate understanding of the spirit and principles of the present application, and the implementation of the present application is not limited in this respect.
[0090] See Figure 2 As shown, it is a schematic diagram of an implementation process of a task execution method provided in an embodiment of the present application. The execution subject is a server as an example. The specific implementation process of the method is as follows:
[0091] S201: In response to a publishing operation of a first task node for a target task to be executed, generating an expected value of the target task based on attribute information corresponding to each event included in the target task.
[0092] The above-mentioned expected value can be used to indicate the expected execution result of the target task, that is, the expected value can be used to measure whether the target task is executed and completed according to the processing expectation for the target task. As can be seen, the expected value of the target task can be determined based on one or more events that need to be executed included in the target task.
[0093] In an optional implementation, when executing step S201, the server responds to the first task node's publishing operation for the target task to be executed, and can obtain the first attribute value and the second attribute value corresponding to each event included in the target task from each attribute information; then, based on the obtained second attribute values, filter out multiple events whose corresponding events are to-be-executed events from each event; finally, generate expected values based on the first attribute values corresponding to the multiple events. Each first attribute value uniquely identifies the corresponding event, that is, the first attribute value can be a unique identifier of the event, and each second attribute value can indicate whether the corresponding event is an event to be executed, that is, the corresponding event needs to be published for execution.
[0094] For example, see Figure 3 As shown, taking the target task of successful loan disbursement as an example, successful loan disbursement can include 4 events, namely: notification core, credit limit confirmation, text message sending and notification scenario. Among them, the first attribute values corresponding to the notification core, credit limit confirmation, text message sending and notification scenario respectively can be: 1, 4, 8 and 16, and the second attribute values corresponding to the notification core, credit limit confirmation, text message sending and notification scenario respectively can be: need to be published, need to be published, need to be published and no need to be published. Therefore, based on the second attribute values corresponding to the notification core, credit limit confirmation, text message sending and notification scenario respectively, the server can determine that the notification core, credit limit confirmation and text message sending are events to be executed, and thus can determine the expected value of the target task based on the first attribute values corresponding to the notification core, credit limit confirmation and text message sending respectively, for example, the expected value is 13.
[0095] It should be noted that the attribute information of each event may also include information such as the event name, which is not limited in this application.
[0096] Based on the above approach, the first attribute value included in the event's attribute information can be used to determine the multiple pending events in the target task that require the task processing node to execute. Furthermore, the second attribute value included in the event's attribute information can be used to determine the expected value that indicates whether the aforementioned multiple pending events have been completed as expected. Thus, based on the obtained expected value and the actual execution result of the target task, it can be determined whether the target task has been executed and completed as expected.
[0097] In order to save the overhead required by the first task node to publish the various events included in the target task, the first task node can only publish events that require multiple second task nodes to execute. Still taking the target task of successful loan as an example, among the four events included in the successful loan, the notification core, credit limit confirmation, and SMS sending require processing by the second task node, while the notification scenario does not require processing by the second task node. Therefore, in the publishing operation for successful loan, the first task node can only publish the notification core, credit limit confirmation, and SMS sending, and not publish the notification scenario. In this way, the first task node does not publish all the events included in the target task, but only publishes the pending events that need to be processed by the second task node, thereby reducing the event publishing overhead of the first task node and reducing the consumption of system resources.
[0098] In an optional implementation, the first attribute value may be binary data, and the bits that have a value of 1 in different first attribute values are different. For example, the target task includes two pending events that need to be published (i.e., event 1 and event 2), wherein the first attribute value of event 1 may be 010, and the first attribute value of event 2 may be 101, i.e., the bits that have a value of 1 in the first attribute value of event 1 are different from the bits that have a value of 1 in the first attribute value of event 2. For another example, the target task includes three pending events that need to be published (i.e., event a, event b, and event c), wherein the first attribute value of event a may be 001, the first attribute value of event b may be 010, and the first attribute value of event c may be 100.
[0099] Furthermore, when the server generates the expected value of the target task based on the first attribute values corresponding to the above-mentioned multiple events, it can obtain the operation result by performing an OR operation or an XOR operation on the first attribute values corresponding to the multiple events, and then use the operation result as the expected value of the target task. Taking the above-mentioned events 1 and 2 as an example, the server can obtain the operation result of 111 by performing an OR operation or an XOR operation on the first attribute value of event 1 (i.e., 010) and the first attribute value of event 2 (i.e., 101), that is, the expected value of the target task is 111 (i.e., 7).
[0100] Taking the above-mentioned events a, b, and c as an example, the server can obtain the result of 111 by performing an OR operation or an XOR operation on the first attribute value of event a (i.e., 001), the first attribute value of event c (i.e., 010), and the first attribute value of event c (i.e., 100), that is, the expected value of the target task is 111 (i.e., 7).
[0101] Based on the above method, binary data is used as the first attribute value of the event, and through the special design of the bits, after obtaining the first attribute value of the event, the obtained multiple first attribute values can be subjected to XOR operation or OR operation to quickly determine the expected value of the target task, thereby improving the efficiency of task execution for the target task.
[0102] S202: Determine an execution state of the target task based on the expected value and the execution values when the target task is executed in the plurality of second task nodes.
[0103] The above-mentioned execution status can be used to indicate whether the actual execution result of the target task corresponding to the execution value is the expected execution result corresponding to the expected value. That is, according to the execution status, it can be used to determine whether the target task is executed and completed as expected. When the execution value when executing the target task in multiple second task nodes is less than the expected value, it can be determined that the target task has not been completed as expected. When the execution value when executing the target task in multiple second task nodes is equal to the above-mentioned expected value, it can be determined that the target task is about to be completed as expected or has been completed as expected. Therefore, the above-mentioned execution status can specifically be: the target task has been completed or the target task has not been completed.
[0104] In an optional implementation, when executing step S202, the server executes the reference Figure 4 The specific steps of the method shown are as follows:
[0105] S401: Determine at least one first event corresponding to a second task node, and obtain an initial execution value generated based on first attribute values corresponding to at least one executed second event in a plurality of events.
[0106] The at least one first event mentioned above is also at least one event that needs to be executed by the above-mentioned second task node but has not been executed. The at least one second event mentioned above is also at least one event that the target task needs to be executed and has been completed before the execution flow of the target task is transferred to the above-mentioned second task node.
[0107] S402: Update the initial execution value based on the first attribute value corresponding to the at least one first event, obtain the target execution value, and determine the execution state based on the expected value and the target execution value.
[0108] It can be understood that the above-mentioned updating of the initial execution value based on the first attribute value corresponding to at least one first event to obtain the target execution value is to perform an XOR operation or an OR operation on the first attribute value corresponding to the above-mentioned at least one first event and the initial execution value, so as to use the operation result as the new execution value, that is, the target execution value.
[0109] Furthermore, if the target execution value is less than the expected value (that is, the expected value is greater than the target execution value), it can be determined that the execution status of the target task represents that the actual execution result of the target task is not the expected execution result of the target task, that is, the target task has not been completed as expected; if the expected value is equal to the target execution value, it is determined that the execution status of the target task represents that the actual execution result of the target task is the expected execution result of the target task, that is, the target task has been completed as expected.
[0110] Optionally, for any one of the multiple third events to be executed in the multiple events mentioned above, the server can determine the first event execution information of the aforementioned third event based on the result of the AND operation of the first attribute value and the expected value of the third event. The aforementioned first event execution information can be used to indicate whether it is necessary to execute the aforementioned third event in the aforementioned second task node. It should be understood that the aforementioned at least one first event is also an unexecuted event, so the aforementioned multiple third events include the aforementioned at least one first event.
[0111] Assuming the first attribute value of the third event is 0001 and the expected value is 0011, the corresponding AND operation result is 0001 & 0011 = 0001. If the condition for event execution is that the first attribute value of the event & the expected value ! = 0, then the AND operation result determines that the third event needs to be executed in the second task node.
[0112] In addition, the server may also determine second event execution information of the third event based on the result of an AND operation between the first attribute value of the third event and the initial execution value. The second event execution information may be used to indicate whether the third event has been executed in the second task node.
[0113] Assuming again that the first attribute value of the aforementioned third event is 0001 and the initial execution value is 0010, the corresponding AND operation result is 0001 & 0010 = 0000. If the condition for event non-execution is the event's first attribute value & expected value == 0, then combined with the AND operation result, it can be determined that the aforementioned third event has not yet been executed in the aforementioned second task node.
[0114] It can be seen from this that when each second task node executes the target task, it only needs to execute the events that it can execute according to the expected value corresponding to the target task. The events that cannot be executed can be handed over to other second task nodes, thereby ensuring that all events of the target task can be executed correctly, so that there will be no multiple executions or missed executions.
[0115] Based on the execution status confirmation method described in steps S401 to S402, refer to Figure 5 As shown in Figure 1, it is a schematic diagram of an application scenario for executing a target task provided by an embodiment of the present application. In this application scenario, the target task is still to successfully disburse a loan. The first task node is Server1-Pulisher, and the second task nodes include Server1-Listener and Server2-Listener. This shows that Server1 can serve as both the first task node and the second task node.
[0116] When Server1 acts as a Pulisher, it publishes a task for a successful loan disbursement. This task includes four events: notifying the core, confirming the credit limit, sending a text message, and notifying the scenario. Of these, the three events, notifying the core, confirming the credit limit, and sending the text message, must be published for execution. Although the notification scenario event is included in the successful loan disbursement task, it is not executed again. At this point, the server records an expected value of 13, an execution value of 0, and an execution status of incomplete (i.e., is completed = false).
[0117] When Server1 acts as a Listener, after successfully publishing the loan disbursement task, it can start two threads (thread 1 and thread 2) to execute the core notification and credit limit confirmation events respectively. At this time, the server records the expected value as 13, the executed value as 5, and the execution status as incomplete (i.e., is completed = false).
[0118] Since Server1 cannot execute the SMS event, it can use a timer compensation mechanism to execute the unexecuted event (i.e., sending the SMS message) through Server2, which acts as a Listener, after a period of time (e.g., 5 minutes). At this time, the server records the expected value as 13, the executed value as 13, and the execution status as completed (i.e., is completed = true).
[0119] Optionally, before executing SMS sending, Server2 can use a binary operation (such as an AND operation) to determine whether the SMS sending event is required and has not yet been executed. Furthermore, Server2 can also use a binary operation (such as an AND operation) to determine whether the notification scenario event is not required. Specifically, Server2 can determine that the notification scenario event does not need to be executed based on the AND result (i.e., 00000) of the first attribute value corresponding to the notification scenario (i.e., 10000) and the expected value (i.e., 01101).
[0120] S203: If the execution status indicates that the actual execution result is not the expected execution result, the target task continues to be executed in the plurality of second task nodes until the actual execution result is the expected execution result. At this point, it can be determined that the target task has not been completed as expected. In other words, if the execution status indicates that the actual execution result is not the expected execution result, the target task continues to be executed based on the expected value and the current execution value until the execution value equals the expected value.
[0121] Optionally, if the execution status indicates that the actual execution result is the expected execution result, it is determined that the task execution operation for the target task has been completed. In this case, it can be determined that the target task has been completed as expected.
[0122] Based on the task execution method described in the above steps S201 to S203, since the target task usually includes multiple events, the use of storage resources is reduced to a certain extent; and by adding the attributes of the event, the flexible decision-making of whether the target task is completed as expected can be improved. In addition, when a second task node is unable to execute a certain event (or the event fails to execute), the event can be executed by a new second task node through a timing compensation mechanism, that is, it can be guaranteed that after a certain event fails to execute on a second task node, the event can be accurately retried, thereby ensuring that under distributed services, all events of the target task are executed and completed as expected.
[0123] To sum up, in the task execution method provided in the embodiment of the present application, in response to the publishing operation of the first task node for the target task to be executed, the expected value of the target task is generated based on the attribute information corresponding to each event included in the target task; the expected value can be used to indicate the expected execution result of the target task; then, based on the expected value and the execution value when the target task is executed in multiple second task nodes, the execution status of the target task is determined; the execution status can be used to indicate whether the actual execution result of the target task corresponding to the execution value is the expected execution result corresponding to the expected value; finally, if the execution status indicates that the actual execution result is not the expected execution result, the target task continues to be executed in multiple second task nodes until the actual execution result is the expected execution result.
[0124] It can be seen from this that by determining the execution status of the target task through the expected value that can characterize the expected execution result of the target task and the execution value that characterizes the actual execution result of the target task, it is possible to timely determine whether the various events included in the target task are executed and completed as expected, thereby ensuring the normal processing of the target task.
[0125] Furthermore, based on the same technical concept, the embodiment of the present application provides a task execution device, which is used to implement the above method flow of the embodiment of the present application. Figure 6 As shown, the task execution device 600 may include: an information processing module 601, a state determination module 602 and a task execution module 603, wherein:
[0126] The information processing module 601 is configured to generate an expected value of the target task based on the attribute information corresponding to each event included in the target task in response to the publishing operation of the first task node for the target task to be executed; the expected value is used to indicate the expected execution result of the target task;
[0127] A state determination module 602 is configured to determine an execution state of a target task based on an expected value and an execution value when the target task is executed in a plurality of second task nodes; the execution state is configured to indicate whether an actual execution result of the target task corresponding to the execution value is an expected execution result corresponding to the expected value;
[0128] The task execution module 603 is configured to continue executing the target task in a plurality of second task nodes until the actual execution result is the expected execution result if the execution status indicates that the actual execution result is not the expected execution result.
[0129] In an optional implementation, when generating the expected value of the target task based on the attribute information corresponding to each event included in the target task, the information processing module 601 is specifically configured to:
[0130] Obtaining first attribute values and second attribute values corresponding to each event from each attribute information; wherein each first attribute value uniquely identifies the corresponding event, and each second attribute value indicates whether the corresponding event is a to-be-executed event;
[0131] Based on the obtained second attribute values, select from each event a plurality of events corresponding to the events to be executed;
[0132] An expected value is generated based on first attribute values respectively corresponding to a plurality of events.
[0133] In an optional implementation, the first attribute value is binary data, and different first attribute values have different bits with values of 1;
[0134] When generating expected values based on the first attribute values corresponding to the multiple events, the information processing module 601 is specifically configured to:
[0135] Performing an OR operation or an XOR operation on the first attribute values corresponding to the multiple events to obtain an operation result;
[0136] The result of the operation is taken as the expected value.
[0137] In an optional implementation, when determining the execution status of the target task based on the expected value and the execution values when the target task is executed in the plurality of second task nodes, the status determination module 602 is specifically configured to:
[0138] For multiple second task nodes, perform the following operations respectively:
[0139] Determining at least one first event corresponding to a second task node, and obtaining an initial execution value generated based on first attribute values corresponding to at least one executed second event in the plurality of events;
[0140] An initial execution value is updated based on first attribute values respectively corresponding to at least one first event to obtain a target execution value, and an execution state is determined based on the expected value and the target execution value.
[0141] In an optional implementation, the state determination module 602 is further configured to:
[0142] For multiple third events to be executed in the multiple events, perform the following operations respectively:
[0143] Determining first event execution information of a third event based on an AND operation result of a first attribute value and an expected value of a third event; the first event execution information is used to indicate whether a third event needs to be executed in a second task node;
[0144] And, based on the AND operation result of the first attribute value and the initial execution value of a third event, second event execution information of a third event is determined; the second event execution information is used to indicate whether a third event has been executed in a second task node.
[0145] In an optional implementation, when determining the execution state based on the expected value and the target execution value, the state determination module 602 is specifically configured to:
[0146] If the expected value is greater than the target execution value, then the execution status is determined to indicate that the actual execution result is not the expected execution result;
[0147] If the expected value is equal to the target execution value, then the execution status is determined to represent that the actual execution result is the expected execution result.
[0148] In an optional implementation, after determining the execution status of the target task based on the expected value and the execution values when the target task is executed in the plurality of second task nodes, the task execution module 603 is further configured to:
[0149] If the execution status indicates that the actual execution result is the expected execution result, it is determined that the task execution operation for the target task has been completed.
[0150] Based on the description of the above method embodiment and apparatus embodiment, the exemplary embodiments of the present invention further provide an electronic device, comprising: at least one processor; and a memory communicatively connected to the at least one processor. The memory stores a computer program executable by the at least one processor, and when executed by the at least one processor, the computer program causes the electronic device to perform a method according to an embodiment of the present invention.
[0151] An embodiment of the present application further provides a non-transitory computer-readable storage medium storing a computer program, wherein the computer program, when executed by a processor of a computer, is used to cause the computer to execute a method according to an embodiment of the present application.
[0152] An embodiment of the present application further provides a computer program product, including a computer program, wherein the computer program, when executed by a processor of a computer, is used to cause the computer to perform a method according to an embodiment of the present application.
[0153] See Figure 7As shown, the structural block diagram of the electronic device 700 that can be used as the server or client of the present application will now be described, which is an example of the hardware device that can be applied to various aspects of the present application. The electronic device is intended to represent various forms of digital electronic computer equipment, such as laptop computers, desktop computers, workbenches, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device can also represent various forms of mobile devices, such as personal digital processing, cellular phones, smart phones, wearable devices and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely examples and are not intended to limit the implementation of the present application described and / or required herein.
[0154] like Figure 7 As shown, the electronic device 700 includes a computing unit 701, which can perform various appropriate actions and processes according to a computer program stored in a read-only memory (ROM) 702 or a computer program loaded from a storage unit 708 into a random access memory (RAM) 703. Various programs and data required for the operation of the device 700 can also be stored in the RAM 703. The computing unit 701, the ROM 702, and the RAM 703 are connected to each other via a bus 704. An input / output (I / O) interface 705 is also connected to the bus 704.
[0155] Multiple components within electronic device 700 are connected to I / O interface 705, including an input unit 706, an output unit 707, a storage unit 708, and a communication unit 709. Input unit 706 can be any type of device capable of inputting information into electronic device 700. Input unit 706 can receive input numeric or character information and generate key input signals related to user settings and / or function control of the electronic device. Output unit 707 can be any type of device capable of presenting information and may include, but is not limited to, a display, a speaker, a video / audio output terminal, a vibrator, and / or a printer. Storage unit 708 may include, but is not limited to, a magnetic disk or an optical disk. Communication unit 709 allows electronic device 700 to exchange information / data with other devices via computer networks such as the Internet and / or various telecommunication networks and may include, but is not limited to, a modem, a network card, an infrared communication device, a wireless communication transceiver, and / or a chipset, such as a Bluetooth device, a WiFi device, a Worldwide Interoperability for Microwave Access (WiMax) device, a cellular communication device, and / or the like.
[0156] The computing unit 701 can be a variety of general and / or special processing components with processing and computing capabilities. Some examples of the computing unit 701 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various artificial intelligence (AI) computing chips, various computing units that run machine learning model algorithms, a digital signal processor (DSP), and any appropriate processor, controller, microcontroller, etc. The computing unit 701 performs the various methods and processes described above. For example, in some embodiments, the above-mentioned task execution method can be implemented as a computer software program, which is tangibly contained in a machine-readable medium, such as the storage unit 708. In some embodiments, part or all of the computer program can be loaded and / or installed on the electronic device 700 via the ROM 702 and / or the communication unit 709. In some embodiments, the computing unit 701 can be configured to perform the above-mentioned task execution method by any other appropriate means (e.g., by means of firmware).
[0157] The program code for implementing the methods of the present application can be written in any combination of one or more programming languages. Such program code can be provided to a processor or controller of a general-purpose computer, a special-purpose computer, or other programmable data processing device, so that when the program code is executed by the processor or controller, the functions / operations specified in the flow charts and / or block diagrams are implemented. The program code can be executed entirely on the machine, partially on the machine, as a stand-alone software package, partially on the machine and partially on a remote machine, or entirely on a remote machine or server.
[0158] In the context of the present application, a machine-readable medium can be a tangible medium that can contain or store a program for use by an instruction execution system, device or equipment or used in combination with an instruction execution system, device or equipment. A machine-readable medium can be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium can include, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared or semiconductor system, device or equipment, or any suitable combination of the foregoing. A more specific example of a machine-readable storage medium can include an electrical connection based on one or more lines, a portable computer disk, a hard disk, a RAM, a ROM, an erasable programmable read-only memory (EPROM) or a flash memory, an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
[0159] As used herein, the terms "machine-readable medium" and "computer-readable medium" refer to any computer program product, apparatus, and / or device (e.g., a magnetic disk, an optical disk, a memory, a programmable logic device (PLD)) for providing machine instructions and / or data to a programmable processor, including machine-readable media that receives machine instructions as a machine-readable signal. The term "machine-readable signal" refers to any signal for providing machine instructions and / or data to a programmable processor.
[0160] To provide interaction with a user, the systems and techniques described herein can be implemented on a computer having: a display device (e.g., a cathode ray tube (CRT) or a liquid crystal display (LCD) monitor) for displaying information to the user; and a keyboard and pointing device (e.g., a mouse or trackball) through which the user can provide input to the computer. Other types of devices can also be used to provide interaction with the user; for example, the feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form (including acoustic input, voice input, or tactile input).
[0161] The systems and techniques described herein can be implemented in a computing system that includes back-end components (e.g., as a data server), or a computing system that includes middleware components (e.g., an application server), or a computing system that includes front-end components (e.g., a user computer having a graphical user interface or a web browser through which a user can interact with implementations of the systems and techniques described herein), or a computing system that includes any combination of such back-end components, middleware components, or front-end components. The components of the system can be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include a local area network (LAN), a wide area network (WAN), and the Internet.
[0162] Computer systems may include clients and servers. A client and server are generally remote from each other and typically interact through a communication network. The client and server relationship arises through computer programs running on the respective computers and having a client-server relationship to each other.
[0163] Furthermore, it should be understood that what is disclosed above is merely a preferred embodiment of the present application and certainly cannot be used to limit the scope of rights of the present invention. Therefore, equivalent changes made according to the claims of the present invention are still within the scope covered by the present application.
Claims
1. A task execution method, characterized in that: include: In response to a publishing operation of the first task node for a target task to be executed, generating an expected value of the target task based on attribute information corresponding to each event included in the target task; The expected value is used to indicate the expected execution result of the target task; determining an execution state of the target task based on the expected value and execution values when the target task is executed in a plurality of second task nodes; The execution status is used to indicate whether the actual execution result of the target task corresponding to the execution value is the expected execution result corresponding to the expected value; If the execution status indicates that the actual execution result is not the expected execution result, the target task continues to be executed in the plurality of second task nodes until the actual execution result is the expected execution result.
2. The method according to claim 1, wherein Generating the expected value of the target task based on the attribute information corresponding to each event included in the target task includes: Obtaining first attribute values and second attribute values corresponding to each event from each attribute information; wherein each first attribute value uniquely identifies a corresponding event, and each second attribute value indicates whether the corresponding event is a to-be-executed event; Based on the obtained second attribute values, filter out a plurality of events corresponding to events to be executed from the events; The expected value is generated based on the first attribute values respectively corresponding to the multiple events.
3. The method according to claim 2, wherein The first attribute value is binary data, and different first attribute values have different bits with a value of 1; Then, generating the expected value based on the first attribute values corresponding to the multiple events includes: Performing an OR operation or an XOR operation on the first attribute values corresponding to the multiple events to obtain an operation result; The operation result is used as the expected value.
4. The method according to claim 2 or 3, wherein: The determining the execution status of the target task based on the expected value and the execution values when the target task is executed in the plurality of second task nodes includes: For the multiple second task nodes, perform the following operations respectively: Determining at least one first event corresponding to a second task node, and obtaining an initial execution value generated based on first attribute values corresponding to at least one executed second event among the multiple events; The initial execution value is updated based on the first attribute value corresponding to the at least one first event to obtain a target execution value, and the execution state is determined based on the expected value and the target execution value.
5. The method according to claim 4, wherein The method further comprises: For the multiple third events to be executed among the multiple events, perform the following operations respectively: Determining first event execution information of the third event based on a result of an AND operation between a first attribute value of the third event and the expected value; the first event execution information is used to indicate whether the third event needs to be executed in the second task node; And, based on the first attribute value of the third event and the result of the AND operation of the initial execution value, the second event execution information of the third event is determined; the second event execution information is used to indicate whether the third event has been executed in the second task node.
6. The method according to claim 4, wherein The determining the execution state based on the expected value and the target execution value includes: If the expected value is greater than the target execution value, determining that the execution status indicates that the actual execution result is not the expected execution result; If the expected value is equal to the target execution value, determining that the execution status represents that the actual execution result is the expected execution result.
7. The method according to claim 1, 2 or 3, wherein: After determining the execution status of the target task based on the expected value and the execution values when the target task is executed in the plurality of second task nodes, the method further includes: If the execution status indicates that the actual execution result is the expected execution result, it is determined that the task execution operation for the target task has been completed.
8. A task execution device, characterized in that: include: an information processing module, configured to generate an expected value of a target task based on attribute information corresponding to each event included in the target task in response to a publishing operation of the first task node for the target task to be executed; The expected value is used to indicate the expected execution result of the target task; a state determination module, configured to determine an execution state of the target task based on the expected value and execution values when the target task is executed in a plurality of second task nodes; The execution status is used to indicate whether the actual execution result of the target task corresponding to the execution value is the expected execution result corresponding to the expected value; The task execution module is configured to continue executing the target task in the plurality of second task nodes until the actual execution result is the expected execution result if the execution status indicates that the actual execution result is not the expected execution result.
9. An electronic device comprising: processor; as well as Memory for storing programs, The program includes instructions, which, when executed by the processor, cause the processor to perform the method according to any one of claims 1 to 7.
10. A non-transitory computer-readable storage medium storing computer instructions, wherein: The computer instructions are used to cause the computer to execute the method according to any one of claims 1 to 7.