@@ -309,13 +309,13 @@ func (m *RpcServer) doNewEnvironmentAsync(cxt context.Context, userVars map[stri
309309 // we store the last known request user in the environment
310310 lastRequestUserJ , _ := json .Marshal (requestUser )
311311 userVars ["last_request_user" ] = string (lastRequestUserJ [:])
312- id , err = m .state .environments .CreateEnvironment (workflowTemplate , userVars , public , id , autoTransition )
312+ err = m .state .environments .RunEnvironment (workflowTemplate , id , autoTransition )
313313 if err != nil {
314314 the .EventWriterWithTopic (topic .Environment ).WriteEvent (& evpb.Ev_EnvironmentEvent {
315315 EnvironmentId : id .String (),
316316 State : "ERROR" ,
317317 Error : err .Error (),
318- Message : "cannot create new environment" , // GUI listens for this concrete string
318+ Message : "cannot run new environment" , // GUI listens for this concrete string
319319 LastRequestUser : requestUser ,
320320 WorkflowTemplateInfo : & evpb.WorkflowTemplateInfo {
321321 Public : public ,
@@ -374,7 +374,26 @@ func (m *RpcServer) NewEnvironmentAsync(cxt context.Context, request *pb.NewEnvi
374374 }
375375 defer setCurrentUnixMilli (& reply .Timestamp )
376376
377- go m .doNewEnvironmentAsync (cxt , userVars , request .GetRequestUser (), request .GetWorkflowTemplate (), request .GetPublic (), request .GetAutoTransition (), id )
377+ public := request .GetPublic ()
378+ workflowTemplate := request .GetWorkflowTemplate ()
379+ requestUser := request .GetRequestUser ()
380+
381+ id , err = m .state .environments .CreateEnvironment (request .GetWorkflowTemplate (), userVars , request .GetPublic (), id )
382+ if err != nil {
383+ the .EventWriterWithTopic (topic .Environment ).WriteEvent (& evpb.Ev_EnvironmentEvent {
384+ EnvironmentId : id .String (),
385+ State : "ERROR" ,
386+ Error : err .Error (),
387+ Message : "cannot create new environment" , // GUI listens for this concrete string
388+ LastRequestUser : requestUser ,
389+ WorkflowTemplateInfo : & evpb.WorkflowTemplateInfo {
390+ Public : public ,
391+ Path : workflowTemplate ,
392+ },
393+ })
394+ return
395+ }
396+ go m .doNewEnvironmentAsync (cxt , userVars , requestUser , workflowTemplate , public , request .GetAutoTransition (), id )
378397
379398 return
380399}
@@ -421,7 +440,7 @@ func (m *RpcServer) NewEnvironment(cxt context.Context, request *pb.NewEnvironme
421440
422441 // Create new Environment instance with some roles, we get back a UUID
423442 id := uid .New ()
424- id , err = m .state .environments .CreateEnvironment (request .GetWorkflowTemplate (), inputUserVars , request .GetPublic (), id , request . GetAutoTransition () )
443+ id , err = m .state .environments .CreateEnvironment (request .GetWorkflowTemplate (), inputUserVars , request .GetPublic (), id )
425444 if err != nil {
426445 st := status .Newf (codes .Internal , "cannot create new environment: %s" , utils .TruncateString (err .Error (), MAX_ERROR_LENGTH ))
427446 ei := & pb.EnvironmentInfo {
@@ -436,6 +455,20 @@ func (m *RpcServer) NewEnvironment(cxt context.Context, request *pb.NewEnvironme
436455 return
437456 }
438457
458+ err = m .state .environments .RunEnvironment (request .GetWorkflowTemplate (), id , request .GetAutoTransition ())
459+ if err != nil {
460+ st := status .Newf (codes .Internal , "cannot run new environment: %s" , utils .TruncateString (err .Error (), MAX_ERROR_LENGTH ))
461+ ei := & pb.EnvironmentInfo {
462+ Id : id .String (),
463+ CreatedWhen : time .Now ().UnixMilli (),
464+ State : "ERROR" , // not really, but close
465+ NumberOfFlps : 0 ,
466+ }
467+ st , _ = st .WithDetails (ei )
468+ err = st .Err ()
469+
470+ return
471+ }
439472 newEnv , err := m .state .environments .Environment (id )
440473 if err != nil {
441474 st := status .Newf (codes .Internal , "cannot get newly created environment: %s" , utils .TruncateString (err .Error (), MAX_ERROR_LENGTH ))
0 commit comments