@@ -13,39 +13,44 @@ export async function executorTask(
1313 const jobDataArg = JSON . stringify ( job . data ) ;
1414 // const escapedJobDataArg = `'${jobDataArg.replace(/'/g, "'\\''")}'`;
1515
16- const child = spawn ( join ( command ) , {
17- shell : options ?. shell ?? true ,
18- // stdio: 'pipe',
19- } ) ;
20-
21- child . stdin . write ( jobDataArg ) ;
22- child . stdin . end ( ) ;
23-
24- let outputChunk = '' ;
25- let errorChunk = '' ;
26-
27- child . stdout . on ( 'data' , ( data ) => {
28- console . log ( `stdout: ${ data } ` ) ;
29- outputChunk += data ;
30- } ) ;
31-
32- child . stderr . on ( 'data' , ( data ) => {
33- console . error ( `stderr: ${ data } ` ) ;
34- errorChunk += data ;
35- } ) ;
36-
37- child . on ( 'close' , ( code ) => {
38- console . log ( `Le processus enfant s'est terminé avec le code ${ code } ` ) ;
39- resolve ( {
40- status : code ,
41- output : outputChunk ?. toString ( ) ,
42- error : errorChunk ?. toString ( ) ,
16+ try {
17+ const child = spawn ( join ( command ) , {
18+ shell : options ?. shell ?? true ,
19+ stdio : 'pipe' ,
4320 } ) ;
44- } ) ;
4521
46- child . on ( 'error' , ( spawnError ) => {
47- console . error ( 'Erreur lors du lancement du processus enfant' , spawnError ) ;
48- reject ( spawnError ) ;
49- } ) ;
22+ child . stdin . write ( jobDataArg ) ;
23+ child . stdin . end ( ) ;
24+
25+ let outputChunk = '' ;
26+ let errorChunk = '' ;
27+
28+ child . stdout . on ( 'data' , ( data ) => {
29+ console . log ( `stdout: ${ data } ` ) ;
30+ outputChunk += data ;
31+ } ) ;
32+
33+ child . stderr . on ( 'data' , ( data ) => {
34+ console . error ( `stderr: ${ data } ` ) ;
35+ errorChunk += data ;
36+ } ) ;
37+
38+ child . on ( 'close' , ( code ) => {
39+ console . log ( `Le processus enfant s'est terminé avec le code ${ code } ` ) ;
40+ resolve ( {
41+ status : code ,
42+ output : outputChunk ?. toString ( ) ,
43+ error : errorChunk ?. toString ( ) ,
44+ } ) ;
45+ } ) ;
46+
47+ child . on ( 'error' , ( spawnError ) => {
48+ console . error ( 'Erreur lors du lancement du processus enfant' , spawnError ) ;
49+ reject ( spawnError ) ;
50+ } ) ;
51+ } catch ( error ) {
52+ console . error ( 'Erreur lors de l\'exécution de la tâche' , error ) ;
53+ reject ( error ) ;
54+ }
5055 } ) ;
5156}
0 commit comments