@@ -29,7 +29,7 @@ class InteractiveClient {
2929 if ( msg . type === Message . RUN ) {
3030 const [ cmd , ...opts ] = InteractiveClient . parseCommand ( msg . data ) ;
3131 this . subprocess = spawn ( cmd , opts ) ;
32- this . subprocess . on ( 'exit' , code => this . sendMessage ( Message . COMPLETE , code ) ) ;
32+ this . subprocess . on ( 'exit' , code => this . sendMessage ( Message . COMPLETE , [ code ] ) ) ;
3333 this . subprocess . stdout . on ( 'data' , data => this . sendMessage ( Message . STDOUT , data ) ) ;
3434 this . subprocess . stderr . on ( 'data' , data => this . sendMessage ( Message . STDERR , data ) ) ;
3535 } else if ( msg . type === Message . KILL ) {
@@ -46,15 +46,31 @@ class InteractiveClient {
4646 Utils ,
4747 ) => {
4848 const { Storage} = Utils ;
49-
50- async function saveArtifact ( ) {
51- const client = await Storage . getClient ( dataInfo . backend , null , config ) ;
49+ const fetchArtifact = async ( ) => {
50+ const client = await Storage . getClient ( dataInfo . backend , undefined , config ) ;
5251 const dataPath = path . join ( ...dirs . concat ( 'data' ) ) ;
5352 const stream = await client . getFileStream ( dataInfo ) ;
5453 await pipeline ( stream , fs . createWriteStream ( dataPath ) ) ;
5554 const filePath = path . join ( ...dirs . concat ( '__init__.py' ) ) ;
5655 await fsp . writeFile ( filePath , initFile ( name , type ) ) ;
57- }
56+ } ;
57+
58+ this . runTask ( fetchArtifact ) ;
59+ } ) ;
60+ } else if ( msg . type === Message . SAVE_ARTIFACT ) {
61+ const [ filepath , name , backend , config = { } ] = msg . data ;
62+ requirejs ( [
63+ './utils.build' ,
64+ ] , (
65+ Utils ,
66+ ) => {
67+ const { Storage} = Utils ;
68+ const saveArtifact = async ( ) => {
69+ const client = await Storage . getClient ( backend , null , config ) ;
70+ const stream = await fs . createReadStream ( filepath ) ;
71+ const dataInfo = await client . putFileStream ( name , stream ) ;
72+ return dataInfo ;
73+ } ;
5874
5975 this . runTask ( saveArtifact ) ;
6076 } ) ;
@@ -76,7 +92,7 @@ class InteractiveClient {
7692 await fsp . unlink ( filepath ) ;
7793 } ) ;
7894 } else {
79- this . sendMessage ( Message . COMPLETE , 2 ) ;
95+ this . sendMessage ( Message . COMPLETE , [ 2 ] ) ;
8096 }
8197 }
8298
@@ -99,13 +115,14 @@ class InteractiveClient {
99115
100116 async runTask ( fn ) {
101117 let exitCode = 0 ;
118+ let result ;
102119 try {
103- await fn ( ) ;
120+ result = await fn ( ) ;
104121 } catch ( err ) {
105122 exitCode = 1 ;
106123 console . log ( 'Task failed with error:' , err ) ;
107124 }
108- this . sendMessage ( Message . COMPLETE , exitCode ) ;
125+ this . sendMessage ( Message . COMPLETE , [ exitCode , result ] ) ;
109126 }
110127
111128 static parseCommand ( cmd ) {
0 commit comments