@@ -208,17 +208,19 @@ function startMonitor(j: Job, ws: Webservice, getState, dispatch) {
208
208
...value ,
209
209
messages : [ 'removed to keep log cleaner' ] ,
210
210
} )
211
+ let updatedJob = {
212
+ ...j ,
213
+ jobData : value ,
214
+ }
211
215
const finished = [
212
216
JobStatus . ERROR ,
213
217
JobStatus . FAIL ,
214
218
JobStatus . SUCCESS ,
215
219
] . includes ( value . status )
216
-
217
220
if ( finished ) {
218
221
clearInterval ( monitor )
222
+ updatedJob . state = JobState . ENDED
219
223
}
220
- let updatedJob = { ...j }
221
- updatedJob . jobData = value
222
224
const newJobName = `${
223
225
updatedJob . jobData . nicename ??
224
226
updatedJob . jobData . script . nicename
@@ -712,68 +714,83 @@ export function pipelineMiddleware({ getState, dispatch }) {
712
714
case runJob . type :
713
715
// Launch the job with the API and start monitoring its execution
714
716
// Also change its state to submited
715
- let runJobInterval = null
716
717
const jobToRun = action . payload as Job
717
718
// Empty previous references to jobData results for re run
718
719
if ( jobToRun . jobData && jobToRun . jobData . results ) {
719
720
jobToRun . jobData . results = undefined
720
721
}
721
- info ( 'Launching job' , JSON . stringify ( jobToRun ) )
722
- const launchJobOn = pipelineAPI . launchJob ( jobToRun )
723
- runJobInterval = setInterval ( ( ) => {
724
- if ( webservice ) {
725
- launchJobOn ( webservice )
726
- . then ( ( jobResponse ) => {
727
- const updatedJob = {
728
- ...jobToRun ,
729
- state : JobState . SUBMITTED ,
730
- } as Job
731
- if (
732
- jobResponse . type == 'JobRequestError' ||
733
- jobResponse . type == 'JobUnknownResponse'
734
- ) {
735
- updatedJob . jobRequestError =
736
- jobResponse as JobRequestError
737
- } else {
738
- updatedJob . jobData = jobResponse as JobData
739
- // start a job monitor
740
- startMonitor (
741
- updatedJob ,
742
- webservice ,
743
- getState ,
744
- dispatch
745
- )
746
- }
747
- clearInterval ( runJobInterval )
748
- dispatch ( updateJob ( updatedJob ) )
749
- } )
750
- . catch ( ( e ) => {
751
- clearInterval ( runJobInterval )
752
- error (
753
- 'error launching job' ,
754
- jobToRun . internalId ,
755
- e
722
+ if (
723
+ jobToRun . state === JobState . SUBMITTED ||
724
+ jobToRun . state === JobState . SUBMITTING
725
+ ) {
726
+ info ( 'Job is already launched' , JSON . stringify ( jobToRun ) )
727
+ } else if ( webservice ) {
728
+ info ( 'Launching job' , JSON . stringify ( jobToRun ) )
729
+ dispatch (
730
+ updateJob ( { ...jobToRun , state : JobState . SUBMITTING } )
731
+ )
732
+ pipelineAPI
733
+ . launchJob ( jobToRun ) ( webservice )
734
+ . then ( ( jobResponse ) => {
735
+ const updatedJob = {
736
+ ...jobToRun ,
737
+ state : JobState . SUBMITTED ,
738
+ } as Job
739
+ if (
740
+ jobResponse . type == 'JobRequestError' ||
741
+ jobResponse . type == 'JobUnknownResponse'
742
+ ) {
743
+ updatedJob . jobRequestError =
744
+ jobResponse as JobRequestError
745
+ } else {
746
+ updatedJob . jobData = jobResponse as JobData
747
+ // start a job monitor
748
+ startMonitor (
749
+ updatedJob ,
750
+ webservice ,
751
+ getState ,
752
+ dispatch
756
753
)
757
- dispatch (
758
- updateJob ( {
759
- ...jobToRun ,
760
- jobData : {
761
- ...jobToRun . jobData ,
762
- status : JobStatus . ERROR ,
754
+ }
755
+ dispatch ( updateJob ( updatedJob ) )
756
+ } )
757
+ . catch ( ( e ) => {
758
+ error ( 'error launching job' , jobToRun . internalId , e )
759
+ dispatch (
760
+ updateJob ( {
761
+ ...jobToRun ,
762
+ jobData : {
763
+ ...jobToRun . jobData ,
764
+ status : JobStatus . ERROR ,
765
+ } ,
766
+ errors : [
767
+ {
768
+ error :
769
+ e instanceof ParserException
770
+ ? e . parsedText
771
+ : String ( e ) ,
763
772
} ,
764
- errors : [
765
- {
766
- error :
767
- e instanceof ParserException
768
- ? e . parsedText
769
- : String ( e ) ,
770
- } ,
771
- ] ,
772
- } )
773
- )
774
- } )
775
- }
776
- } , 1000 )
773
+ ] ,
774
+ } )
775
+ )
776
+ } )
777
+ } else {
778
+ error ( 'No webservice available to run job' , jobToRun )
779
+ dispatch (
780
+ updateJob ( {
781
+ ...jobToRun ,
782
+ jobData : {
783
+ ...jobToRun . jobData ,
784
+ status : JobStatus . ERROR ,
785
+ } ,
786
+ errors : [
787
+ {
788
+ error : 'No webservice available' ,
789
+ } ,
790
+ ] ,
791
+ } )
792
+ )
793
+ }
777
794
break
778
795
case requestStylesheetParameters . type :
779
796
const job = action . payload as Job
0 commit comments