Skip to content

feat(api): create new sandbox job #293

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .stats.yml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
configured_endpoints: 34
configured_endpoints: 35
10 changes: 10 additions & 0 deletions api.md
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,16 @@ Methods:

## Jobs

Types:

```python
from finch.types.sandbox import JobCreateResponse
```

Methods:

- <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>

### Configuration

Types:
Expand Down
98 changes: 98 additions & 0 deletions src/finch/resources/sandbox/jobs/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,16 @@

from __future__ import annotations

from typing_extensions import Literal

import httpx

from .... import _legacy_response
from ...._types import NOT_GIVEN, Body, Query, Headers, NotGiven
from ...._utils import maybe_transform
from ...._compat import cached_property
from ...._resource import SyncAPIResource, AsyncAPIResource
from ...._response import to_streamed_response_wrapper, async_to_streamed_response_wrapper
from .configuration import (
Configuration,
AsyncConfiguration,
Expand All @@ -12,6 +20,10 @@
ConfigurationWithStreamingResponse,
AsyncConfigurationWithStreamingResponse,
)
from ...._base_client import (
make_request_options,
)
from ....types.sandbox import JobCreateResponse, job_create_params

__all__ = ["Jobs", "AsyncJobs"]

Expand All @@ -29,6 +41,41 @@ def with_raw_response(self) -> JobsWithRawResponse:
def with_streaming_response(self) -> JobsWithStreamingResponse:
return JobsWithStreamingResponse(self)

def create(
self,
*,
type: Literal["data_sync_all"],
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
) -> JobCreateResponse:
"""Enqueue a new sandbox job

Args:
type: The type of job to start.

Currently the only supported type is `data_sync_all`

extra_headers: Send extra headers

extra_query: Add additional query parameters to the request

extra_body: Add additional JSON properties to the request

timeout: Override the client-level default timeout for this request, in seconds
"""
return self._post(
"/sandbox/jobs",
body=maybe_transform({"type": type}, job_create_params.JobCreateParams),
options=make_request_options(
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
),
cast_to=JobCreateResponse,
)


class AsyncJobs(AsyncAPIResource):
@cached_property
Expand All @@ -43,11 +90,50 @@ def with_raw_response(self) -> AsyncJobsWithRawResponse:
def with_streaming_response(self) -> AsyncJobsWithStreamingResponse:
return AsyncJobsWithStreamingResponse(self)

async def create(
self,
*,
type: Literal["data_sync_all"],
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
) -> JobCreateResponse:
"""Enqueue a new sandbox job

Args:
type: The type of job to start.

Currently the only supported type is `data_sync_all`

extra_headers: Send extra headers

extra_query: Add additional query parameters to the request

extra_body: Add additional JSON properties to the request

timeout: Override the client-level default timeout for this request, in seconds
"""
return await self._post(
"/sandbox/jobs",
body=maybe_transform({"type": type}, job_create_params.JobCreateParams),
options=make_request_options(
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
),
cast_to=JobCreateResponse,
)


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

self.create = _legacy_response.to_raw_response_wrapper(
jobs.create,
)

@cached_property
def configuration(self) -> ConfigurationWithRawResponse:
return ConfigurationWithRawResponse(self._jobs.configuration)
Expand All @@ -57,6 +143,10 @@ class AsyncJobsWithRawResponse:
def __init__(self, jobs: AsyncJobs) -> None:
self._jobs = jobs

self.create = _legacy_response.async_to_raw_response_wrapper(
jobs.create,
)

@cached_property
def configuration(self) -> AsyncConfigurationWithRawResponse:
return AsyncConfigurationWithRawResponse(self._jobs.configuration)
Expand All @@ -66,6 +156,10 @@ class JobsWithStreamingResponse:
def __init__(self, jobs: Jobs) -> None:
self._jobs = jobs

self.create = to_streamed_response_wrapper(
jobs.create,
)

@cached_property
def configuration(self) -> ConfigurationWithStreamingResponse:
return ConfigurationWithStreamingResponse(self._jobs.configuration)
Expand All @@ -75,6 +169,10 @@ class AsyncJobsWithStreamingResponse:
def __init__(self, jobs: AsyncJobs) -> None:
self._jobs = jobs

self.create = async_to_streamed_response_wrapper(
jobs.create,
)

@cached_property
def configuration(self) -> AsyncConfigurationWithStreamingResponse:
return AsyncConfigurationWithStreamingResponse(self._jobs.configuration)
2 changes: 2 additions & 0 deletions src/finch/types/sandbox/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

from __future__ import annotations

from .job_create_params import JobCreateParams as JobCreateParams
from .job_create_response import JobCreateResponse as JobCreateResponse
from .company_update_params import CompanyUpdateParams as CompanyUpdateParams
from .payment_create_params import PaymentCreateParams as PaymentCreateParams
from .company_update_response import CompanyUpdateResponse as CompanyUpdateResponse
Expand Down
12 changes: 12 additions & 0 deletions src/finch/types/sandbox/job_create_params.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# File generated from our OpenAPI spec by Stainless.

from __future__ import annotations

from typing_extensions import Literal, Required, TypedDict

__all__ = ["JobCreateParams"]


class JobCreateParams(TypedDict, total=False):
type: Required[Literal["data_sync_all"]]
"""The type of job to start. Currently the only supported type is `data_sync_all`"""
19 changes: 19 additions & 0 deletions src/finch/types/sandbox/job_create_response.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# File generated from our OpenAPI spec by Stainless.

from ..._models import BaseModel

__all__ = ["JobCreateResponse"]


class JobCreateResponse(BaseModel):
allowed_refreshes: int
"""The number of allowed refreshes per hour (per hour, fixed window)"""

job_id: str
"""The id of the job that has been created."""

job_url: str
"""The url that can be used to retrieve the job status"""

remaining_refreshes: int
"""The number of remaining refreshes available (per hour, fixed window)"""
84 changes: 84 additions & 0 deletions tests/api_resources/sandbox/test_jobs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
# File generated from our OpenAPI spec by Stainless.

from __future__ import annotations

import os
from typing import Any, cast

import pytest

from finch import Finch, AsyncFinch
from tests.utils import assert_matches_type
from finch.types.sandbox import JobCreateResponse

base_url = os.environ.get("TEST_API_BASE_URL", "http://127.0.0.1:4010")


class TestJobs:
parametrize = pytest.mark.parametrize("client", [False, True], indirect=True, ids=["loose", "strict"])

@parametrize
def test_method_create(self, client: Finch) -> None:
job = client.sandbox.jobs.create(
type="data_sync_all",
)
assert_matches_type(JobCreateResponse, job, path=["response"])

@parametrize
def test_raw_response_create(self, client: Finch) -> None:
response = client.sandbox.jobs.with_raw_response.create(
type="data_sync_all",
)

assert response.is_closed is True
assert response.http_request.headers.get("X-Stainless-Lang") == "python"
job = response.parse()
assert_matches_type(JobCreateResponse, job, path=["response"])

@parametrize
def test_streaming_response_create(self, client: Finch) -> None:
with client.sandbox.jobs.with_streaming_response.create(
type="data_sync_all",
) as response:
assert not response.is_closed
assert response.http_request.headers.get("X-Stainless-Lang") == "python"

job = response.parse()
assert_matches_type(JobCreateResponse, job, path=["response"])

assert cast(Any, response.is_closed) is True


class TestAsyncJobs:
parametrize = pytest.mark.parametrize("async_client", [False, True], indirect=True, ids=["loose", "strict"])

@parametrize
async def test_method_create(self, async_client: AsyncFinch) -> None:
job = await async_client.sandbox.jobs.create(
type="data_sync_all",
)
assert_matches_type(JobCreateResponse, job, path=["response"])

@parametrize
async def test_raw_response_create(self, async_client: AsyncFinch) -> None:
response = await async_client.sandbox.jobs.with_raw_response.create(
type="data_sync_all",
)

assert response.is_closed is True
assert response.http_request.headers.get("X-Stainless-Lang") == "python"
job = response.parse()
assert_matches_type(JobCreateResponse, job, path=["response"])

@parametrize
async def test_streaming_response_create(self, async_client: AsyncFinch) -> None:
async with async_client.sandbox.jobs.with_streaming_response.create(
type="data_sync_all",
) as response:
assert not response.is_closed
assert response.http_request.headers.get("X-Stainless-Lang") == "python"

job = await response.parse()
assert_matches_type(JobCreateResponse, job, path=["response"])

assert cast(Any, response.is_closed) is True