Switch to locking package

The locking logic was added to its own package as it may need to be used
by other parts of the code.

Signed-off-by: Gabriel Adrian Samfira <gsamfira@cloudbasesolutions.com>
This commit is contained in:
Gabriel Adrian Samfira 2025-04-07 16:45:05 +00:00
parent e51f19acc8
commit 5ba53adf84
6 changed files with 131 additions and 62 deletions

View file

@ -35,18 +35,6 @@ import (
const maxCapacityHeader = "X-ScaleSetMaxCapacity"
func NewMessageSession(ctx context.Context, cli *ScaleSetClient, session *params.RunnerScaleSetSession) (*MessageSession, error) {
sess := &MessageSession{
ssCli: cli,
session: session,
ctx: ctx,
done: make(chan struct{}),
closed: false,
}
go sess.loop()
return sess, nil
}
type MessageSession struct {
ssCli *ScaleSetClient
session *params.RunnerScaleSetSession
@ -243,10 +231,16 @@ func (s *ScaleSetClient) CreateMessageSession(ctx context.Context, runnerScaleSe
return nil, fmt.Errorf("failed to decode response: %w", err)
}
return &MessageSession{
sess := &MessageSession{
ssCli: s,
session: &createdSession,
}, nil
ctx: ctx,
done: make(chan struct{}),
closed: false,
}
go sess.loop()
return sess, nil
}
func (s *ScaleSetClient) DeleteMessageSession(ctx context.Context, session *MessageSession) error {