From 6fb650e8eebe65932b76655fdc0b0c5db8fe04de Mon Sep 17 00:00:00 2001 From: lmasson Date: Fri, 29 Mar 2024 11:01:21 +0100 Subject: [PATCH 1/2] feat(llm-inference): add waiter support --- .../v1beta1/lm_inference_utils.go | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 api/llm_inference/v1beta1/lm_inference_utils.go diff --git a/api/llm_inference/v1beta1/lm_inference_utils.go b/api/llm_inference/v1beta1/lm_inference_utils.go new file mode 100644 index 000000000..66beae7a6 --- /dev/null +++ b/api/llm_inference/v1beta1/lm_inference_utils.go @@ -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 = 2 * time.Second + defaultTimeout = 5 * 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 +} From 486a788fc8be4247daba3c068a74b0c5895149b2 Mon Sep 17 00:00:00 2001 From: lmasson Date: Fri, 29 Mar 2024 11:30:45 +0100 Subject: [PATCH 2/2] fix ttl --- api/llm_inference/v1beta1/lm_inference_utils.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/api/llm_inference/v1beta1/lm_inference_utils.go b/api/llm_inference/v1beta1/lm_inference_utils.go index 66beae7a6..e747fcdd0 100644 --- a/api/llm_inference/v1beta1/lm_inference_utils.go +++ b/api/llm_inference/v1beta1/lm_inference_utils.go @@ -8,8 +8,8 @@ import ( ) const ( - defaultRetryInterval = 2 * time.Second - defaultTimeout = 5 * time.Minute + defaultRetryInterval = 15 * time.Second + defaultTimeout = 30 * time.Minute ) type WaitForDeploymentRequest struct {