Skip to content

Commit 45d91e2

Browse files
feat(workflows): add bulk support (#2551)
1 parent f0a6a21 commit 45d91e2

File tree

7 files changed

+266
-5
lines changed

7 files changed

+266
-5
lines changed

.stats.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
configured_endpoints: 1650
1+
configured_endpoints: 1651
22
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/cloudflare%2Fcloudflare-0ed9f898b31619623e50d660d04beca50e44987bfd3eb3a6ff98d3bca2a9c569.yml

api.md

+2
Original file line numberDiff line numberDiff line change
@@ -9087,6 +9087,7 @@ Types:
90879087
from cloudflare.types.workflows import (
90889088
InstanceCreateResponse,
90899089
InstanceListResponse,
9090+
InstanceBulkResponse,
90909091
InstanceGetResponse,
90919092
)
90929093
```
@@ -9095,6 +9096,7 @@ Methods:
90959096

90969097
- <code title="post /accounts/{account_id}/workflows/{workflow_name}/instances">client.workflows.instances.<a href="./src/cloudflare/resources/workflows/instances/instances.py">create</a>(workflow_name, \*, account_id, \*\*<a href="src/cloudflare/types/workflows/instance_create_params.py">params</a>) -> <a href="./src/cloudflare/types/workflows/instance_create_response.py">InstanceCreateResponse</a></code>
90979098
- <code title="get /accounts/{account_id}/workflows/{workflow_name}/instances">client.workflows.instances.<a href="./src/cloudflare/resources/workflows/instances/instances.py">list</a>(workflow_name, \*, account_id, \*\*<a href="src/cloudflare/types/workflows/instance_list_params.py">params</a>) -> <a href="./src/cloudflare/types/workflows/instance_list_response.py">SyncV4PagePaginationArray[InstanceListResponse]</a></code>
9099+
- <code title="post /accounts/{account_id}/workflows/{workflow_name}/instances/batch">client.workflows.instances.<a href="./src/cloudflare/resources/workflows/instances/instances.py">bulk</a>(workflow_name, \*, account_id, \*\*<a href="src/cloudflare/types/workflows/instance_bulk_params.py">params</a>) -> <a href="./src/cloudflare/types/workflows/instance_bulk_response.py">SyncSinglePage[InstanceBulkResponse]</a></code>
90989100
- <code title="get /accounts/{account_id}/workflows/{workflow_name}/instances/{instance_id}">client.workflows.instances.<a href="./src/cloudflare/resources/workflows/instances/instances.py">get</a>(instance_id, \*, account_id, workflow_name) -> <a href="./src/cloudflare/types/workflows/instance_get_response.py">InstanceGetResponse</a></code>
90999101

91009102
### Status

src/cloudflare/resources/workflows/instances/instances.py

+96-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from __future__ import annotations
44

5-
from typing import Type, Union, cast
5+
from typing import Type, Union, Iterable, cast
66
from datetime import datetime
77
from typing_extensions import Literal
88

@@ -30,10 +30,11 @@
3030
async_to_streamed_response_wrapper,
3131
)
3232
from ...._wrappers import ResultWrapper
33-
from ....pagination import SyncV4PagePaginationArray, AsyncV4PagePaginationArray
33+
from ....pagination import SyncSinglePage, AsyncSinglePage, SyncV4PagePaginationArray, AsyncV4PagePaginationArray
3434
from ...._base_client import AsyncPaginator, make_request_options
35-
from ....types.workflows import instance_list_params, instance_create_params
35+
from ....types.workflows import instance_bulk_params, instance_list_params, instance_create_params
3636
from ....types.workflows.instance_get_response import InstanceGetResponse
37+
from ....types.workflows.instance_bulk_response import InstanceBulkResponse
3738
from ....types.workflows.instance_list_response import InstanceListResponse
3839
from ....types.workflows.instance_create_response import InstanceCreateResponse
3940

@@ -175,6 +176,46 @@ def list(
175176
model=InstanceListResponse,
176177
)
177178

179+
def bulk(
180+
self,
181+
workflow_name: str,
182+
*,
183+
account_id: str,
184+
body: Iterable[instance_bulk_params.Body] | NotGiven = NOT_GIVEN,
185+
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
186+
# The extra values given here take precedence over values defined on the client or passed to this method.
187+
extra_headers: Headers | None = None,
188+
extra_query: Query | None = None,
189+
extra_body: Body | None = None,
190+
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
191+
) -> SyncSinglePage[InstanceBulkResponse]:
192+
"""
193+
Batch create new Workflow instances
194+
195+
Args:
196+
extra_headers: Send extra headers
197+
198+
extra_query: Add additional query parameters to the request
199+
200+
extra_body: Add additional JSON properties to the request
201+
202+
timeout: Override the client-level default timeout for this request, in seconds
203+
"""
204+
if not account_id:
205+
raise ValueError(f"Expected a non-empty value for `account_id` but received {account_id!r}")
206+
if not workflow_name:
207+
raise ValueError(f"Expected a non-empty value for `workflow_name` but received {workflow_name!r}")
208+
return self._get_api_list(
209+
f"/accounts/{account_id}/workflows/{workflow_name}/instances/batch",
210+
page=SyncSinglePage[InstanceBulkResponse],
211+
body=maybe_transform(body, Iterable[instance_bulk_params.Body]),
212+
options=make_request_options(
213+
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
214+
),
215+
model=InstanceBulkResponse,
216+
method="post",
217+
)
218+
178219
def get(
179220
self,
180221
instance_id: str,
@@ -354,6 +395,46 @@ def list(
354395
model=InstanceListResponse,
355396
)
356397

398+
def bulk(
399+
self,
400+
workflow_name: str,
401+
*,
402+
account_id: str,
403+
body: Iterable[instance_bulk_params.Body] | NotGiven = NOT_GIVEN,
404+
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
405+
# The extra values given here take precedence over values defined on the client or passed to this method.
406+
extra_headers: Headers | None = None,
407+
extra_query: Query | None = None,
408+
extra_body: Body | None = None,
409+
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
410+
) -> AsyncPaginator[InstanceBulkResponse, AsyncSinglePage[InstanceBulkResponse]]:
411+
"""
412+
Batch create new Workflow instances
413+
414+
Args:
415+
extra_headers: Send extra headers
416+
417+
extra_query: Add additional query parameters to the request
418+
419+
extra_body: Add additional JSON properties to the request
420+
421+
timeout: Override the client-level default timeout for this request, in seconds
422+
"""
423+
if not account_id:
424+
raise ValueError(f"Expected a non-empty value for `account_id` but received {account_id!r}")
425+
if not workflow_name:
426+
raise ValueError(f"Expected a non-empty value for `workflow_name` but received {workflow_name!r}")
427+
return self._get_api_list(
428+
f"/accounts/{account_id}/workflows/{workflow_name}/instances/batch",
429+
page=AsyncSinglePage[InstanceBulkResponse],
430+
body=maybe_transform(body, Iterable[instance_bulk_params.Body]),
431+
options=make_request_options(
432+
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
433+
),
434+
model=InstanceBulkResponse,
435+
method="post",
436+
)
437+
357438
async def get(
358439
self,
359440
instance_id: str,
@@ -408,6 +489,9 @@ def __init__(self, instances: InstancesResource) -> None:
408489
self.list = to_raw_response_wrapper(
409490
instances.list,
410491
)
492+
self.bulk = to_raw_response_wrapper(
493+
instances.bulk,
494+
)
411495
self.get = to_raw_response_wrapper(
412496
instances.get,
413497
)
@@ -427,6 +511,9 @@ def __init__(self, instances: AsyncInstancesResource) -> None:
427511
self.list = async_to_raw_response_wrapper(
428512
instances.list,
429513
)
514+
self.bulk = async_to_raw_response_wrapper(
515+
instances.bulk,
516+
)
430517
self.get = async_to_raw_response_wrapper(
431518
instances.get,
432519
)
@@ -446,6 +533,9 @@ def __init__(self, instances: InstancesResource) -> None:
446533
self.list = to_streamed_response_wrapper(
447534
instances.list,
448535
)
536+
self.bulk = to_streamed_response_wrapper(
537+
instances.bulk,
538+
)
449539
self.get = to_streamed_response_wrapper(
450540
instances.get,
451541
)
@@ -465,6 +555,9 @@ def __init__(self, instances: AsyncInstancesResource) -> None:
465555
self.list = async_to_streamed_response_wrapper(
466556
instances.list,
467557
)
558+
self.bulk = async_to_streamed_response_wrapper(
559+
instances.bulk,
560+
)
468561
self.get = async_to_streamed_response_wrapper(
469562
instances.get,
470563
)

src/cloudflare/types/workflows/__init__.py

+2
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@
33
from __future__ import annotations
44

55
from .version_list_params import VersionListParams as VersionListParams
6+
from .instance_bulk_params import InstanceBulkParams as InstanceBulkParams
67
from .instance_list_params import InstanceListParams as InstanceListParams
78
from .version_get_response import VersionGetResponse as VersionGetResponse
89
from .workflow_list_params import WorkflowListParams as WorkflowListParams
910
from .instance_get_response import InstanceGetResponse as InstanceGetResponse
1011
from .version_list_response import VersionListResponse as VersionListResponse
1112
from .workflow_get_response import WorkflowGetResponse as WorkflowGetResponse
13+
from .instance_bulk_response import InstanceBulkResponse as InstanceBulkResponse
1214
from .instance_create_params import InstanceCreateParams as InstanceCreateParams
1315
from .instance_list_response import InstanceListResponse as InstanceListResponse
1416
from .workflow_list_response import WorkflowListResponse as WorkflowListResponse
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2+
3+
from __future__ import annotations
4+
5+
from typing import Iterable
6+
from typing_extensions import Required, TypedDict
7+
8+
__all__ = ["InstanceBulkParams", "Body"]
9+
10+
11+
class InstanceBulkParams(TypedDict, total=False):
12+
account_id: Required[str]
13+
14+
body: Iterable[Body]
15+
16+
17+
class Body(TypedDict, total=False):
18+
instance_id: str
19+
20+
params: object
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2+
3+
from typing_extensions import Literal
4+
5+
from ..._models import BaseModel
6+
7+
__all__ = ["InstanceBulkResponse"]
8+
9+
10+
class InstanceBulkResponse(BaseModel):
11+
id: str
12+
13+
status: Literal[
14+
"queued", "running", "paused", "errored", "terminated", "complete", "waitingForPause", "waiting", "unknown"
15+
]
16+
17+
version_id: str
18+
19+
workflow_id: str

tests/api_resources/workflows/test_instances.py

+126-1
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@
1010
from cloudflare import Cloudflare, AsyncCloudflare
1111
from tests.utils import assert_matches_type
1212
from cloudflare._utils import parse_datetime
13-
from cloudflare.pagination import SyncV4PagePaginationArray, AsyncV4PagePaginationArray
13+
from cloudflare.pagination import SyncSinglePage, AsyncSinglePage, SyncV4PagePaginationArray, AsyncV4PagePaginationArray
1414
from cloudflare.types.workflows import (
1515
InstanceGetResponse,
16+
InstanceBulkResponse,
1617
InstanceListResponse,
1718
InstanceCreateResponse,
1819
)
@@ -142,6 +143,68 @@ def test_path_params_list(self, client: Cloudflare) -> None:
142143
account_id="account_id",
143144
)
144145

146+
@parametrize
147+
def test_method_bulk(self, client: Cloudflare) -> None:
148+
instance = client.workflows.instances.bulk(
149+
workflow_name="x",
150+
account_id="account_id",
151+
)
152+
assert_matches_type(SyncSinglePage[InstanceBulkResponse], instance, path=["response"])
153+
154+
@parametrize
155+
def test_method_bulk_with_all_params(self, client: Cloudflare) -> None:
156+
instance = client.workflows.instances.bulk(
157+
workflow_name="x",
158+
account_id="account_id",
159+
body=[
160+
{
161+
"instance_id": "instance_id",
162+
"params": {},
163+
}
164+
],
165+
)
166+
assert_matches_type(SyncSinglePage[InstanceBulkResponse], instance, path=["response"])
167+
168+
@parametrize
169+
def test_raw_response_bulk(self, client: Cloudflare) -> None:
170+
response = client.workflows.instances.with_raw_response.bulk(
171+
workflow_name="x",
172+
account_id="account_id",
173+
)
174+
175+
assert response.is_closed is True
176+
assert response.http_request.headers.get("X-Stainless-Lang") == "python"
177+
instance = response.parse()
178+
assert_matches_type(SyncSinglePage[InstanceBulkResponse], instance, path=["response"])
179+
180+
@parametrize
181+
def test_streaming_response_bulk(self, client: Cloudflare) -> None:
182+
with client.workflows.instances.with_streaming_response.bulk(
183+
workflow_name="x",
184+
account_id="account_id",
185+
) as response:
186+
assert not response.is_closed
187+
assert response.http_request.headers.get("X-Stainless-Lang") == "python"
188+
189+
instance = response.parse()
190+
assert_matches_type(SyncSinglePage[InstanceBulkResponse], instance, path=["response"])
191+
192+
assert cast(Any, response.is_closed) is True
193+
194+
@parametrize
195+
def test_path_params_bulk(self, client: Cloudflare) -> None:
196+
with pytest.raises(ValueError, match=r"Expected a non-empty value for `account_id` but received ''"):
197+
client.workflows.instances.with_raw_response.bulk(
198+
workflow_name="x",
199+
account_id="",
200+
)
201+
202+
with pytest.raises(ValueError, match=r"Expected a non-empty value for `workflow_name` but received ''"):
203+
client.workflows.instances.with_raw_response.bulk(
204+
workflow_name="",
205+
account_id="account_id",
206+
)
207+
145208
@parametrize
146209
def test_method_get(self, client: Cloudflare) -> None:
147210
instance = client.workflows.instances.get(
@@ -325,6 +388,68 @@ async def test_path_params_list(self, async_client: AsyncCloudflare) -> None:
325388
account_id="account_id",
326389
)
327390

391+
@parametrize
392+
async def test_method_bulk(self, async_client: AsyncCloudflare) -> None:
393+
instance = await async_client.workflows.instances.bulk(
394+
workflow_name="x",
395+
account_id="account_id",
396+
)
397+
assert_matches_type(AsyncSinglePage[InstanceBulkResponse], instance, path=["response"])
398+
399+
@parametrize
400+
async def test_method_bulk_with_all_params(self, async_client: AsyncCloudflare) -> None:
401+
instance = await async_client.workflows.instances.bulk(
402+
workflow_name="x",
403+
account_id="account_id",
404+
body=[
405+
{
406+
"instance_id": "instance_id",
407+
"params": {},
408+
}
409+
],
410+
)
411+
assert_matches_type(AsyncSinglePage[InstanceBulkResponse], instance, path=["response"])
412+
413+
@parametrize
414+
async def test_raw_response_bulk(self, async_client: AsyncCloudflare) -> None:
415+
response = await async_client.workflows.instances.with_raw_response.bulk(
416+
workflow_name="x",
417+
account_id="account_id",
418+
)
419+
420+
assert response.is_closed is True
421+
assert response.http_request.headers.get("X-Stainless-Lang") == "python"
422+
instance = await response.parse()
423+
assert_matches_type(AsyncSinglePage[InstanceBulkResponse], instance, path=["response"])
424+
425+
@parametrize
426+
async def test_streaming_response_bulk(self, async_client: AsyncCloudflare) -> None:
427+
async with async_client.workflows.instances.with_streaming_response.bulk(
428+
workflow_name="x",
429+
account_id="account_id",
430+
) as response:
431+
assert not response.is_closed
432+
assert response.http_request.headers.get("X-Stainless-Lang") == "python"
433+
434+
instance = await response.parse()
435+
assert_matches_type(AsyncSinglePage[InstanceBulkResponse], instance, path=["response"])
436+
437+
assert cast(Any, response.is_closed) is True
438+
439+
@parametrize
440+
async def test_path_params_bulk(self, async_client: AsyncCloudflare) -> None:
441+
with pytest.raises(ValueError, match=r"Expected a non-empty value for `account_id` but received ''"):
442+
await async_client.workflows.instances.with_raw_response.bulk(
443+
workflow_name="x",
444+
account_id="",
445+
)
446+
447+
with pytest.raises(ValueError, match=r"Expected a non-empty value for `workflow_name` but received ''"):
448+
await async_client.workflows.instances.with_raw_response.bulk(
449+
workflow_name="",
450+
account_id="account_id",
451+
)
452+
328453
@parametrize
329454
async def test_method_get(self, async_client: AsyncCloudflare) -> None:
330455
instance = await async_client.workflows.instances.get(

0 commit comments

Comments
 (0)