@@ -32,6 +32,41 @@ public async Task Build()
32
32
var dataSource = _pluginManager . Resolve < IDataSource > ( _project . DataSource . Name ) ;
33
33
await dataSource . InitData ( ) ;
34
34
35
+ if ( _project . AllowParallel )
36
+ {
37
+ await this . ParallelBuild ( dataSource ) ;
38
+ }
39
+ else
40
+ {
41
+ await this . SerialBuild ( dataSource ) ;
42
+ }
43
+ }
44
+
45
+ public async Task SerialBuild ( IDataSource dataSource )
46
+ {
47
+ foreach ( var buildKV in _project . BuildTasks )
48
+ {
49
+ _logger . LogInformation ( $ "-------- BuildTask:{ buildKV . Key } Start! ---------") ;
50
+ var context = new BuildContext
51
+ {
52
+ PluginManager = _pluginManager ,
53
+ Project = _project ,
54
+ DataSource = dataSource ,
55
+ BuildKey = buildKV . Key ,
56
+ Build = buildKV . Value ,
57
+ Output = buildKV . Value . Output ? . Copy ( ) ,
58
+ } ;
59
+
60
+ //执行自身任务
61
+ await _pluginManager . Resolve < IBuildTask > ( context . Build . Type ) . Build ( context ) ;
62
+
63
+ _logger . LogInformation ( $ "-------- BuildTask:{ buildKV . Key } End! ---------") ;
64
+ }
65
+ }
66
+
67
+ private Task ParallelBuild ( IDataSource dataSource )
68
+ {
69
+
35
70
IList < BuildContext > allContexts = _project . BuildTasks . Select ( d => new BuildContext
36
71
{
37
72
PluginManager = _pluginManager ,
@@ -57,8 +92,8 @@ public async Task Build()
57
92
{
58
93
context . CountDown . AddCount ( context . DependOn . Count ) ;
59
94
}
60
-
61
- ThreadPool . QueueUserWorkItem ( this . BuildTask , ( context , allContexts ) ) ;
95
+
96
+ ThreadPool . QueueUserWorkItem ( ( obj ) => _ = this . BuildTask ( obj ) , ( context , allContexts ) ) ;
62
97
}
63
98
64
99
foreach ( var context in allContexts )
@@ -68,9 +103,11 @@ public async Task Build()
68
103
69
104
countdown . Signal ( ) ;
70
105
countdown . Wait ( ) ;
106
+
107
+ return Task . CompletedTask ;
71
108
}
72
109
73
- private async void BuildTask ( object obj )
110
+ private async Task BuildTask ( object obj )
74
111
{
75
112
var p = ( ( BuildContext context , IList < BuildContext > allContexts ) ) obj ;
76
113
@@ -87,7 +124,7 @@ private async void BuildTask(object obj)
87
124
88
125
foreach ( var c in p . allContexts )
89
126
{
90
- if ( c . DependOn == null || c . DependOn . Count == 0 )
127
+ if ( c . DependOn == null || c . DependOn . Count == 0 )
91
128
{
92
129
continue ;
93
130
}
0 commit comments