@@ -252,6 +252,7 @@ export default {
252252 " filter" ,
253253 " permission" ,
254254 " script_microservice_enabled" ,
255+ " script_microservice_tenant_id" ,
255256 ],
256257 data () {
257258 return {
@@ -271,7 +272,8 @@ export default {
271272 exitCode: 0 ,
272273 showDockerfile: false ,
273274 loading: true ,
274- script_microservice_broadcast_uui: null ,
275+ activeBuildUuid: null ,
276+ pendingBuildEvents: [],
275277
276278 localLoadOnStart: true ,
277279 orderBy: " language" ,
@@ -356,16 +358,15 @@ export default {
356358 }
357359 );
358360 }
361+
362+ if (this .script_microservice_enabled && this .script_microservice_tenant_id ) {
363+ this .subscribeToTenantBuildChannel ();
364+ }
359365 },
360366 watch: {
361367 commandOutput () {
362368 this .scrollToBottom ();
363369 },
364- script_microservice_broadcast_uui (newVal ) {
365- if (newVal) {
366- this .subscribeToScriptMicroserviceChannel (newVal);
367- }
368- },
369370 },
370371 computed: {
371372 modalTitle () {
@@ -434,7 +435,13 @@ export default {
434435 },
435436 setErrors (errors ) {
436437 this .status = " error" ;
437- this .errors = errors .response .data .errors ;
438+ this .errors = _ .get (errors, " response.data.errors" , {});
439+ const messages = Object .values (this .errors )
440+ .flat ()
441+ .filter ((message ) => typeof message === " string" && message !== " " );
442+ if (messages .length ) {
443+ this .output (messages .join (" \n " ) + " \n " );
444+ }
438445 },
439446 doNotHideIfRunning (e ) {
440447 if (this .isRunning ) {
@@ -472,13 +479,15 @@ export default {
472479 save () {
473480 this .resetProcessInfo ();
474481 this .status = " saving" ;
482+ this .activeBuildUuid = this .formData .uuid || null ;
483+ this .pendingBuildEvents = [];
475484 if (this .formData .id ) {
476485 const path = " /script-executors/" + this .formData .id ;
477486 ProcessMaker .apiClient
478487 .put (path, this .formData )
479488 .then ((result ) => {
480489 this .status = _ .get (result, " data.status" , " error" );
481- this .script_microservice_broadcast_uui = result . data .uuid ;
490+ this .setActiveBuildUuid ( _ . get (result, " data.uuid " , this . formData .uuid )) ;
482491 })
483492 .catch ((e ) => {
484493 this .setErrors (e);
@@ -489,9 +498,10 @@ export default {
489498 .post (path, this .formData )
490499 .then ((result ) => {
491500 this .status = _ .get (result, " data.status" , " error" );
492- this .script_microservice_broadcast_uui = result . data .uuid ;
501+ this .setActiveBuildUuid ( _ . get (result, " data.uuid" )) ;
493502 if (this .status === " started" ) {
494503 this .formData .id = result .data .id ;
504+ this .formData .uuid = result .data .uuid ;
495505 this .fetch (); // refresh the table (beneath the modal)
496506 }
497507 })
@@ -505,13 +515,17 @@ export default {
505515 },
506516 edit (row ) {
507517 this .formData = _ .cloneDeep (row);
518+ this .activeBuildUuid = row .uuid || null ;
508519 this .$refs .edit .show ();
509520 },
510521 reset () {
511522 this .formData = _ .cloneDeep (this .emptyFormData );
512523 this .errors = {};
513524 this .showDockerfile = false ;
514- (this .status = " idle" ), this .resetProcessInfo ();
525+ this .status = " idle" ;
526+ this .activeBuildUuid = null ;
527+ this .pendingBuildEvents = [];
528+ this .resetProcessInfo ();
515529 },
516530 resetProcessInfo () {
517531 this .commandOutput = " " ;
@@ -550,31 +564,72 @@ export default {
550564 onAddToBundle (data ) {
551565 this .$root .$emit (' add-to-bundle' , data);
552566 },
553- subscribeToScriptMicroserviceChannel (name ) {
554- const channel = ` build-image-${ name} ` ;
555- if (this .script_microservice_enabled ) {
556- // Subscribe to new channel
557- window .ScriptMicroserviceEcho
558- .channel (channel)
559- .listenToAll ((eventName , data ) => {
560- this .status = this .status === " idle" ? " starting" : this .status ;
561- switch (eventName) {
562- case " .build-image" :
563- this .output (` ${ data} \n ` );
564- break ;
565- case " .build-finished" :
566- this .pidFile = null ;
567- this .exitCode = 0 ;
568- this .status = " done" ;
569- break ;
570- case " .build-error" :
571- this .output (data);
572- this .pidFile = null ;
573- this .exitCode = 1 ;
574- this .status = " done" ;
575- break ;
576- }
577- });
567+ subscribeToTenantBuildChannel () {
568+ if (! window .ScriptMicroserviceEcho ) {
569+ return ;
570+ }
571+ const channel = ` tenant-${ this .script_microservice_tenant_id } -builds` ;
572+ window .ScriptMicroserviceEcho .channel (channel).listen (
573+ " .executor-build" ,
574+ (data ) => {
575+ this .handleExecutorBuildEvent (data);
576+ }
577+ );
578+ },
579+ setActiveBuildUuid (uuid ) {
580+ if (! uuid) {
581+ return ;
582+ }
583+ this .activeBuildUuid = uuid;
584+ const pending = this .pendingBuildEvents .filter (
585+ (event ) => event .executor_id === uuid
586+ );
587+ this .pendingBuildEvents = [];
588+ pending .forEach ((event ) => this .applyExecutorBuildEvent (event ));
589+ },
590+ handleExecutorBuildEvent (data ) {
591+ if (! data || typeof data !== " object" ) {
592+ return ;
593+ }
594+ if (! this .isRunning ) {
595+ return ;
596+ }
597+ if (! this .activeBuildUuid ) {
598+ this .pendingBuildEvents .push (data);
599+ return ;
600+ }
601+ if (data .executor_id !== this .activeBuildUuid ) {
602+ return ;
603+ }
604+ this .applyExecutorBuildEvent (data);
605+ },
606+ applyExecutorBuildEvent (data ) {
607+ if (this .status === " saving" ) {
608+ this .status = " starting" ;
609+ } else if (this .status === " idle" ) {
610+ this .status = " starting" ;
611+ }
612+
613+ if (data .type === " status" ) {
614+ this .output (` [${ data .phase } ] ${ data .message || " " } \n ` );
615+ } else if (data .message ) {
616+ const message = data .message .endsWith (" \n " )
617+ ? data .message
618+ : ` ${ data .message } \n ` ;
619+ this .output (message);
620+ }
621+
622+ if (data .phase === " completed" && data .type === " status" ) {
623+ this .pidFile = null ;
624+ this .exitCode = 0 ;
625+ this .status = " done" ;
626+ return ;
627+ }
628+
629+ if (data .phase === " error" || data .type === " error" ) {
630+ this .pidFile = null ;
631+ this .exitCode = 1 ;
632+ this .status = " done" ;
578633 }
579634 },
580635 },
0 commit comments