Disclosure of Invention
Based on the technical problems, the application provides a block chain BAAS system task scheduling framework based on a directed acyclic graph, so as to solve the problem that the scheduling requirements for complex and unreliable tasks cannot be met in a BAAS system.
A block chain BAAS system task scheduling framework based on a directed acyclic graph comprises a task creating module, a task triggering module, a task executing module and an alarming module, wherein:
the task creating module is configured to create a task based on a block chain BASS system and place the task into a task pool;
the task triggering module is configured to check the task pool, find a task to be executed in the tasks, which meets a triggering strategy, and send the task to be executed to an execution queue of the task executing module;
the task execution module is configured to execute the task to be executed according to the execution queue, generate a task execution result, and check the task execution result;
if the task execution result is that the task is successfully executed, the task execution module is further configured to evaluate task arrangement of the task to be executed, and if the task arrangement needs to be executed, the task execution module updates information of the task arrangement based on a directed acyclic graph; if the task arrangement does not need to be executed, the task execution module removes the task pool from the task to be executed;
the alarm module is configured to check whether an alarm strategy is met or not if the task execution result is that the task execution fails, and trigger an alarm if the alarm strategy is met;
the task execution module is further configured to evaluate a failure processing strategy if the alarm strategy is not met or the alarm is triggered to end; if the evaluation result is the end, the task execution module removes the task pool of the task to be executed; and if the evaluation result is the task retry, the task execution module updates the task execution information.
Further, the task creation module is further configured to specify parameters of task execution when creating a task, the parameters including: triggering strategy, executing strategy, alarming strategy, failure processing strategy and task arrangement.
Furthermore, the task pool can be plugged and disconnected, and the task pool is stored by adopting a MySQL database.
Furthermore, the task trigger module can be plugged and disconnected, and the task trigger module realizes distributed scheduling by adopting a mode based on Redis lock and local scheduling.
Furthermore, the task execution module can be plugged and disconnected, and the task execution module adopts a built-in thread tool execution module in Java to realize a local queue.
Furthermore, the alarm module can be plugged and pulled, and the alarm module is connected to the nailing robot to give an alarm.
Further, if the task arrangement needs to be executed, the step of updating the task arrangement information by the task execution module based on the directed acyclic graph includes:
if the task to be executed has the task arrangement and the task arrangement is not finished, continuing to execute according to the execution relation in the task arrangement configuration;
a plurality of execution relations are established in the task arrangement configuration, and the execution relations form a directed acyclic graph;
and executing the task arrangement according to the task arrangement sequence of the execution relation in the directed acyclic graph, and updating the information of the task arrangement.
Further, the execution relationship is pre-configured when the task is created.
Further, the task arrangement corresponds to a plurality of task units, the task units are program codes for realizing the task arrangement, and the task units can be reused.
Further, the task execution module contains an execution policy configuration item, the execution policy configuration item includes parallel execution and distributed serial execution, and the execution policy configuration item is extensible.
According to the technical scheme, the block chain BAAS system task scheduling framework based on the directed acyclic graph comprises a task creating module, a task triggering module, a task executing module and an alarm module, wherein the task creating module creates tasks and puts the tasks into a task pool; the task triggering module checks the task pool, searches for a task to be executed which meets a triggering strategy, and sends the task to be executed to an execution queue of the task executing module; the task execution module executes the task to be executed according to the execution queue, generates a task execution result and checks the task execution result; if the task is successfully executed, the task execution module evaluates the task arrangement of the task to be executed, and if the task arrangement needs to be executed, the task execution module updates the information of the task arrangement based on the directed acyclic graph; if the task arrangement does not need to be executed, the task execution module removes the task pool from the task to be executed; if the task execution fails, the alarm module checks whether an alarm strategy is met, and if the alarm strategy is met, the alarm module triggers an alarm; if the alarm strategy is not satisfied or the alarm is triggered to be finished, the task execution module evaluates a failure processing strategy; if the evaluation result is end, the task execution module removes the task pool of the task to be executed; and if the evaluation result is that the task retries, the task execution module updates the task execution information. The application can realize high concurrency, high availability and high performance capability of the frame by matching different pluggable components, and solves the problem that the dispatching requirement on complex and unreliable tasks cannot be met in a BAAS system by applying high availability, distributed, pluggable and directed acyclic graph technologies.
Detailed Description
To make the objects, technical solutions and advantages of the present application more clear, the technical solutions of the present application will be clearly and completely described below with reference to specific embodiments of the present application and the accompanying drawings. It should be apparent that the described embodiments are only a few embodiments of the present application, and not all embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present application. The technical solutions provided by the embodiments of the present application are described in detail below with reference to the accompanying drawings.
The task scheduling framework is a software framework for task scheduling and management, and is used for being integrated with other software systems to manage the execution of tasks in the systems. At present, in an open source task scheduling framework of an open source code, a distributed timing execution and failure processing mechanism of a task can be achieved, but a timing mechanism, a failure processing mechanism, an alarm mechanism and an arrangement reuse mechanism of a fine-grained management task cannot be achieved. In addition, the purpose of the open source task scheduling framework is to solve the general problem, and on the special problem of the BAAS system, a large amount of customized development is required, the development amount is large, and the large development amount brings the risk of system robustness. The invention aims to solve the problems and meets the scheduling requirements of the BAAS system on complex and unreliable tasks by the application of high availability, distributed, pluggable and directed acyclic graph technologies.
In the application, the task scheduling framework cannot operate independently and needs to be integrated with the BAAS system. The BAAS, namely Blockchain as a Service, is a block chain Service, and a user can deploy and develop various block chain services efficiently, flexibly and easily by using a BAAS system. It should be noted that the present application does not replace the existing open source task scheduling framework, but enhances their capabilities by organically combining them to meet the task scheduling requirements of a specific field.
Referring to fig. 1, fig. 1 is a schematic diagram of a block chain BAAS system task scheduling framework based on a directed acyclic graph disclosed in the present application, in a graph theory, if a directed graph cannot go from a certain vertex and go back to the certain vertex through a plurality of edges, the graph is a directed acyclic graph, as can be seen from fig. 1, a block chain BAAS system task scheduling framework based on a directed acyclic graph includes a task creating module, a task triggering module, a task executing module, and an alarm module, where:
and the task creating module is configured to create the tasks based on the block chain BASS system and place the tasks into the task pool. When creating a task, parameters for task execution need to be specified, including: trigger strategy, execution strategy, alarm strategy, failure processing strategy, arrangement and configuration, etc. The strategy can be expanded according to requirements, flexibility is achieved, the task scheduling framework can meet the requirements of the block chain BAAS system on complex task scheduling to a great extent through strategy configuration and expansion, and development difficulty is greatly reduced. The task pool provides persistent storage capacity of tasks, and the task pool can be plugged and unplugged, so-called pluggable performance, wherein literal understanding means that plugging and unplugging do not affect normal operation of the system, plugging and unplugging certain functions can be realized, and system operation is not affected, and the task pool can be interpreted as adding configuration to automatically operate on software, and automatically stops without configuration. For example, the task pool may be pluggable by using a MySQL database to perform persistent storage, and may also be implemented in other manners, which is not specifically limited in this application. The task scheduling framework with pluggable design enables the framework to have expandability and evolutionary capability, and the selection which best meets the current situation can be made according to requirements, technologies, cost, infrastructure and the like.
And the task triggering module is configured to check the task pool, find the tasks to be executed meeting the triggering strategy in the tasks, and send the tasks to be executed to the execution queue of the task execution module. The trigger strategy comprises immediate execution, time-designated execution, interval execution, cron expression execution and the like, and is extensible. The task triggering module provides the capability of selecting tasks from the task pool, takes the tasks meeting the triggering strategy in the task pool as the tasks to be executed, and sends the tasks to be executed to the execution queue of the task execution module. Meanwhile, the task trigger module can be plugged, for example, the task trigger module adopts a mode based on a Redis lock and local scheduling, and can be combined with an open-source distributed scheduling framework to realize distributed scheduling of tasks, wherein a Redis (Remote Dictionary Server), namely, a Remote Dictionary service, is an open-source log-type and Key-Value database which is written by using an ANSI C language, supports a network, can be based on a memory and can also be persisted, and provides APIs (application programming interfaces) of multiple languages.
And the task execution module is configured to execute the task to be executed according to the execution queue, generate a task execution result and check the task execution result. The task execution module comprises an execution strategy configuration item, namely the task execution module can configure the execution strategy, the execution strategy configuration item comprises parallel execution and distributed serial execution, and the execution strategy configuration item can be expanded. The execution queue provides queue service capability, and can use a memory queue or a distributed queue. Meanwhile, the task execution module may be plugged, for example, the task execution module implements the local queue by using a thread pool threadpool built in Java.
And the task execution module checks the task execution result, and if the task execution result is that the task is successfully executed, the task execution module evaluates the task arrangement of the task to be executed according to the execution parameters specified when the task is created, by combining with the graph 1. And if the task to be executed has the task arrangement and the task arrangement is not completed, continuing to execute the subsequent tasks according to the execution relation in the task arrangement. The execution relation is configured in advance when the task is created, the execution relation of a plurality of tasks is established in the task arrangement, the task arrangement corresponds to a directed acyclic graph, the task arrangement is executed according to the task arrangement sequence of the execution relation in the directed acyclic graph, and the information of the task arrangement is updated.
Referring to fig. 2, fig. 2 is an exemplary diagram of a directed acyclic graph disclosed in an embodiment of the present application, where if task orchestration needs to be performed, a task execution module updates task orchestration information based on the directed acyclic graph, and if task orchestration does not need to be performed, the task execution module removes a task pool for a task to be performed. In order to facilitate further understanding of the present application, taking the task arrangement that needs to be performed as an example, 7 tasks are illustrated in fig. 2, and in the blockchain BAAS system, each task may be regarded as a node, a plurality of execution relations are preset in the 7 tasks, and when the task arrangement is performed, the tasks are sequentially executed according to the task arrangement sequence in the execution relations, for example, taking fig. 2 as an example, the execution sequence is assumed to be sequentially executed from task 1 to task 7, and the specific execution steps are as follows:
step 1: based on the directed acyclic graph shown in fig. 2, the task execution modules execute the tasks in sequence according to the task arrangement order in the execution relation, and the task arrangement order in fig. 2 is that the direction of the front view 2 is executed from left to right in the direction indicated by the arrow, that is, the direction from task 1 to task 7. And scheduling and executing the tasks from the task 1, and triggering the concurrent execution of the tasks 2, 3 and 4 from the edge of the task 1 after the task 1 is successfully executed. In the directed acyclic graph, an edge associated with a node has a part of an outgoing edge and an incoming edge, in fig. 2, the outgoing edge of task 1 connects tasks 2, 3 and 4, it can be seen that the outgoing edge of task 1 is an edge in the direction of an arrow on the right side of the node of task 1 in the front view 2, and accordingly, the incoming edge can be understood as an edge in the direction of an arrow on the left side of a certain node in the front view 2.
Step 2: after the tasks 2 and 3 are successfully executed, the mark of the task 5 is updated, and the number of entries of the task 5 is reduced by 1. The degree of entries is an initial value calculated according to task arrangement configuration when a task is created, and is updated according to the execution process of the task, the degree of entries of the task 5 is the number of edges, for example, taking a front view 2 as an example, the number of edges of the left side of a node where the current task 5 is located is two, that is, the number of edges of a direction pointing to the task 5 is 2, the degree of entries of the task 5 is initially 2, and after the tasks 2 and 3 are executed, the degree of entries are updated to 0, and the condition for executing the degree of entries of the task 5 is met, then the task 5 is triggered to execute.
And 3, step 3: and after the task 4 is successfully executed, the execution condition of the number of entries of the task 6 is met, and the task 6 is triggered to be executed.
And 4, step 4: after the tasks 5 and 6 are successfully executed, the marks of the task 7 are respectively updated until the in-degree number execution condition of the task 7 is met, the task 7 is triggered to be executed, and after the task 7 is executed, the task arrangement based on the directed acyclic graph shown in fig. 2 is executed.
The above is an example of a step of performing task arrangement according to a task arrangement sequence of an execution relation in a directed acyclic graph, where a task execution module updates information of task arrangement according to an execution progress in a task arrangement process, for example, updates the degree according to the task execution progress, and with reference to fig. 1, after the task execution module updates the task arrangement information based on the directed acyclic graph, the task execution module updates information of a next task arrangement according to actual requirements, and after the current task arrangement execution is completed, a task trigger module may continue to check a task pool to find a task to be executed that meets a trigger policy, as shown by an arrow in fig. 1.
And the alarm module is configured to check whether an alarm strategy is met or not if the task execution result is that the task execution fails. The warning module is used for providing warning notice, and the warning module is pluggable, if the warning module can be used for warning notice through the access nailing robot so as to realize that the warning module is pluggable, other forms can be provided, and the application is not particularly limited. If the alarm strategy is met through the inspection of the alarm module, the alarm module triggers the alarm, and the specific condition meeting the alarm strategy can be preset according to the actual condition.
The task execution module is further configured, in conjunction with fig. 1, to evaluate a failure handling policy if the alarm policy is not satisfied or the alarm is triggered to end by the alarm module, where the failure handling policy may include: fixed interval retry, dynamic interval retry, end, i.e., failure handling policy may include both an end and retry state. When the evaluation result is the end, the task execution module removes the task pool of the task to be executed; when the evaluation result is that the task retries, the task execution module updates the task execution information, where the updated task execution information may include the number of task executions, next trigger time, and the like, and if the current task is scheduled and executed, the task trigger module may continue to check the task pool to find the task to be executed that meets the trigger policy, and as shown by an arrow in the figure in conjunction with fig. 1, the example steps in the figure are executed again according to the actual situation.
In order to facilitate further understanding of the present application, the implementation principle of the present application is further described, where the task scheduling framework in the present application cannot operate independently, and needs to be integrated with the blockchain BAAS system, and the blockchain BAAS system integrates the task scheduling framework by adding a MAVEN dependency, and then configures the framework. The Maven is a tool specially used for constructing and managing related Java items, and the advantages of using the Maven to manage the items are mainly two points, one is that all Java items managed by the Maven have the same item structure, and the other is that a jar package is convenient to maintain in a unified mode.
With reference to fig. 4 in conjunction with the above description, fig. 4 is a schematic flowchart illustrating a process of implementing a pluggable function disclosed in this embodiment of the present application. The method comprises the following steps of configuring a block chain BAAS system task scheduling framework based on the directed acyclic graph: the task pool adopts a MySQL database for persistent storage, so that the task pool can be plugged and unplugged; the task trigger module realizes distributed scheduling by adopting a mode based on Redis lock and local scheduling, and realizes that the task trigger module can be plugged; the task execution module adopts a built-in thread queue execution or of Java to realize a local queue, so that the task execution module can be plugged; the alarm module is connected to the nailing robot to give an alarm, so that the alarm module can be plugged and unplugged. The task pool, the task trigger module, the task execution module and the alarm module are not limited to the above form, and other forms are available, and the specific implementation manner is not specifically limited in the present application.
After the task scheduling framework is configured, the task scheduling framework completes initialization at the starting stage of the BAAS system, and then task scheduling service can be provided for the block-chaining BAAS system. Referring to fig. 3, fig. 3 is an exemplary diagram of another directed acyclic graph disclosed in the embodiment of the present application, for example, a blockchain BAAS system needs to create a blockchain of a certain type, and the specific steps of creating are sequentially: the method comprises the steps of starting a chain node in parallel, creating a chain channel, adding an organization to the channel, and registering chain monitoring, wherein before a specific task is executed, a block chain BAAS system needs to realize service codes of the steps in advance and register the service codes as the task. When the action of creating the blockchain is executed, the blockchain BAAS system invokes a task scheduling frame to perform configuration and creation of tasks, including configuring task arrangement information of the tasks, assuming that the chain nodes started in parallel in this embodiment include a chain node 1 and a chain node 2, the corresponding directed acyclic graph is the directed acyclic graph shown in fig. 3, and the task scheduling frame automatically executes scheduling of the tasks according to the configured task information, that is, executes specific tasks in task arrangement according to the execution relationship shown in fig. 3.
In the application, the task arrangement based on the directed acyclic graph can flexibly arrange tasks and can enable the task units to be reusable, wherein the task units refer to program codes for realizing the task arrangement, the task arrangement corresponds to a plurality of task units, and the task unit reusability refers to the fact that the realization codes of the tasks can be configured into the plurality of task arrangements. For example, task T is used for sending short messages, the existing A, B two services correspond to X, Y two task arrangements, because the services are different, X, Y two task arrangements are also different, but both services need to send short messages, and then both task arrangements include task T, that is, task T can be arranged in both task arrangements. For a block chain BAAS system with a large number of tasks, the reusability of the task units can greatly increase the code reusability, reduce the code amount and increase the robustness of the system.
According to the technical scheme, the block chain BAAS system task scheduling framework based on the directed acyclic graph comprises a task creating module, a task triggering module, a task executing module and an alarm module, wherein the task creating module creates tasks and puts the tasks into a task pool; the task triggering module checks the task pool, searches for a task to be executed which meets a triggering strategy, and sends the task to be executed to an execution queue of the task executing module; the task execution module executes the task to be executed according to the execution queue, generates a task execution result and checks the task execution result; if the task is successfully executed, the task execution module evaluates the task arrangement of the task to be executed, and if the task arrangement needs to be executed, the task execution module updates the information of the task arrangement based on the directed acyclic graph; if the task arrangement does not need to be executed, the task execution module removes the task pool of the tasks to be executed; if the task execution fails, the alarm module checks whether an alarm strategy is met, and if the alarm strategy is met, the alarm module triggers an alarm; if the alarm strategy is not satisfied or the alarm is triggered to be finished, the task execution module evaluates a failure processing strategy; if the evaluation result is end, the task execution module removes the task pool of the task to be executed; and if the evaluation result is the task retry, the task execution module updates the task execution information. The application can realize high concurrency, high availability and high performance capability of the frame by matching different pluggable components, and solves the problem that the dispatching requirement on complex and unreliable tasks cannot be met in a BAAS system by applying high availability, distributed, pluggable and directed acyclic graph technologies.
Other embodiments of the invention will be apparent to those skilled in the art from consideration of the specification and practice of the invention disclosed herein. This application is intended to cover any variations, uses, or adaptations of the invention following, in general, the principles of the invention and including such departures from the present disclosure as come within known or customary practice within the art to which the invention pertains. It is intended that the specification and examples be considered as exemplary only, with a true scope and spirit of the invention being indicated by the following claims.