Skip to content

Commit 1767c3b

Browse files
committed
Merge branch '144-clone-connection' into 'master'
# Description (#144) * use Database Lab client host after clone creation in case the `localhost` is given as `accessHost` in the Database Lab config. * process connection errors properly: send message as well, not only to logs See merge request postgres-ai/joe!117
2 parents 777b1bd + 015e1da commit 1767c3b

File tree

2 files changed

+19
-9
lines changed

2 files changed

+19
-9
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ To discuss Joe, [join our community Slack](https://database-lab-team-slack-invit
2727
### 1. Database Lab
2828
Install and setup [Database Lab](https://gitlab.com/postgres-ai/database-lab)
2929

30-
Prepare one or more Database Lab instances before configuring Joe bot.
30+
Prepare one or more Database Lab instances before configuring Joe bot.
31+
32+
> ⚠ Make sure that `accessHost` is specified in the Database Lab configuration file.
3133
3234
Then, configure ways of communication with Joe.
3335

pkg/services/msgproc/dblab.go

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ var hintExplainDmlWords = []string{"insert", "select", "update", "delete", "with
7878
var hintExecDdlWords = []string{"alter", "create", "drop", "set"}
7979

8080
// runSession starts a user session if not exists.
81-
func (s *ProcessingService) runSession(ctx context.Context, user *usermanager.User, incomingMessage models.IncomingMessage) error {
81+
func (s *ProcessingService) runSession(ctx context.Context, user *usermanager.User, incomingMessage models.IncomingMessage) (err error) {
8282
sMsg := models.NewMessage(incomingMessage)
8383

8484
if user.Session.Clone != nil {
@@ -104,11 +104,17 @@ func (s *ProcessingService) runSession(ctx context.Context, user *usermanager.Us
104104

105105
user.Session.PlatformSessionID = sessionID
106106

107+
defer func() {
108+
if err != nil {
109+
if failErr := s.messenger.Fail(sMsg, err.Error()); failErr != nil {
110+
log.Err(failErr)
111+
}
112+
}
113+
}()
114+
107115
clone, err := s.createDBLabClone(ctx, user, sessionID)
108116
if err != nil {
109-
s.messenger.Fail(sMsg, err.Error())
110-
111-
return err
117+
return errors.Wrap(err, "failed to create a Database Lab clone")
112118
}
113119

114120
sMsg.AppendText(
@@ -120,7 +126,6 @@ func (s *ProcessingService) runSession(ctx context.Context, user *usermanager.Us
120126
))
121127

122128
if err := s.messenger.UpdateText(sMsg); err != nil {
123-
s.messenger.Fail(sMsg, err.Error())
124129
return errors.Wrap(err, "failed to append message with a foreword")
125130
}
126131

@@ -142,15 +147,13 @@ func (s *ProcessingService) runSession(ctx context.Context, user *usermanager.Us
142147

143148
if s.config.Platform.HistoryEnabled && incomingMessage.SessionID == "" {
144149
if err := s.createPlatformSession(ctx, user, sMsg.ChannelID); err != nil {
145-
s.messenger.Fail(sMsg, err.Error())
146-
return err
150+
return errors.Wrap(err, "failed to create a platform session")
147151
}
148152
}
149153

150154
sMsg.AppendText(fmt.Sprintf("Session started: `%s`", sessionID))
151155

152156
if err := s.messenger.UpdateText(sMsg); err != nil {
153-
s.messenger.Fail(sMsg, err.Error())
154157
return errors.Wrap(err, "failed to append message about session start")
155158
}
156159

@@ -210,6 +213,11 @@ func (s *ProcessingService) createDBLabClone(ctx context.Context, user *usermana
210213

211214
clone.DB.Password = pwd
212215

216+
// To get an accessible address in case running the assistant inside a container.
217+
if clone.DB.Host == "localhost" || clone.DB.Host == "127.0.0.1" {
218+
clone.DB.Host = s.DBLab.URL("").Hostname()
219+
}
220+
213221
return clone, nil
214222
}
215223

0 commit comments

Comments
 (0)