You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -48,97 +48,166 @@ Among them, each task may produce output, and may also require the output of som
48
48
49
49
### Programmatically implement task definition
50
50
51
-
Users need to program to implement the `Action` trait to define the specific logic of the task, and then build a series of `DefaultTask`. The example: `examples/compute_dag.rs`. `DefaultTask` is the default implementation of the Task trait, and it has several mandatory attributes:
51
+
Users need to program to implement the `Action` trait to define the specific logic of the task, and then build a series of `DefaultTask`.
52
52
53
-
-`id`: uniquely identifies the task assigned by the global ID assigner
54
-
-`name`: the name of the task
55
-
-`predecessor_tasks`: the predecessor tasks of this task
56
-
-`action`: is a dynamic type that implements the Action trait in user programming, and it is the specific logic to be executed by the task
53
+
First, users need to define some specific task logic. There are two ways to define task logic:
54
+
55
+
- Create a closure whose type is `Simple`, which is suitable for simple scenarios.
56
+
- Create a type and implement the `Complex` trait, which is suitable for more complex situations. For example, if the logic of the task is to execute a system command, the command string needs to be recorded in some way. You can create a `Commad` structure with a string attribute inside to store the command string.
57
+
58
+
You can refer to examples:`examples/actions.rs`.
59
+
60
+
In the second step, you need to use the defined task logic to create specific tasks. Here you may need to use the `DefaultTask` type, which provides users with several ways to create `Task`. `DefaultTask` allows you to specify specific task logic for the task and give the task a name. Please refer to the documentation for specific function functions.
61
+
62
+
In the third step, you need to specify dependencies for the defined series of tasks. Here you need to use the `set_predecessors` function of `DefaultTask`. This function requires you to specify a series of predecessor tasks for the current task.
63
+
64
+
The fourth step is to create a `Dag` and put all the defined tasks into the `Dag` scheduler.
65
+
66
+
Optional step: You can specify an environment variable for `Dag`. This environment variable is available in all tasks. In some specific tasks, this behavior can be useful.
67
+
68
+
Finally, don’t forget to initialize the logger, and then you can call the `start` function of `Dag` to start executing all tasks.
69
+
70
+
You can refer to an example for the above complete steps: `examples/compute_dag.rs`
57
71
58
72
59
73
Here is the `examples/impl_action.rs` example:
60
74
61
75
```rust
62
-
//! Implement the Action trait to define the task logic.
76
+
//! Only use Dag, execute a job. The graph is as follows:
First, we define `SimpleAction` and implement the `Action` trait for this structure. In the rewritten run function, we simply get the output value of the predecessor task and multiply it by the environment variable `base`. Then accumulate the multiplied result to itself self.0.
110
-
111
-
After defining the specific task logic, start creating the prerequisites for executing `Dag`:
112
-
Initialize the global logger first. Here we set the log level to Info, and do not give the log output file, let the log output to the console by default.
169
+
First, we initialize the logger, declare the `Compute` type, and implement the `Complex` trait for it. In the rewritten run function, we simply get the output value of the predecessor task and multiply it by the environment variable `base`. Then accumulate the multiplied result to itself self.0.
113
170
114
-
Create a `DefaultTask` with `SimpleAction` and give the task a name. Then set the dependencies between tasks.
171
+
Next, we define 6 tasks and show the usage of some functions in the `DefaultTask` type. Set predecessor tasks for each task.
115
172
116
-
Then create a Dag and assign it a global environment variable.
173
+
Then, create a `Dag`, set a base environment variable for it, and use the start method to start executing all tasks.
117
174
118
175
Finally we call the `start` function of `Dag` to execute all tasks. After the task is executed, call the `get_result` function to obtain the final execution result of the task.
You can see an example: `examples/yaml_dag.rs`. In fact, you can also programmatically read the yaml configuration file generation task, which is very simple, just use the `with_yaml` function provided by `Dag` to parse the configuration file.
229
298
299
+
--------------------------------------
300
+
230
301
**In addition to these two methods, `dagrs` also supports advanced task custom configuration.**
231
302
232
-
- `DefaultTask`is a default implementation of the `Task` trait. Users can also customize tasks and add more functions and attributes to tasks, but they still need to have the four necessary attributes in `DefaultTask`. `YamlTask` is another example of `Task` concrete implementation, its source code is available for reference, or refer to `example/custom_task.rs`.
233
-
- In addition to yaml-type configuration files, users can also provide other types of configuration files, but in order to allow other types of configuration files to be parsed as tasks, users need to implement the `Parser` trait. `YamlParser` source code is available for reference, or refer to `examples/custom_parser.rs`
303
+
- `DefaultTask` is a default implementation of the `Task` trait. Users can also customize tasks and add more functions and attributes to tasks, but they still need to have the four necessary attributes in `DefaultTask`. `YamlTask` is another example of `Task` concrete implementation, its source code is available for reference. No matter how you customize the task type, the customized task type must have the following attributes:
304
+
- `id`: uniquely identifies the task assigned by the global ID assigner
305
+
- `name`: the name of the task
306
+
- `predecessor_tasks`: the predecessor tasks of this task
307
+
- `action`: is a dynamic type that implements the Action trait in user programming, and it is the specific logic to be executed by the task
308
+
309
+
- In addition to yaml-type configuration files, users can also provide other types of configuration files, but in order to allow other types of configuration files to be parsed as tasks, users need to implement the `Parser` trait. `YamlParser` source code is available for reference.
310
+
311
+
`examples/custom_parser_and_task.rs`is an example of a custom task type and a custom configuration file parser
234
312
235
313
## Analyze the logic of task execution
236
314
@@ -323,27 +401,27 @@ gantt
323
401
324
402
### Basic function usage
325
403
326
-
`examples/compute_dag.rs`: Use a custom macro to generate multiple simple tasks.
404
+
`examples/compute_dag.rs`: A complete usage example of dagrs.
327
405
328
-
`examples/impl_action.rs`: Define a simple Action to build multiple tasks with the same logic.
406
+
`examples/action.rs`: Two ways to define the specific logic of a task.
329
407
330
-
`examples/yaml_dag.rs`: Spawn multiple tasks with a given yaml configuration file。
331
-
332
-
`examples/use_macro.rs`: Use the `gen_task` macro provided by `dagrs` to generate multiple simple tasks。
408
+
`examples/yaml_dag.rs`: Example of reading yaml configuration file (needs to enable `yaml` features).
333
409
334
410
`examples/engine.rs`: Using `Engine` to manage multiple dags with different task types.
335
411
336
412
### Advanced Features
337
413
338
-
`examples/custom_task.rs`: Implement the `Task` trait and define your own task type.
339
-
340
-
`examples/custom_parser.rs`: Implement the `Parser` trait to define your own task configuration file parser。
414
+
`examples/custom_parser_and_task.rs`: Custom task types and configuration file parsers.
341
415
342
416
`examples/custom_log.rs`: Implement the `Logger` trait to define your own global logger.
343
417
418
+
`examples/derive_task.rs`:Use `CustomTask` derived macros to help customize task types.
419
+
420
+
`examples/dependencies.rs`:Use the `dependencies!` macro to specify dependencies in an intuitive way and define a series of tasks.
421
+
344
422
## Contribution
345
423
346
-
The dagrs project relies on community contributions and aims to simplify getting started. To develop `dagrs`, clone the repository, then install all dependencies, run the test suite and try it out locally. Pick an issue, make changes, and submit a pull request for community review.
424
+
The `dagrs` project relies on community contributions and aims to simplify getting started. To develop `dagrs`, clone the repository, then install all dependencies, run the test suite and try it out locally. Pick an issue, make changes, and submit a pull request for community review.
0 commit comments