Files
orbit/sdk/go/application_resources.go

56 lines
2.7 KiB
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package orbit
import "context"
// ApplicationResources 是当前应用下所有命名空间共享的配置与用量快照。
// 配置变更需要应用级权限;修改计数不会增加 Revision。
type ApplicationResources struct {
// ApplicationID 所属应用标识,由凭据归属确定。
ApplicationID string `json:"application_id"`
// Revision 仅配置变更增加的版本;JSON 使用十进制字符串。
Revision uint64 `json:"revision,string"`
// MaxUnfinishedTasks 跨命名空间的未终结任务上限,包含待核查任务。
MaxUnfinishedTasks uint32 `json:"max_unfinished_tasks"`
// UnfinishedTasks 当前未终结任务总数;自动重试不重复占用。
UnfinishedTasks uint64 `json:"unfinished_tasks,string"`
// MaxConcurrency 跨队列的预占及运行尝试总上限。
MaxConcurrency uint32 `json:"max_concurrency"`
// ActiveAttempts 当前预占与运行的尝试数。
ActiveAttempts uint64 `json:"active_attempts,string"`
// PendingStarts 已预占但尚未开始的尝试数,属于 ActiveAttempts。
PendingStarts uint64 `json:"pending_starts,string"`
// RatePerSecond 每秒固定窗口允许的开始授权次数。
RatePerSecond uint32 `json:"rate_per_second"`
}
// ConfigureApplicationResourcesRequest 完整替换上限,重复请求必须保留原版本与幂等键。
type ConfigureApplicationResourcesRequest struct {
// ExpectedRevision 管理命令预期配置版本,须保留原值重报。
ExpectedRevision uint64 `json:"expected_revision,string"`
// Reason 非空审计原因,最多 1024 个 Unicode 字符。
Reason string `json:"reason"`
// MaxUnfinishedTasks 跨命名空间的未终结任务上限,包含待核查任务。
MaxUnfinishedTasks uint32 `json:"max_unfinished_tasks"`
// MaxConcurrency 跨队列的预占及运行尝试总上限。
MaxConcurrency uint32 `json:"max_concurrency"`
// RatePerSecond 每秒固定窗口允许的开始授权次数。
RatePerSecond uint32 `json:"rate_per_second"`
}
type ConfigureApplicationResourcesResult struct {
// Resources 配置成功时的原用量快照,重报不刷新。
Resources ApplicationResources `json:"resources"`
// Deduplicated 是否返回先前已提交的同身份回执。
Deduplicated bool `json:"deduplicated"`
}
func (c *Client) GetApplicationResources(ctx context.Context) (ApplicationResources, error) {
var out ApplicationResources
err := c.call(ctx, "GET", "/v1/application/resources", "", nil, &out)
return out, err
}
func (c *Client) ConfigureApplicationResources(ctx context.Context, key string, in ConfigureApplicationResourcesRequest) (ConfigureApplicationResourcesResult, error) {
var out ConfigureApplicationResourcesResult
err := c.call(ctx, "POST", "/v1/application/resources:configure", key, in, &out)
return out, err
}