File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -17,7 +17,6 @@ async function startServer() {
1717 Logger . debug ( `✌️ 后端服务启动成功!` ) ;
1818 console . debug ( `✌️ 后端服务启动成功!` ) ;
1919 process . send ?.( 'ready' ) ;
20- require ( './loaders/bootAfter' ) . default ( ) ;
2120 } )
2221 . on ( 'error' , ( err ) => {
2322 Logger . error ( err ) ;
Original file line number Diff line number Diff line change @@ -68,24 +68,26 @@ export default async () => {
6868 } ) ;
6969 }
7070
71- const installDependencies = ( ) => {
72- // 初始化时安装所有处于安装中,安装成功,安装失败的依赖
73- DependenceModel . findAll ( {
71+ const installDependencies = async ( ) => {
72+ const docs = await DependenceModel . findAll ( {
7473 where : { } ,
7574 order : [
7675 [ 'type' , 'DESC' ] ,
7776 [ 'createdAt' , 'DESC' ] ,
7877 ] ,
7978 raw : true ,
80- } ) . then ( async ( docs ) => {
81- await DependenceModel . update (
82- { status : DependenceStatus . queued , log : [ ] } ,
83- { where : { id : docs . map ( ( x ) => x . id ! ) } } ,
84- ) ;
85- setTimeout ( ( ) => {
86- dependenceService . installDependenceOneByOne ( docs ) ;
87- } , 5000 ) ;
8879 } ) ;
80+
81+ await DependenceModel . update (
82+ { status : DependenceStatus . queued , log : [ ] } ,
83+ { where : { id : docs . map ( ( x ) => x . id ! ) } } ,
84+ ) ;
85+
86+ setTimeout ( async ( ) => {
87+ await dependenceService . installDependenceOneByOne ( docs ) ;
88+
89+ require ( './loaders/bootAfter' ) . default ( ) ;
90+ } , 5000 ) ;
8991 } ;
9092
9193 // 初始化更新 linux/python/nodejs 镜像源配置
Original file line number Diff line number Diff line change @@ -132,10 +132,12 @@ export default class DependenceService {
132132 docs : Dependence [ ] ,
133133 isInstall : boolean = true ,
134134 force : boolean = false ,
135- ) {
135+ ) : Promise < void > {
136136 docs . forEach ( ( dep ) => {
137137 this . installOrUninstallDependency ( dep , isInstall , force ) ;
138138 } ) ;
139+
140+ return taskLimit . waitDependencyQueueDone ( ) ;
139141 }
140142
141143 public async reInstall ( ids : number [ ] ) : Promise < Dependence [ ] > {
Original file line number Diff line number Diff line change @@ -189,6 +189,19 @@ class TaskLimit {
189189 return this . scriptLimit . add ( fn , options ) ;
190190 }
191191
192+ public async waitDependencyQueueDone ( ) : Promise < void > {
193+ if ( this . dependenyLimit . size === 0 && this . dependenyLimit . pending === 0 ) {
194+ return ;
195+ }
196+ return new Promise ( ( resolve ) => {
197+ const onIdle = ( ) => {
198+ this . dependenyLimit . removeListener ( 'idle' , onIdle ) ;
199+ resolve ( ) ;
200+ } ;
201+ this . dependenyLimit . on ( 'idle' , onIdle ) ;
202+ } ) ;
203+ }
204+
192205 public runDependeny < T > (
193206 dependency : Dependence ,
194207 fn : IDependencyFn < T > ,
You can’t perform that action at this time.
0 commit comments