Skip to content

refac(opensearch): Use new WaitHelper for waiters#7323

Open
Fyusel wants to merge 1 commit into
mainfrom
refac-opensearch-wait-handler
Open

refac(opensearch): Use new WaitHelper for waiters#7323
Fyusel wants to merge 1 commit into
mainfrom
refac-opensearch-wait-handler

Conversation

@Fyusel
Copy link
Copy Markdown
Contributor

@Fyusel Fyusel commented May 19, 2026

STACKITSDK-385

Description

Checklist

  • Issue was linked above
  • No generated code was adjusted manually (check comments in file header)
  • Changelogs
    • Changelog in the root directory was adjusted (see here)
    • Changelog(s) of the service(s) were adjusted (see e.g. here)
  • VERSION file(s) of the service(s) were adjusted
  • Code format was applied: make fmt
  • Examples were added / adjusted (see examples/ directory)
  • Unit tests got implemented or updated
  • Unit tests are passing: make test (will be checked by CI)
  • No linter issues: make lint (will be checked by CI)

@Fyusel Fyusel requested a review from a team as a code owner May 19, 2026 11:11
STACKITSDK-385

Signed-off-by: Alexander Dahmen <alexander.dahmen@inovex.de>
@Fyusel Fyusel force-pushed the refac-opensearch-wait-handler branch from 7985eea to d1f8909 Compare May 19, 2026 11:11
@@ -27,44 +28,44 @@ const (

// CreateInstanceWaitHandler will wait for instance creation
func CreateInstanceWaitHandler(ctx context.Context, a opensearch.DefaultAPI, projectId, instanceId string) *wait.AsyncActionHandler[opensearch.Instance] {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could be half the code 😉

// note the private visibility for the shared logic
func createOrUpdateInstanceWaitHandler(ctx context.Context, a opensearch.DefaultAPI, projectId, instanceId string) *wait.AsyncActionHandler[opensearch.Instance] {
	waitConfig := wait.WaiterHelper[opensearch.Instance, string]{
		FetchInstance: a.GetInstance(ctx, projectId, instanceId).Execute,
		GetState: func(s *opensearch.Instance) (string, error) {
			if s == nil {
				return "", errors.New("empty response")
			}
			if s.Status == nil {
				return "", errors.New("status is missing")
			}
			return *s.Status, nil
		},
		ActiveState: []string{INSTANCESTATUS_ACTIVE},
		ErrorState:  []string{INSTANCESTATUS_FAILED},
	}

	handler := wait.New(waitConfig.Wait())
	handler.SetTimeout(45 * time.Minute)
	return handler
}

func CreateInstanceWaitHandler(ctx context.Context, a opensearch.DefaultAPI, projectId, instanceId string) *wait.AsyncActionHandler[opensearch.Instance] {
    return createOrUpdateInstanceWaitHandler(...)
}

func PartialUpdateInstanceWaitHandler(ctx context.Context, a opensearch.DefaultAPI, projectId, instanceId string) *wait.AsyncActionHandler[opensearch.Instance] {
    return createOrUpdateInstanceWaitHandler(...)
}

You can then also use the test construct I've shown @GokceGK here to test all 3 implementations using the same logic:

#7163 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants