Skip to content
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

fix: always fetch current resource state #41

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
40 changes: 15 additions & 25 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,17 +268,15 @@ func (c *Client) CreateDatabase(ctx context.Context, database *models.CreateData
return nil, handleAPIError(err)
}

err = c.PollTaskStatus(ctx, TaskPollingConfig{
taskErr := c.PollTaskStatus(ctx, TaskPollingConfig{
SubjectID: resp.Payload.ID.String(),
SubjectKind: "database",
MaxAttempts: 360, // 30 minutes
Interval: 5 * time.Second,
})
if err != nil {
return resp.Payload, err
}
currentState, getErr := c.GetDatabase(ctx, *resp.Payload.ID)

return c.GetDatabase(ctx, *resp.Payload.ID)
return currentState, errors.Join(taskErr, getErr)
}

func (c *Client) GetDatabase(ctx context.Context, id strfmt.UUID) (*models.Database, error) {
Expand Down Expand Up @@ -313,17 +311,15 @@ func (c *Client) UpdateDatabase(ctx context.Context, id strfmt.UUID, body *model
return nil, handleAPIError(err)
}

err = c.PollTaskStatus(ctx, TaskPollingConfig{
taskErr := c.PollTaskStatus(ctx, TaskPollingConfig{
SubjectID: resp.Payload.ID.String(),
SubjectKind: "database",
MaxAttempts: 360, // 30 minutes
Interval: 5 * time.Second,
})
if err != nil {
return nil, err
}
currentState, getErr := c.GetDatabase(ctx, id)

return c.GetDatabase(ctx, id)
return currentState, errors.Join(taskErr, getErr)
}

func (c *Client) DeleteDatabase(ctx context.Context, id strfmt.UUID) error {
Expand Down Expand Up @@ -397,17 +393,15 @@ func (c *Client) CreateCluster(ctx context.Context, cluster *models.CreateCluste
return nil, handleAPIError(err)
}

err = c.PollTaskStatus(ctx, TaskPollingConfig{
taskErr := c.PollTaskStatus(ctx, TaskPollingConfig{
SubjectID: resp.Payload.ID.String(),
SubjectKind: "cluster",
MaxAttempts: 540, // 45 minutes
Interval: 5 * time.Second,
})
if err != nil {
return resp.Payload, err
}
currentState, getErr := c.GetCluster(ctx, *resp.Payload.ID)

return c.GetCluster(ctx, *resp.Payload.ID)
return currentState, errors.Join(taskErr, getErr)
}

func (c *Client) UpdateCluster(ctx context.Context, id strfmt.UUID, body *models.UpdateClusterInput) (*models.Cluster, error) {
Expand All @@ -425,17 +419,15 @@ func (c *Client) UpdateCluster(ctx context.Context, id strfmt.UUID, body *models
return nil, handleAPIError(err)
}

err = c.PollTaskStatus(ctx, TaskPollingConfig{
taskErr := c.PollTaskStatus(ctx, TaskPollingConfig{
SubjectID: resp.Payload.ID.String(),
SubjectKind: "cluster",
MaxAttempts: 540, // 45 minutes
Interval: 5 * time.Second,
})
if err != nil {
return nil, err
}
currentState, getErr := c.GetCluster(ctx, strfmt.UUID(*resp.Payload.ID))

return c.GetCluster(ctx, strfmt.UUID(*resp.Payload.ID))
return currentState, errors.Join(taskErr, getErr)
}

func (c *Client) DeleteCluster(ctx context.Context, id strfmt.UUID) error {
Expand Down Expand Up @@ -680,17 +672,15 @@ func (c *Client) CreateBackupStore(ctx context.Context, input *models.CreateBack
return nil, fmt.Errorf("received nil response or payload")
}

err = c.PollTaskStatus(ctx, TaskPollingConfig{
taskErr := c.PollTaskStatus(ctx, TaskPollingConfig{
SubjectID: resp.Payload.ID.String(),
SubjectKind: "backup_store",
MaxAttempts: 360, // 30 minutes
Interval: 5 * time.Second,
})
if err != nil {
return resp.Payload, err
}
currentState, getErr := c.GetBackupStore(ctx, *resp.Payload.ID)

return c.GetBackupStore(ctx, *resp.Payload.ID)
return currentState, errors.Join(taskErr, getErr)
}

func (c *Client) GetBackupStore(ctx context.Context, id strfmt.UUID) (*models.BackupStore, error) {
Expand Down