@@ -51,6 +51,12 @@ qx.Class.define("osparc.data.model.IframeHandler", {
5151 check : "osparc.widget.PersistentIframe" ,
5252 init : null ,
5353 nullable : true
54+ } ,
55+
56+ polling : {
57+ check : "Boolean" ,
58+ init : null ,
59+ nullable : true
5460 }
5561 } ,
5662
@@ -64,6 +70,11 @@ qx.Class.define("osparc.data.model.IframeHandler", {
6470 __retriesLeft : null ,
6571
6672 startPolling : function ( ) {
73+ if ( this . isPolling ( ) ) {
74+ return ;
75+ }
76+ this . setPolling ( true ) ;
77+
6778 this . getNode ( ) . getStatus ( ) . getProgressSequence ( )
6879 . resetSequence ( ) ;
6980
@@ -146,10 +157,12 @@ qx.Class.define("osparc.data.model.IframeHandler", {
146157 __nodeState : function ( starting = true ) {
147158 // Check if study is still there
148159 if ( this . getStudy ( ) === null || this . __stopRequestingStatus === true ) {
160+ this . setPolling ( false ) ;
149161 return ;
150162 }
151163 // Check if node is still there
152164 if ( this . getStudy ( ) . getWorkbench ( ) . getNode ( this . getNode ( ) . getNodeId ( ) ) === null ) {
165+ this . setPolling ( false ) ;
153166 return ;
154167 }
155168
@@ -176,6 +189,7 @@ qx.Class.define("osparc.data.model.IframeHandler", {
176189 } ;
177190 node . fireDataEvent ( "showInLogger" , errorMsgData ) ;
178191 if ( "status" in err && err . status === 406 ) {
192+ this . setPolling ( false ) ;
179193 return ;
180194 }
181195 if ( this . __unresponsiveRetries > 0 ) {
@@ -190,6 +204,7 @@ qx.Class.define("osparc.data.model.IframeHandler", {
190204 const interval = Math . floor ( Math . random ( ) * 5000 ) + 3000 ;
191205 setTimeout ( ( ) => this . __nodeState ( ) , interval ) ;
192206 } else {
207+ this . setPolling ( false ) ;
193208 node . getStatus ( ) . setInteractive ( "failed" ) ;
194209 osparc . FlashMessenger . getInstance ( ) . logAs ( this . tr ( "There was an error starting" ) + " " + node . getLabel ( ) , "ERROR" ) ;
195210 }
@@ -201,14 +216,17 @@ qx.Class.define("osparc.data.model.IframeHandler", {
201216 const nodeId = data [ "service_uuid" ] ;
202217 const node = this . getNode ( ) ;
203218 const status = node . getStatus ( ) ;
219+ let nextPollIn = null ;
220+ let pollingInNextStage = null ;
204221 switch ( serviceState ) {
205222 case "idle" : {
206223 status . setInteractive ( serviceState ) ;
207224 if ( starting && this . __unresponsiveRetries > 0 ) {
208225 // a bit of a hack. We will get rid of it when the backend pushes the states
209226 this . __unresponsiveRetries -- ;
210- const interval = 2000 ;
211- qx . event . Timer . once ( ( ) => this . __nodeState ( starting ) , this , interval ) ;
227+ nextPollIn = 2000 ;
228+ } else {
229+ this . setPolling ( false ) ;
212230 }
213231 break ;
214232 }
@@ -228,27 +246,24 @@ qx.Class.define("osparc.data.model.IframeHandler", {
228246 node . fireDataEvent ( "showInLogger" , msgData ) ;
229247 }
230248 status . setInteractive ( serviceState ) ;
231- const interval = 10000 ;
232- qx . event . Timer . once ( ( ) => this . __nodeState ( starting ) , this , interval ) ;
249+ nextPollIn = 10000 ;
233250 break ;
234251 }
235252 case "stopping" :
236253 case "unknown" :
237254 case "starting" :
238255 case "pulling" : {
239256 status . setInteractive ( serviceState ) ;
240- const interval = 5000 ;
241- qx . event . Timer . once ( ( ) => this . __nodeState ( starting ) , this , interval ) ;
257+ nextPollIn = 5000 ;
242258 break ;
243259 }
244260 case "running" : {
245261 if ( nodeId !== node . getNodeId ( ) ) {
246- return ;
262+ break ;
247263 }
248264 if ( ! starting ) {
249265 status . setInteractive ( "stopping" ) ;
250- const interval = 5000 ;
251- qx . event . Timer . once ( ( ) => this . __nodeState ( starting ) , this , interval ) ;
266+ nextPollIn = 5000 ;
252267 break ;
253268 }
254269 const {
@@ -260,6 +275,7 @@ qx.Class.define("osparc.data.model.IframeHandler", {
260275 this . __retriesLeft = 40 ;
261276 this . __waitForServiceReady ( srvUrl ) ;
262277 }
278+ pollingInNextStage = true ;
263279 break ;
264280 }
265281 case "complete" :
@@ -279,12 +295,18 @@ qx.Class.define("osparc.data.model.IframeHandler", {
279295 console . error ( serviceState , "service state not supported" ) ;
280296 break ;
281297 }
298+ if ( nextPollIn ) {
299+ qx . event . Timer . once ( ( ) => this . __nodeState ( starting ) , this , nextPollIn ) ;
300+ } else if ( pollingInNextStage !== true ) {
301+ this . setPolling ( false ) ;
302+ }
282303 } ,
283304
284305 __waitForServiceReady : function ( srvUrl ) {
285306 this . getNode ( ) . getStatus ( ) . setInteractive ( "connecting" ) ;
286307
287308 if ( this . __retriesLeft === 0 ) {
309+ this . setPolling ( false ) ;
288310 return ;
289311 }
290312
@@ -293,6 +315,7 @@ qx.Class.define("osparc.data.model.IframeHandler", {
293315
294316 // Check if node is still there
295317 if ( this . getStudy ( ) . getWorkbench ( ) . getNode ( this . getNode ( ) . getNodeId ( ) ) === null ) {
318+ this . setPolling ( false ) ;
296319 return ;
297320 }
298321 const interval = 5000 ;
@@ -310,6 +333,7 @@ qx.Class.define("osparc.data.model.IframeHandler", {
310333 console . log ( "Connecting: fetch's response status" , response . status ) ;
311334 }
312335 if ( response . status < 400 ) {
336+ this . setPolling ( false ) ;
313337 this . __serviceReadyIn ( srvUrl ) ;
314338 } else {
315339 console . log ( `Connecting: ${ srvUrl } is not reachable. Status: ${ response . status } ` ) ;
0 commit comments