@@ -9,6 +9,7 @@ import {assert} from "./asserts";
9
9
import * as dotenv from "dotenv" ;
10
10
import * as camelCase from "camelcase" ;
11
11
12
+ let parser : Parser | null = null ;
12
13
const checkFolderAndFile = ( cwd : string , file ?: string ) => {
13
14
assert ( fs . pathExistsSync ( cwd ) , `${ cwd } is not a directory` ) ;
14
15
@@ -44,18 +45,18 @@ export async function handler(argv: any) {
44
45
} else if ( argv . list != null ) {
45
46
checkFolderAndFile ( cwd , argv . file ) ;
46
47
const pipelineIid = await state . getPipelineIid ( cwd ) ;
47
- const parser = await Parser . create ( cwd , pipelineIid , false , argv . file , argv . home ) ;
48
+ parser = await Parser . create ( cwd , pipelineIid , false , argv . file , argv . home ) ;
48
49
Commander . runList ( parser ) ;
49
50
} else if ( argv . job ) {
50
51
checkFolderAndFile ( cwd , argv . file ) ;
51
52
const pipelineIid = await state . getPipelineIid ( cwd ) ;
52
- const parser = await Parser . create ( cwd , pipelineIid , false , argv . file , argv . home ) ;
53
+ parser = await Parser . create ( cwd , pipelineIid , false , argv . file , argv . home ) ;
53
54
await Commander . runSingleJob ( parser , argv . job , argv . needs , argv . privileged ) ;
54
55
} else {
55
56
checkFolderAndFile ( cwd , argv . file ) ;
56
57
await state . incrementPipelineIid ( cwd ) ;
57
58
const pipelineIid = await state . getPipelineIid ( cwd ) ;
58
- const parser = await Parser . create ( cwd , pipelineIid , false , argv . file , argv . home ) ;
59
+ parser = await Parser . create ( cwd , pipelineIid , false , argv . file , argv . home ) ;
59
60
await Commander . runPipeline ( parser , argv . manual || [ ] , argv . privileged ) ;
60
61
}
61
62
}
@@ -71,3 +72,15 @@ exports.handler = async (argv: any) => {
71
72
throw e ;
72
73
}
73
74
} ;
75
+
76
+ process . on ( 'SIGINT' , async ( _ : string , code : number ) => {
77
+ if ( ! parser ) {
78
+ return process . exit ( code ) ;
79
+ }
80
+ const promises = [ ] ;
81
+ for ( const job of parser . getJobs ( ) ) {
82
+ promises . push ( job . removeContainer ( ) ) ;
83
+ }
84
+ await Promise . all ( promises ) ;
85
+ process . exit ( code ) ;
86
+ } ) ;
0 commit comments