Skip to content

Commit 7da3fc6

Browse files
committed
small changes to the session manager
1 parent 2b5c7fc commit 7da3fc6

File tree

4 files changed

+18
-18
lines changed

4 files changed

+18
-18
lines changed

engine/api/graphql/server/schema.resolvers.go

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

engine/sessions/manager.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ package sessions
1212
*/
1313

1414
import (
15+
"errors"
1516
"fmt"
1617
"log/slog"
1718
"os"
@@ -39,31 +40,30 @@ func NewManager(l *slog.Logger) et.SessionManager {
3940

4041
func (r *manager) NewSession(cfg *config.Config) (et.Session, error) {
4142
s, err := CreateSession(cfg)
42-
if err != nil {
43-
return nil, err
44-
}
45-
if _, err = r.AddSession(s); err != nil {
46-
return nil, err
43+
if err == nil {
44+
err = r.AddSession(s)
45+
46+
if err == nil {
47+
return s, nil
48+
}
4749
}
48-
return s, nil
50+
return nil, err
4951
}
5052

5153
// Add: adds a session to a session storage after checking the session config.
52-
func (r *manager) AddSession(s et.Session) (uuid.UUID, error) {
54+
func (r *manager) AddSession(s et.Session) error {
5355
if s == nil {
54-
return uuid.UUID{}, nil
56+
return errors.New("the provided session is nil")
5557
}
5658

5759
r.Lock()
58-
defer r.Unlock()
59-
60-
var id uuid.UUID
6160
if sess, ok := s.(*Session); ok {
62-
id = sess.id
63-
r.sessions[id] = sess
61+
r.sessions[sess.id] = sess
6462
}
63+
r.Unlock()
64+
6565
// TODO: Need to add the session config checks here (using the Registry)
66-
return id, nil
66+
return nil
6767
}
6868

6969
// CancelSession: cancels a session in a session storage.

engine/sessions/manager_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ func TestAddSession(t *testing.T) {
2424
done: make(chan struct{}),
2525
}
2626

27-
if _, err := mgr.AddSession(s); err != nil {
27+
if err := mgr.AddSession(s); err != nil {
2828
t.Error(err)
2929
}
3030
}

engine/types/sessions.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ type SessionStats struct {
4040

4141
type SessionManager interface {
4242
NewSession(cfg *config.Config) (Session, error)
43-
AddSession(s Session) (uuid.UUID, error)
43+
AddSession(s Session) error
4444
CancelSession(id uuid.UUID)
4545
GetSession(id uuid.UUID) Session
4646
Shutdown()

0 commit comments

Comments
 (0)