// 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 WorkQueuesAPI from './work-queues'; import * as Shared from './shared'; export class WorkQueues extends APIResource { /** * Creates a new work queue. * * If a work queue with the same name already exists, an error will be raised. */ create( params: WorkQueueCreateParams, options?: Core.RequestOptions, ): Core.APIPromise { const { 'x-prefect-api-version': xPrefectAPIVersion, ...body } = params; return this._client.post('/api/work_queues/', { body, ...options, headers: { ...(xPrefectAPIVersion != null ? { 'x-prefect-api-version': xPrefectAPIVersion } : undefined), ...options?.headers, }, }); } /** * Get a work queue by id. */ retrieve( id: string, params?: WorkQueueRetrieveParams, options?: Core.RequestOptions, ): Core.APIPromise; retrieve(id: string, options?: Core.RequestOptions): Core.APIPromise; retrieve( id: string, params: WorkQueueRetrieveParams | Core.RequestOptions = {}, options?: Core.RequestOptions, ): Core.APIPromise { if (isRequestOptions(params)) { return this.retrieve(id, {}, params); } const { 'x-prefect-api-version': xPrefectAPIVersion } = params; return this._client.get(`/api/work_queues/${id}`, { ...options, headers: { ...(xPrefectAPIVersion != null ? { 'x-prefect-api-version': xPrefectAPIVersion } : undefined), ...options?.headers, }, }); } /** * Updates an existing work queue. */ update(id: string, params: WorkQueueUpdateParams, options?: Core.RequestOptions): Core.APIPromise { const { 'x-prefect-api-version': xPrefectAPIVersion, ...body } = params; return this._client.patch(`/api/work_queues/${id}`, { body, ...options, headers: { Accept: '*/*', ...(xPrefectAPIVersion != null ? { 'x-prefect-api-version': xPrefectAPIVersion } : undefined), ...options?.headers, }, }); } /** * Delete a work queue by id. */ delete(id: string, params?: WorkQueueDeleteParams, options?: Core.RequestOptions): Core.APIPromise; delete(id: string, options?: Core.RequestOptions): Core.APIPromise; delete( id: string, params: WorkQueueDeleteParams | Core.RequestOptions = {}, options?: Core.RequestOptions, ): Core.APIPromise { if (isRequestOptions(params)) { return this.delete(id, {}, params); } const { 'x-prefect-api-version': xPrefectAPIVersion } = params; return this._client.delete(`/api/work_queues/${id}`, { ...options, headers: { Accept: '*/*', ...(xPrefectAPIVersion != null ? { 'x-prefect-api-version': xPrefectAPIVersion } : undefined), ...options?.headers, }, }); } /** * Query for work queues. */ filter( params?: WorkQueueFilterParams, options?: Core.RequestOptions, ): Core.APIPromise; filter(options?: Core.RequestOptions): Core.APIPromise; filter( params: WorkQueueFilterParams | 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/work_queues/filter', { body, ...options, headers: { ...(xPrefectAPIVersion != null ? { 'x-prefect-api-version': xPrefectAPIVersion } : undefined), ...options?.headers, }, }); } /** * Get flow runs from the work queue. */ getRuns( id: string, params?: WorkQueueGetRunsParams, options?: Core.RequestOptions, ): Core.APIPromise; getRuns(id: string, options?: Core.RequestOptions): Core.APIPromise; getRuns( id: string, params: WorkQueueGetRunsParams | Core.RequestOptions = {}, options?: Core.RequestOptions, ): Core.APIPromise { if (isRequestOptions(params)) { return this.getRuns(id, {}, params); } const { 'x-prefect-api-version': xPrefectAPIVersion, 'x-prefect-ui': xPrefectUi, ...body } = params; return this._client.post(`/api/work_queues/${id}/get_runs`, { body, ...options, headers: { ...(xPrefectAPIVersion != null ? { 'x-prefect-api-version': xPrefectAPIVersion } : undefined), ...(xPrefectUi?.toString() != null ? { 'x-prefect-ui': xPrefectUi?.toString() } : undefined), ...options?.headers, }, }); } /** * Get a work queue by id. */ retrieveByName( name: string, params?: WorkQueueRetrieveByNameParams, options?: Core.RequestOptions, ): Core.APIPromise; retrieveByName(name: string, options?: Core.RequestOptions): Core.APIPromise; retrieveByName( name: string, params: WorkQueueRetrieveByNameParams | Core.RequestOptions = {}, options?: Core.RequestOptions, ): Core.APIPromise { if (isRequestOptions(params)) { return this.retrieveByName(name, {}, params); } const { 'x-prefect-api-version': xPrefectAPIVersion } = params; return this._client.get(`/api/work_queues/name/${name}`, { ...options, headers: { ...(xPrefectAPIVersion != null ? { 'x-prefect-api-version': xPrefectAPIVersion } : undefined), ...options?.headers, }, }); } /** * Get the status of a work queue. */ status( id: string, params?: WorkQueueStatusParams, options?: Core.RequestOptions, ): Core.APIPromise; status(id: string, options?: Core.RequestOptions): Core.APIPromise; status( id: string, params: WorkQueueStatusParams | Core.RequestOptions = {}, options?: Core.RequestOptions, ): Core.APIPromise { if (isRequestOptions(params)) { return this.status(id, {}, params); } const { 'x-prefect-api-version': xPrefectAPIVersion } = params; return this._client.get(`/api/work_queues/${id}/status`, { ...options, headers: { ...(xPrefectAPIVersion != null ? { 'x-prefect-api-version': xPrefectAPIVersion } : undefined), ...options?.headers, }, }); } } export interface WorkQueueStatusDetail { /** * The policy used to determine whether or not the work queue is healthy. */ health_check_policy: WorkQueueStatusDetail.HealthCheckPolicy; /** * Whether or not the work queue is healthy. */ healthy: boolean; /** * The last time an agent polled this queue for work. */ last_polled?: string | null; /** * The number of late flow runs in the work queue. */ late_runs_count?: number; } export namespace WorkQueueStatusDetail { /** * The policy used to determine whether or not the work queue is healthy. */ export interface HealthCheckPolicy { /** * The maximum number of late runs in the work queue before it is deemed unhealthy. * Defaults to `0`. */ maximum_late_runs?: number | null; /** * The maximum number of time in seconds elapsed since work queue has been polled * before it is deemed unhealthy. Defaults to `60`. */ maximum_seconds_since_last_polled?: number | null; } } export type WorkQueueFilterResponse = Array; export type WorkQueueGetRunsResponse = Array; export interface WorkQueueCreateParams { /** * Body param: The name of the work queue. */ name: string; /** * Body param: The work queue's concurrency limit. */ concurrency_limit?: number | null; /** * Body param: An optional description for the work queue. */ description?: string | null; /** * Body param: Filter criteria definition for a work queue. */ filter?: WorkQueueCreateParams.Filter | null; /** * Body param: Whether or not the work queue is paused. */ is_paused?: boolean; /** * Body param: The queue's priority. Lower values are higher priority (1 is the * highest). */ priority?: number | null; /** * Header param: */ 'x-prefect-api-version'?: string; } export namespace WorkQueueCreateParams { /** * @deprecated: Filter criteria definition for a work queue. */ export interface Filter { /** * Only include flow runs from these deployments in the work queue. */ deployment_ids?: Array | null; /** * Only include flow runs with these tags in the work queue. */ tags?: Array | null; } } export interface WorkQueueRetrieveParams { 'x-prefect-api-version'?: string; } export interface WorkQueueUpdateParams { /** * Body param: */ concurrency_limit?: number | null; /** * Body param: */ description?: string | null; /** * Body param: Filter criteria definition for a work queue. */ filter?: WorkQueueUpdateParams.Filter | null; /** * Body param: Whether or not the work queue is paused. */ is_paused?: boolean; /** * Body param: */ last_polled?: string | null; /** * Body param: */ name?: string | null; /** * Body param: */ priority?: number | null; /** * Header param: */ 'x-prefect-api-version'?: string; } export namespace WorkQueueUpdateParams { /** * @deprecated: Filter criteria definition for a work queue. */ export interface Filter { /** * Only include flow runs from these deployments in the work queue. */ deployment_ids?: Array | null; /** * Only include flow runs with these tags in the work queue. */ tags?: Array | null; } } export interface WorkQueueDeleteParams { 'x-prefect-api-version'?: string; } export interface WorkQueueFilterParams { /** * Body param: Defaults to PREFECT_API_DEFAULT_LIMIT if not provided. */ limit?: number; /** * Body param: */ offset?: number; /** * Body param: Filter work queues. Only work queues matching all criteria will be * returned */ work_queues?: WorkQueueFilterParams.WorkQueues; /** * Header param: */ 'x-prefect-api-version'?: string; } export namespace WorkQueueFilterParams { /** * Filter work queues. Only work queues matching all criteria will be returned */ export interface WorkQueues { /** * Filter by `WorkQueue.id`. */ id?: WorkQueues.ID | null; /** * Filter by `WorkQueue.name`. */ name?: WorkQueues.Name | null; /** * Operator for combining filter criteria. Defaults to 'and\_'. */ operator?: 'and_' | 'or_'; } export namespace WorkQueues { /** * Filter by `WorkQueue.id`. */ export interface ID { /** * A list of work queue ids to include */ any_?: Array | null; } /** * Filter by `WorkQueue.name`. */ export interface Name { /** * A list of work queue names to include */ any_?: Array | null; /** * A list of case-insensitive starts-with matches. For example, passing 'marvin' * will match 'marvin', and 'Marvin-robot', but not 'sad-marvin'. */ startswith_?: Array | null; } } } export interface WorkQueueGetRunsParams { /** * Body param: An optional unique identifier for the agent making this query. If * provided, the Prefect REST API will track the last time this agent polled the * work queue. */ agent_id?: string | null; /** * Body param: Defaults to PREFECT_API_DEFAULT_LIMIT if not provided. */ limit?: number; /** * Body param: Only flow runs scheduled to start before this time will be returned. */ scheduled_before?: string; /** * Header param: */ 'x-prefect-api-version'?: string; /** * Header param: A header to indicate this request came from the Prefect UI. */ 'x-prefect-ui'?: boolean; } export interface WorkQueueRetrieveByNameParams { 'x-prefect-api-version'?: string; } export interface WorkQueueStatusParams { 'x-prefect-api-version'?: string; } export namespace WorkQueues { export import WorkQueueStatusDetail = WorkQueuesAPI.WorkQueueStatusDetail; export import WorkQueueFilterResponse = WorkQueuesAPI.WorkQueueFilterResponse; export import WorkQueueGetRunsResponse = WorkQueuesAPI.WorkQueueGetRunsResponse; export import WorkQueueCreateParams = WorkQueuesAPI.WorkQueueCreateParams; export import WorkQueueRetrieveParams = WorkQueuesAPI.WorkQueueRetrieveParams; export import WorkQueueUpdateParams = WorkQueuesAPI.WorkQueueUpdateParams; export import WorkQueueDeleteParams = WorkQueuesAPI.WorkQueueDeleteParams; export import WorkQueueFilterParams = WorkQueuesAPI.WorkQueueFilterParams; export import WorkQueueGetRunsParams = WorkQueuesAPI.WorkQueueGetRunsParams; export import WorkQueueRetrieveByNameParams = WorkQueuesAPI.WorkQueueRetrieveByNameParams; export import WorkQueueStatusParams = WorkQueuesAPI.WorkQueueStatusParams; }