Skip to content

Commit 9c477b7

Browse files
committed
[core] Harmonize environment_id setting between regular and AUTO env
1 parent 090a3e3 commit 9c477b7

1 file changed

Lines changed: 24 additions & 7 deletions

File tree

core/environment/manager.go

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -145,15 +145,16 @@ func (envs *Manager) CreateEnvironment(workflowPath string, userVars map[string]
145145
newEnvId := uid.NilID()
146146
if err == nil && env != nil {
147147
newEnvId = env.Id()
148+
} else {
149+
log.WithError(err).Logf(logrus.FatalLevel, "environment creation failed")
150+
return newEnvId, err
148151
}
152+
149153
log.WithFields(logrus.Fields{
150154
"workflow": workflowPath,
151155
"partition": newEnvId.String(),
152156
}).Info("creating new environment")
153157

154-
if err != nil {
155-
return uid.NilID(), err
156-
}
157158
env.hookHandlerF = func(hooks task.Tasks) error {
158159
return envs.taskman.TriggerHooks(hooks)
159160
}
@@ -544,21 +545,37 @@ func (envs *Manager) CreateAutoEnvironment(workflowPath string, userVars map[str
544545
newEnvId := uid.NilID()
545546
if err == nil && env != nil {
546547
newEnvId = env.Id()
548+
} else {
549+
log.WithError(err).Logf(logrus.FatalLevel, "environment creation failed")
550+
env.sendEnvironmentEvent(&event.EnvironmentEvent{EnvironmentID: newEnvId.String(), Error: err})
551+
return
547552
}
553+
548554
log.WithFields(logrus.Fields{
549555
"workflow": workflowPath,
550556
"partition": newEnvId.String(),
551557
}).Info("creating new automatic environment")
552558

553-
if err != nil {
554-
env.sendEnvironmentEvent(&event.EnvironmentEvent{EnvironmentID: env.Id().String(), Error: err})
555-
return
556-
}
557559
env.addSubscription(sub)
558560
defer env.closeStream()
561+
559562
env.hookHandlerF = func(hooks task.Tasks) error {
560563
return envs.taskman.TriggerHooks(hooks)
561564
}
565+
566+
// Ensure the environment_id is available to all
567+
env.UserVars.Set("environment_id", env.id.String())
568+
569+
// in case of err==nil, env will be false unless user
570+
// set it to True which will be overwriten in server.go
571+
env.Public, err = parseWorkflowPublicInfo(workflowPath)
572+
if err != nil {
573+
log.WithField("public info", env.Public).
574+
WithField("environment", env.Id().String()).
575+
WithError(err).
576+
Warn("parse workflow public info failed.")
577+
}
578+
562579
env.workflow, err = envs.loadWorkflow(workflowPath, env.wfAdapter, workflowUserVars)
563580
if err != nil {
564581
err = fmt.Errorf("cannot load workflow template: %w", err)

0 commit comments

Comments
 (0)