-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore/concurrency-limit-support (#360)
* Initial commit * Comment * Add client * Refactor * Rest of definition plus test * Docs * Add back images * Fix test * Fix test based on current usage * Update internal/provider/resources/concurrency_limit.go Co-authored-by: Mitchell Nielsen <[email protected]> * Update internal/provider/resources/concurrency_limit.go Co-authored-by: Mitchell Nielsen <[email protected]> * Update internal/provider/resources/concurrency_limit.go Co-authored-by: Mitchell Nielsen <[email protected]> * Update internal/provider/resources/concurrency_limit_test.go Co-authored-by: Mitchell Nielsen <[email protected]> * Update internal/provider/resources/concurrency_limit.go Co-authored-by: Mitchell Nielsen <[email protected]> * Update internal/client/concurrency_limits.go Co-authored-by: Mitchell Nielsen <[email protected]> * Generate Terraform Docs --------- Co-authored-by: Mitchell Nielsen <[email protected]> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
- Loading branch information
1 parent
d95dc3a
commit c2f14e1
Showing
8 changed files
with
484 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
--- | ||
# generated by https://github.com/hashicorp/terraform-plugin-docs | ||
page_title: "prefect_concurrency_limit Resource - prefect" | ||
subcategory: "" | ||
description: |- | ||
The resource concurrency_limit represents a concurrency limit. Concurrency limits allow you to manage execution efficiently, controlling how many tasks, flows, or other operations can run simultaneously. They are ideal for optimizing resource usage, preventing bottlenecks, and customizing task execution. | ||
--- | ||
|
||
# prefect_concurrency_limit (Resource) | ||
|
||
The resource `concurrency_limit` represents a concurrency limit. Concurrency limits allow you to manage execution efficiently, controlling how many tasks, flows, or other operations can run simultaneously. They are ideal for optimizing resource usage, preventing bottlenecks, and customizing task execution. | ||
|
||
|
||
|
||
<!-- schema generated by tfplugindocs --> | ||
## Schema | ||
|
||
### Required | ||
|
||
- `concurrency_limit` (Number) The concurrency limit. | ||
- `tag` (String) A tag the concurrency limit is applied to. | ||
|
||
### Optional | ||
|
||
- `account_id` (String) Account ID (UUID) | ||
- `workspace_id` (String) Workspace ID (UUID) | ||
|
||
### Read-Only | ||
|
||
- `created` (String) Timestamp of when the resource was created (RFC3339) | ||
- `id` (String) Concurrency limit ID (UUID) | ||
- `updated` (String) Timestamp of when the resource was updated (RFC3339) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package api | ||
|
||
import ( | ||
"context" | ||
) | ||
|
||
// ConcurrencyLimitsClient is a client for working with concurrency limits. | ||
type ConcurrencyLimitsClient interface { | ||
Create(ctx context.Context, concurrencyLimit ConcurrencyLimitCreate) (*ConcurrencyLimit, error) | ||
Read(ctx context.Context, concurrencyLimitID string) (*ConcurrencyLimit, error) | ||
Delete(ctx context.Context, concurrencyLimitID string) error | ||
} | ||
|
||
// ConcurrencyLimit is a representation of a concurrency limit. | ||
type ConcurrencyLimit struct { | ||
BaseModel | ||
Tag string `json:"tag"` | ||
ConcurrencyLimit int64 `json:"concurrency_limit"` | ||
} | ||
|
||
// ConcurrencyLimitCreate is a subset of ConcurrencyLimit used when creating concurrency limits. | ||
type ConcurrencyLimitCreate struct { | ||
Tag string `json:"tag"` | ||
ConcurrencyLimit int64 `json:"concurrency_limit"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
package client | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"net/http" | ||
|
||
"github.com/google/uuid" | ||
"github.com/prefecthq/terraform-provider-prefect/internal/api" | ||
) | ||
|
||
var _ = api.ConcurrencyLimitsClient(&ConcurrencyLimitsClient{}) | ||
|
||
// ConcurrencyLimitsClient is a client for working with concurrency limits. | ||
type ConcurrencyLimitsClient struct { | ||
hc *http.Client | ||
routePrefix string | ||
apiKey string | ||
} | ||
|
||
// ConcurrencyLimits returns a ConcurrencyLimitsClient. | ||
// | ||
//nolint:ireturn // required to support PrefectClient mocking | ||
func (c *Client) ConcurrencyLimits(accountID uuid.UUID, workspaceID uuid.UUID) (api.ConcurrencyLimitsClient, error) { | ||
if accountID == uuid.Nil { | ||
accountID = c.defaultAccountID | ||
} | ||
|
||
if workspaceID == uuid.Nil { | ||
workspaceID = c.defaultWorkspaceID | ||
} | ||
|
||
if err := validateCloudEndpoint(c.endpoint, accountID, workspaceID); err != nil { | ||
return nil, err | ||
} | ||
|
||
return &ConcurrencyLimitsClient{ | ||
hc: c.hc, | ||
routePrefix: getWorkspaceScopedURL(c.endpoint, accountID, workspaceID, "concurrency_limits"), | ||
apiKey: c.apiKey, | ||
}, nil | ||
} | ||
|
||
// Create creates a new concurrency limit. | ||
func (c *ConcurrencyLimitsClient) Create(ctx context.Context, data api.ConcurrencyLimitCreate) (*api.ConcurrencyLimit, error) { | ||
cfg := requestConfig{ | ||
method: http.MethodPost, | ||
url: c.routePrefix + "/", | ||
body: &data, | ||
apiKey: c.apiKey, | ||
successCodes: successCodesStatusOK, | ||
} | ||
|
||
var concurrencyLimit api.ConcurrencyLimit | ||
if err := requestWithDecodeResponse(ctx, c.hc, cfg, &concurrencyLimit); err != nil { | ||
return nil, fmt.Errorf("failed to create concurrency limit: %w", err) | ||
} | ||
|
||
return &concurrencyLimit, nil | ||
} | ||
|
||
// Read returns a concurrency limit. | ||
func (c *ConcurrencyLimitsClient) Read(ctx context.Context, concurrencyLimitID string) (*api.ConcurrencyLimit, error) { | ||
cfg := requestConfig{ | ||
method: http.MethodGet, | ||
url: fmt.Sprintf("%s/%s", c.routePrefix, concurrencyLimitID), | ||
apiKey: c.apiKey, | ||
successCodes: successCodesStatusOK, | ||
} | ||
|
||
var concurrencyLimit api.ConcurrencyLimit | ||
if err := requestWithDecodeResponse(ctx, c.hc, cfg, &concurrencyLimit); err != nil { | ||
return nil, fmt.Errorf("failed to get concurrency limit: %w", err) | ||
} | ||
|
||
return &concurrencyLimit, nil | ||
} | ||
|
||
// Delete deletes a concurrency limit. | ||
func (c *ConcurrencyLimitsClient) Delete(ctx context.Context, concurrencyLimitID string) error { | ||
cfg := requestConfig{ | ||
method: http.MethodDelete, | ||
url: fmt.Sprintf("%s/%s", c.routePrefix, concurrencyLimitID), | ||
apiKey: c.apiKey, | ||
successCodes: successCodesStatusOK, | ||
} | ||
|
||
resp, err := request(ctx, c.hc, cfg) | ||
if err != nil { | ||
return fmt.Errorf("failed to delete concurrency limit: %w", err) | ||
} | ||
defer resp.Body.Close() | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.