@@ -32,7 +32,7 @@ export class workflow_in_node {
3232 WebSocketClient . instance . events . on ( "onclose" , ( message ) => {
3333 if ( message == null ) message = "" ;
3434 this . node . status ( { fill : "red" , shape : "dot" , text : "Disconnected " + message } ) ;
35- this . onclose ( ) ;
35+ this . onclose ( false , null ) ;
3636 } ) ;
3737 this . connect ( ) ;
3838 } catch ( error ) {
@@ -251,11 +251,22 @@ export class workflow_in_node {
251251 }
252252 }
253253 }
254- onclose ( ) {
255- if ( ! NoderedUtil . IsNullEmpty ( this . localqueue ) ) {
254+ async onclose ( removed : boolean , done : any ) {
255+ if ( ! NoderedUtil . IsNullEmpty ( this . localqueue ) && removed ) {
256256 NoderedUtil . CloseQueue ( WebSocketClient . instance , this . localqueue ) ;
257257 this . localqueue = "" ;
258258 }
259+ if ( removed && Config . workflow_node_auto_cleanup ) {
260+ let res = await NoderedUtil . Query ( "workflow" , { "queue" : this . localqueue } , null , null , 1 , 0 , null ) ;
261+ if ( res . length > 0 ) {
262+ await NoderedUtil . DeleteOne ( "workflow" , res [ 0 ] . _id , null ) ;
263+ }
264+ res = await NoderedUtil . Query ( "users" , { "_type" : "role" , "$or" : [ { "workflowid" : this . workflow . _id } , { "name" : this . localqueue + "users" } ] } , null , null , 1 , 0 , null ) ;
265+ if ( res . length > 0 ) {
266+ await NoderedUtil . DeleteOne ( "workflow" , res [ 0 ] . _id , null ) ;
267+ }
268+ }
269+ if ( done != null ) done ( ) ;
259270 }
260271}
261272
@@ -452,7 +463,7 @@ export class assign_workflow_node {
452463 WebSocketClient . instance . events . on ( "onclose" , ( message ) => {
453464 if ( message == null ) message = "" ;
454465 this . node . status ( { fill : "red" , shape : "dot" , text : "Disconnected " + message } ) ;
455- this . onclose ( ) ;
466+ this . onclose ( false , null ) ;
456467 } ) ;
457468 this . connect ( ) ;
458469 }
@@ -598,10 +609,11 @@ export class assign_workflow_node {
598609 NoderedUtil . HandleError ( this , error ) ;
599610 }
600611 }
601- onclose ( ) {
602- if ( ! NoderedUtil . IsNullEmpty ( this . localqueue ) ) {
612+ async onclose ( removed : boolean , done : any ) {
613+ if ( ! NoderedUtil . IsNullEmpty ( this . localqueue ) && removed ) {
603614 NoderedUtil . CloseQueue ( WebSocketClient . instance , this . localqueue ) ;
604615 this . localqueue = "" ;
605616 }
617+ if ( done != null ) done ( ) ;
606618 }
607619}
0 commit comments