Skip to content

Commit ed50140

Browse files
feat(api): create new sandbox job (#293)
1 parent 30d2760 commit ed50140

File tree

7 files changed

+226
-1
lines changed

7 files changed

+226
-1
lines changed

.stats.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
configured_endpoints: 34
1+
configured_endpoints: 35

api.md

+10
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,16 @@ Methods:
330330

331331
## Jobs
332332

333+
Types:
334+
335+
```python
336+
from finch.types.sandbox import JobCreateResponse
337+
```
338+
339+
Methods:
340+
341+
- <code title="post /sandbox/jobs">client.sandbox.jobs.<a href="./src/finch/resources/sandbox/jobs/jobs.py">create</a>(\*\*<a href="src/finch/types/sandbox/job_create_params.py">params</a>) -> <a href="./src/finch/types/sandbox/job_create_response.py">JobCreateResponse</a></code>
342+
333343
### Configuration
334344

335345
Types:

src/finch/resources/sandbox/jobs/jobs.py

+98
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,16 @@
22

33
from __future__ import annotations
44

5+
from typing_extensions import Literal
6+
7+
import httpx
8+
9+
from .... import _legacy_response
10+
from ...._types import NOT_GIVEN, Body, Query, Headers, NotGiven
11+
from ...._utils import maybe_transform
512
from ...._compat import cached_property
613
from ...._resource import SyncAPIResource, AsyncAPIResource
14+
from ...._response import to_streamed_response_wrapper, async_to_streamed_response_wrapper
715
from .configuration import (
816
Configuration,
917
AsyncConfiguration,
@@ -12,6 +20,10 @@
1220
ConfigurationWithStreamingResponse,
1321
AsyncConfigurationWithStreamingResponse,
1422
)
23+
from ...._base_client import (
24+
make_request_options,
25+
)
26+
from ....types.sandbox import JobCreateResponse, job_create_params
1527

1628
__all__ = ["Jobs", "AsyncJobs"]
1729

@@ -29,6 +41,41 @@ def with_raw_response(self) -> JobsWithRawResponse:
2941
def with_streaming_response(self) -> JobsWithStreamingResponse:
3042
return JobsWithStreamingResponse(self)
3143

44+
def create(
45+
self,
46+
*,
47+
type: Literal["data_sync_all"],
48+
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
49+
# The extra values given here take precedence over values defined on the client or passed to this method.
50+
extra_headers: Headers | None = None,
51+
extra_query: Query | None = None,
52+
extra_body: Body | None = None,
53+
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
54+
) -> JobCreateResponse:
55+
"""Enqueue a new sandbox job
56+
57+
Args:
58+
type: The type of job to start.
59+
60+
Currently the only supported type is `data_sync_all`
61+
62+
extra_headers: Send extra headers
63+
64+
extra_query: Add additional query parameters to the request
65+
66+
extra_body: Add additional JSON properties to the request
67+
68+
timeout: Override the client-level default timeout for this request, in seconds
69+
"""
70+
return self._post(
71+
"/sandbox/jobs",
72+
body=maybe_transform({"type": type}, job_create_params.JobCreateParams),
73+
options=make_request_options(
74+
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
75+
),
76+
cast_to=JobCreateResponse,
77+
)
78+
3279

3380
class AsyncJobs(AsyncAPIResource):
3481
@cached_property
@@ -43,11 +90,50 @@ def with_raw_response(self) -> AsyncJobsWithRawResponse:
4390
def with_streaming_response(self) -> AsyncJobsWithStreamingResponse:
4491
return AsyncJobsWithStreamingResponse(self)
4592

93+
async def create(
94+
self,
95+
*,
96+
type: Literal["data_sync_all"],
97+
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
98+
# The extra values given here take precedence over values defined on the client or passed to this method.
99+
extra_headers: Headers | None = None,
100+
extra_query: Query | None = None,
101+
extra_body: Body | None = None,
102+
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
103+
) -> JobCreateResponse:
104+
"""Enqueue a new sandbox job
105+
106+
Args:
107+
type: The type of job to start.
108+
109+
Currently the only supported type is `data_sync_all`
110+
111+
extra_headers: Send extra headers
112+
113+
extra_query: Add additional query parameters to the request
114+
115+
extra_body: Add additional JSON properties to the request
116+
117+
timeout: Override the client-level default timeout for this request, in seconds
118+
"""
119+
return await self._post(
120+
"/sandbox/jobs",
121+
body=maybe_transform({"type": type}, job_create_params.JobCreateParams),
122+
options=make_request_options(
123+
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
124+
),
125+
cast_to=JobCreateResponse,
126+
)
127+
46128

47129
class JobsWithRawResponse:
48130
def __init__(self, jobs: Jobs) -> None:
49131
self._jobs = jobs
50132

133+
self.create = _legacy_response.to_raw_response_wrapper(
134+
jobs.create,
135+
)
136+
51137
@cached_property
52138
def configuration(self) -> ConfigurationWithRawResponse:
53139
return ConfigurationWithRawResponse(self._jobs.configuration)
@@ -57,6 +143,10 @@ class AsyncJobsWithRawResponse:
57143
def __init__(self, jobs: AsyncJobs) -> None:
58144
self._jobs = jobs
59145

146+
self.create = _legacy_response.async_to_raw_response_wrapper(
147+
jobs.create,
148+
)
149+
60150
@cached_property
61151
def configuration(self) -> AsyncConfigurationWithRawResponse:
62152
return AsyncConfigurationWithRawResponse(self._jobs.configuration)
@@ -66,6 +156,10 @@ class JobsWithStreamingResponse:
66156
def __init__(self, jobs: Jobs) -> None:
67157
self._jobs = jobs
68158

159+
self.create = to_streamed_response_wrapper(
160+
jobs.create,
161+
)
162+
69163
@cached_property
70164
def configuration(self) -> ConfigurationWithStreamingResponse:
71165
return ConfigurationWithStreamingResponse(self._jobs.configuration)
@@ -75,6 +169,10 @@ class AsyncJobsWithStreamingResponse:
75169
def __init__(self, jobs: AsyncJobs) -> None:
76170
self._jobs = jobs
77171

172+
self.create = async_to_streamed_response_wrapper(
173+
jobs.create,
174+
)
175+
78176
@cached_property
79177
def configuration(self) -> AsyncConfigurationWithStreamingResponse:
80178
return AsyncConfigurationWithStreamingResponse(self._jobs.configuration)

src/finch/types/sandbox/__init__.py

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
from __future__ import annotations
44

5+
from .job_create_params import JobCreateParams as JobCreateParams
6+
from .job_create_response import JobCreateResponse as JobCreateResponse
57
from .company_update_params import CompanyUpdateParams as CompanyUpdateParams
68
from .payment_create_params import PaymentCreateParams as PaymentCreateParams
79
from .company_update_response import CompanyUpdateResponse as CompanyUpdateResponse
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# File generated from our OpenAPI spec by Stainless.
2+
3+
from __future__ import annotations
4+
5+
from typing_extensions import Literal, Required, TypedDict
6+
7+
__all__ = ["JobCreateParams"]
8+
9+
10+
class JobCreateParams(TypedDict, total=False):
11+
type: Required[Literal["data_sync_all"]]
12+
"""The type of job to start. Currently the only supported type is `data_sync_all`"""
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# File generated from our OpenAPI spec by Stainless.
2+
3+
from ..._models import BaseModel
4+
5+
__all__ = ["JobCreateResponse"]
6+
7+
8+
class JobCreateResponse(BaseModel):
9+
allowed_refreshes: int
10+
"""The number of allowed refreshes per hour (per hour, fixed window)"""
11+
12+
job_id: str
13+
"""The id of the job that has been created."""
14+
15+
job_url: str
16+
"""The url that can be used to retrieve the job status"""
17+
18+
remaining_refreshes: int
19+
"""The number of remaining refreshes available (per hour, fixed window)"""
+84
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
# File generated from our OpenAPI spec by Stainless.
2+
3+
from __future__ import annotations
4+
5+
import os
6+
from typing import Any, cast
7+
8+
import pytest
9+
10+
from finch import Finch, AsyncFinch
11+
from tests.utils import assert_matches_type
12+
from finch.types.sandbox import JobCreateResponse
13+
14+
base_url = os.environ.get("TEST_API_BASE_URL", "http://127.0.0.1:4010")
15+
16+
17+
class TestJobs:
18+
parametrize = pytest.mark.parametrize("client", [False, True], indirect=True, ids=["loose", "strict"])
19+
20+
@parametrize
21+
def test_method_create(self, client: Finch) -> None:
22+
job = client.sandbox.jobs.create(
23+
type="data_sync_all",
24+
)
25+
assert_matches_type(JobCreateResponse, job, path=["response"])
26+
27+
@parametrize
28+
def test_raw_response_create(self, client: Finch) -> None:
29+
response = client.sandbox.jobs.with_raw_response.create(
30+
type="data_sync_all",
31+
)
32+
33+
assert response.is_closed is True
34+
assert response.http_request.headers.get("X-Stainless-Lang") == "python"
35+
job = response.parse()
36+
assert_matches_type(JobCreateResponse, job, path=["response"])
37+
38+
@parametrize
39+
def test_streaming_response_create(self, client: Finch) -> None:
40+
with client.sandbox.jobs.with_streaming_response.create(
41+
type="data_sync_all",
42+
) as response:
43+
assert not response.is_closed
44+
assert response.http_request.headers.get("X-Stainless-Lang") == "python"
45+
46+
job = response.parse()
47+
assert_matches_type(JobCreateResponse, job, path=["response"])
48+
49+
assert cast(Any, response.is_closed) is True
50+
51+
52+
class TestAsyncJobs:
53+
parametrize = pytest.mark.parametrize("async_client", [False, True], indirect=True, ids=["loose", "strict"])
54+
55+
@parametrize
56+
async def test_method_create(self, async_client: AsyncFinch) -> None:
57+
job = await async_client.sandbox.jobs.create(
58+
type="data_sync_all",
59+
)
60+
assert_matches_type(JobCreateResponse, job, path=["response"])
61+
62+
@parametrize
63+
async def test_raw_response_create(self, async_client: AsyncFinch) -> None:
64+
response = await async_client.sandbox.jobs.with_raw_response.create(
65+
type="data_sync_all",
66+
)
67+
68+
assert response.is_closed is True
69+
assert response.http_request.headers.get("X-Stainless-Lang") == "python"
70+
job = response.parse()
71+
assert_matches_type(JobCreateResponse, job, path=["response"])
72+
73+
@parametrize
74+
async def test_streaming_response_create(self, async_client: AsyncFinch) -> None:
75+
async with async_client.sandbox.jobs.with_streaming_response.create(
76+
type="data_sync_all",
77+
) as response:
78+
assert not response.is_closed
79+
assert response.http_request.headers.get("X-Stainless-Lang") == "python"
80+
81+
job = await response.parse()
82+
assert_matches_type(JobCreateResponse, job, path=["response"])
83+
84+
assert cast(Any, response.is_closed) is True

0 commit comments

Comments
 (0)