// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. import { APIResource } from '../resource'; import { isRequestOptions } from '../core'; import * as Core from '../core'; import * as ConcurrencyLimitsV2API from './concurrency-limits-v2'; import * as Shared from './shared'; export class ConcurrencyLimitsV2 extends APIResource { /** * Create Concurrency Limit V2 */ create( params: ConcurrencyLimitsV2CreateParams, options?: Core.RequestOptions, ): Core.APIPromise { const { 'x-prefect-api-version': xPrefectAPIVersion, ...body } = params; return this._client.post('/api/v2/concurrency_limits/', { body, ...options, headers: { ...(xPrefectAPIVersion != null ? { 'x-prefect-api-version': xPrefectAPIVersion } : undefined), ...options?.headers, }, }); } /** * Read Concurrency Limit V2 */ retrieve( idOrName: string, params?: ConcurrencyLimitsV2RetrieveParams, options?: Core.RequestOptions, ): Core.APIPromise; retrieve(idOrName: string, options?: Core.RequestOptions): Core.APIPromise; retrieve( idOrName: string, params: ConcurrencyLimitsV2RetrieveParams | Core.RequestOptions = {}, options?: Core.RequestOptions, ): Core.APIPromise { if (isRequestOptions(params)) { return this.retrieve(idOrName, {}, params); } const { 'x-prefect-api-version': xPrefectAPIVersion } = params; return this._client.get(`/api/v2/concurrency_limits/${idOrName}`, { ...options, headers: { ...(xPrefectAPIVersion != null ? { 'x-prefect-api-version': xPrefectAPIVersion } : undefined), ...options?.headers, }, }); } /** * Update Concurrency Limit V2 */ update( idOrName: string, params: ConcurrencyLimitsV2UpdateParams, options?: Core.RequestOptions, ): Core.APIPromise { const { 'x-prefect-api-version': xPrefectAPIVersion, ...body } = params; return this._client.patch(`/api/v2/concurrency_limits/${idOrName}`, { body, ...options, headers: { Accept: '*/*', ...(xPrefectAPIVersion != null ? { 'x-prefect-api-version': xPrefectAPIVersion } : undefined), ...options?.headers, }, }); } /** * Delete Concurrency Limit V2 */ delete( idOrName: string, params?: ConcurrencyLimitsV2DeleteParams, options?: Core.RequestOptions, ): Core.APIPromise; delete(idOrName: string, options?: Core.RequestOptions): Core.APIPromise; delete( idOrName: string, params: ConcurrencyLimitsV2DeleteParams | Core.RequestOptions = {}, options?: Core.RequestOptions, ): Core.APIPromise { if (isRequestOptions(params)) { return this.delete(idOrName, {}, params); } const { 'x-prefect-api-version': xPrefectAPIVersion } = params; return this._client.delete(`/api/v2/concurrency_limits/${idOrName}`, { ...options, headers: { Accept: '*/*', ...(xPrefectAPIVersion != null ? { 'x-prefect-api-version': xPrefectAPIVersion } : undefined), ...options?.headers, }, }); } /** * Bulk Decrement Active Slots */ decrement( params: ConcurrencyLimitsV2DecrementParams, options?: Core.RequestOptions, ): Core.APIPromise { const { 'x-prefect-api-version': xPrefectAPIVersion, ...body } = params; return this._client.post('/api/v2/concurrency_limits/decrement', { body, ...options, headers: { ...(xPrefectAPIVersion != null ? { 'x-prefect-api-version': xPrefectAPIVersion } : undefined), ...options?.headers, }, }); } /** * Read All Concurrency Limits V2 */ filter( params?: ConcurrencyLimitsV2FilterParams, options?: Core.RequestOptions, ): Core.APIPromise; filter(options?: Core.RequestOptions): Core.APIPromise; filter( params: ConcurrencyLimitsV2FilterParams | Core.RequestOptions = {}, options?: Core.RequestOptions, ): Core.APIPromise { if (isRequestOptions(params)) { return this.filter({}, params); } const { 'x-prefect-api-version': xPrefectAPIVersion, ...body } = params; return this._client.post('/api/v2/concurrency_limits/filter', { body, ...options, headers: { ...(xPrefectAPIVersion != null ? { 'x-prefect-api-version': xPrefectAPIVersion } : undefined), ...options?.headers, }, }); } /** * Bulk Increment Active Slots */ increment( params: ConcurrencyLimitsV2IncrementParams, options?: Core.RequestOptions, ): Core.APIPromise { const { 'x-prefect-api-version': xPrefectAPIVersion, ...body } = params; return this._client.post('/api/v2/concurrency_limits/increment', { body, ...options, headers: { ...(xPrefectAPIVersion != null ? { 'x-prefect-api-version': xPrefectAPIVersion } : undefined), ...options?.headers, }, }); } } /** * An ORM representation of a v2 concurrency limit. */ export interface ConcurrencyLimitV2 { /** * The concurrency limit. */ limit: number; /** * The name of the concurrency limit. */ name: string; id?: string; /** * Whether the concurrency limit is active. */ active?: boolean; /** * The number of active slots. */ active_slots?: number; /** * The average amount of time a slot is occupied. */ avg_slot_occupancy_seconds?: number; created?: string | null; /** * The number of denied slots. */ denied_slots?: number; /** * The decay rate for active slots when used as a rate limit. */ slot_decay_per_second?: number; updated?: string | null; } /** * A response object for global concurrency limits. */ export interface GlobalConcurrencyLimitResponse { /** * The number of active slots. */ active_slots: number; /** * The concurrency limit. */ limit: number; /** * The name of the global concurrency limit. */ name: string; id?: string; /** * Whether the global concurrency limit is active. */ active?: boolean; created?: string | null; /** * The decay rate for active slots when used as a rate limit. */ slot_decay_per_second?: number; updated?: string | null; } export type ConcurrencyLimitsV2DecrementResponse = Array; export type ConcurrencyLimitsV2FilterResponse = Array; export type ConcurrencyLimitsV2IncrementResponse = Array; export interface ConcurrencyLimitsV2CreateParams { /** * Body param: The concurrency limit. */ limit: number; /** * Body param: The name of the concurrency limit. */ name: string; /** * Body param: Whether the concurrency limit is active. */ active?: boolean; /** * Body param: The number of active slots. */ active_slots?: number; /** * Body param: The number of denied slots. */ denied_slots?: number; /** * Body param: The decay rate for active slots when used as a rate limit. */ slot_decay_per_second?: number; /** * Header param: */ 'x-prefect-api-version'?: string; } export interface ConcurrencyLimitsV2RetrieveParams { 'x-prefect-api-version'?: string; } export interface ConcurrencyLimitsV2UpdateParams { /** * Body param: */ active?: boolean | null; /** * Body param: */ active_slots?: number | null; /** * Body param: */ denied_slots?: number | null; /** * Body param: */ limit?: number | null; /** * Body param: */ name?: string | null; /** * Body param: */ slot_decay_per_second?: number | null; /** * Header param: */ 'x-prefect-api-version'?: string; } export interface ConcurrencyLimitsV2DeleteParams { 'x-prefect-api-version'?: string; } export interface ConcurrencyLimitsV2DecrementParams { /** * Body param: */ names: Array; /** * Body param: */ slots: number; /** * Body param: */ create_if_missing?: boolean; /** * Body param: */ occupancy_seconds?: number | null; /** * Header param: */ 'x-prefect-api-version'?: string; } export interface ConcurrencyLimitsV2FilterParams { /** * Body param: Defaults to PREFECT_API_DEFAULT_LIMIT if not provided. */ limit?: number; /** * Body param: */ offset?: number; /** * Header param: */ 'x-prefect-api-version'?: string; } export interface ConcurrencyLimitsV2IncrementParams { /** * Body param: */ names: Array; /** * Body param: */ slots: number; /** * Body param: */ create_if_missing?: boolean; /** * Body param: */ mode?: 'concurrency' | 'rate_limit'; /** * Header param: */ 'x-prefect-api-version'?: string; } export namespace ConcurrencyLimitsV2 { export import ConcurrencyLimitV2 = ConcurrencyLimitsV2API.ConcurrencyLimitV2; export import GlobalConcurrencyLimitResponse = ConcurrencyLimitsV2API.GlobalConcurrencyLimitResponse; export import ConcurrencyLimitsV2DecrementResponse = ConcurrencyLimitsV2API.ConcurrencyLimitsV2DecrementResponse; export import ConcurrencyLimitsV2FilterResponse = ConcurrencyLimitsV2API.ConcurrencyLimitsV2FilterResponse; export import ConcurrencyLimitsV2IncrementResponse = ConcurrencyLimitsV2API.ConcurrencyLimitsV2IncrementResponse; export import ConcurrencyLimitsV2CreateParams = ConcurrencyLimitsV2API.ConcurrencyLimitsV2CreateParams; export import ConcurrencyLimitsV2RetrieveParams = ConcurrencyLimitsV2API.ConcurrencyLimitsV2RetrieveParams; export import ConcurrencyLimitsV2UpdateParams = ConcurrencyLimitsV2API.ConcurrencyLimitsV2UpdateParams; export import ConcurrencyLimitsV2DeleteParams = ConcurrencyLimitsV2API.ConcurrencyLimitsV2DeleteParams; export import ConcurrencyLimitsV2DecrementParams = ConcurrencyLimitsV2API.ConcurrencyLimitsV2DecrementParams; export import ConcurrencyLimitsV2FilterParams = ConcurrencyLimitsV2API.ConcurrencyLimitsV2FilterParams; export import ConcurrencyLimitsV2IncrementParams = ConcurrencyLimitsV2API.ConcurrencyLimitsV2IncrementParams; }