Skip to content

feat(llm-inference): add waiter support #2032

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions api/llm_inference/v1beta1/lm_inference_utils.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package llm_inference

import (
"github.com/scaleway/scaleway-sdk-go/internal/errors"
"github.com/scaleway/scaleway-sdk-go/internal/async"
"time"
"github.com/scaleway/scaleway-sdk-go/scw"
)

const (
defaultRetryInterval = 15 * time.Second
defaultTimeout = 30 * time.Minute
)

type WaitForDeploymentRequest struct {
DeploymentId string
Region scw.Region
Status DeploymentStatus
Timeout *time.Duration
RetryInterval *time.Duration
}

func (s *API) WaitForDeployment(req *WaitForDeploymentRequest, opts ...scw.RequestOption) (*Deployment, error) {
timeout := defaultTimeout
if req.Timeout != nil {
timeout = *req.Timeout
}
retryInterval := defaultRetryInterval
if req.RetryInterval != nil {
retryInterval = *req.RetryInterval
}

terminalStatus := map[DeploymentStatus]struct{}{
DeploymentStatusReady: {},
DeploymentStatusError: {},
DeploymentStatusLocked: {},
}

deployment, err := async.WaitSync(&async.WaitSyncConfig{
Get: func() (interface{}, bool, error) {
deployment, err := s.GetDeployment(&GetDeploymentRequest{
Region: req.Region,
DeploymentID: req.DeploymentId,
}, opts...)
if err != nil {
return nil, false, err
}
_, isTerminal := terminalStatus[deployment.Status]
return deployment, isTerminal, nil
},
IntervalStrategy: async.LinearIntervalStrategy(retryInterval),
Timeout: timeout,
})
if err != nil {
return nil, errors.Wrap(err, "waiting for deployment failed")
}
return deployment.(*Deployment), nil
}