@@ -52,7 +52,8 @@ export function onSubmit(sequence, databases) {
5252 } )
5353 . then ( data => {
5454 dispatch ( { type : types . SUBMIT_JOB , status : 'success' , data : data } ) ;
55- dispatch ( fetchStatus ( data . job_id ) )
55+ dispatch ( fetchStatus ( data . job_id ) ) ;
56+ dispatch ( fetchInfernalStatus ( data . job_id ) ) ;
5657 } )
5758 . catch ( error => dispatch ( { type : types . SUBMIT_JOB , status : 'error' , response : error } ) ) ;
5859 }
@@ -93,6 +94,41 @@ export function fetchStatus(jobId) {
9394 }
9495}
9596
97+ export function fetchInfernalStatus ( jobId ) {
98+ return function ( dispatch ) {
99+ fetch ( routes . infernalJobStatus ( jobId ) , {
100+ method : 'GET' ,
101+ mode : 'cors' ,
102+ credentials : 'include' ,
103+ headers : {
104+ 'Accept' : 'application/json, text/plain, */*' ,
105+ 'Content-Type' : 'application/json'
106+ }
107+ } )
108+ . then ( function ( response ) {
109+ if ( response . ok ) {
110+ return response . json ( )
111+ } else {
112+ throw response ;
113+ }
114+ } )
115+ . then ( ( data ) => {
116+ if ( data . status === 'started' || data . status === 'pending' ) {
117+ let statusTimeout = setTimeout ( ( ) => store . dispatch ( fetchInfernalStatus ( jobId ) ) , 2000 ) ;
118+ dispatch ( { type : types . SET_STATUS_TIMEOUT , timeout : statusTimeout } ) ;
119+ } else if ( data . status === 'success' ) {
120+ dispatch ( fetchInfernalResults ( jobId ) ) ;
121+ }
122+ } )
123+ . catch ( error => {
124+ if ( store . getState ( ) . hasOwnProperty ( 'statusTimeout' ) ) {
125+ clearTimeout ( store . getState ( ) . statusTimeout ) ; // clear status timeout
126+ }
127+ dispatch ( { type : types . FETCH_STATUS , infernal_status : 'error' } )
128+ } ) ;
129+ }
130+ }
131+
96132export function fetchResults ( jobId ) {
97133 let state = store . getState ( ) ;
98134
@@ -120,6 +156,31 @@ export function fetchResults(jobId) {
120156 }
121157}
122158
159+ export function fetchInfernalResults ( jobId ) {
160+ return function ( dispatch ) {
161+ fetch ( routes . infernalJobResult ( jobId ) , {
162+ method : 'GET' ,
163+ mode : 'cors' ,
164+ credentials : 'include' ,
165+ headers : {
166+ 'Accept' : 'application/json, text/plain, */*' ,
167+ 'Content-Type' : 'application/json'
168+ }
169+ } )
170+ . then ( function ( response ) {
171+ if ( response . ok ) {
172+ return response . json ( )
173+ } else {
174+ throw response ;
175+ }
176+ } )
177+ . then ( data => dispatch ( { type : types . FETCH_INFERNAL_RESULTS , infernal_status : 'success' , data : data } ) )
178+ . catch ( error => {
179+ dispatch ( { type : types . FETCH_INFERNAL_RESULTS , infernal_status : 'error' } )
180+ } ) ;
181+ }
182+ }
183+
123184export function failedFetchResults ( response ) {
124185 if ( response . status === 404 ) {
125186 return { type : types . FAILED_FETCH_RESULTS , status : "does_not_exist" , start : 0 } ;
0 commit comments