Skip to content

Commit

Permalink
Hide internal fields from public api
Browse files Browse the repository at this point in the history
  • Loading branch information
romasku committed Jul 12, 2021
1 parent fd32e8e commit 90904cc
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 39 deletions.
24 changes: 2 additions & 22 deletions neuro-sdk/docs/jobs_reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,6 @@ Jobs
reverse: bool = False, \
limit: Optional[int] = None, \
cluster_name: Optional[str] = None, \
materialized: Optional[bool] = None, \
being_dropped: Optional[bool] = False, \
logs_removed: Optional[bool] = False, \
) -> AsyncContextManager[AsyncIterator[JobDescription]]
:async-with:
:async-for:
Expand Down Expand Up @@ -218,13 +215,6 @@ Jobs

``None`` means the current cluster (default).

:param bool materialized: filter jobs by :attr:`JobDescription.materialized` flag.

:param bool being_dropped: filter jobs by :attr:`JobDescription.being_dropped` flag.

:param bool logs_removed: filter jobs by :attr:`JobDescription.logs_removed` flag.


:return: asynchronous iterator which emits :class:`JobDescription` objects.


Expand Down Expand Up @@ -708,19 +698,9 @@ JobDescription
cannot be scheduled because the lack of computation
cluster resources (memory, CPU/GPU etc), :class:`float`

.. attribute:: materialized

Is low-level execution instance (e.g. k8s pod) exists for this job, :class:`bool`

.. attribute:: being_dropped

Is this job being removed from servers database. Some functionality can
work improperly for such job. :class:`bool`

.. attribute:: logs_removed
.. attribute:: _internal

Is logs were removed from this job. This flag can only be set when
:attr:`~JobDescription.being_dropped` flag is set. :class:`bool`
Some internal info about job used by platform. Should not be used.


JobRestartPolicy
Expand Down
37 changes: 22 additions & 15 deletions neuro-sdk/src/neuro_sdk/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,13 @@ def __repr__(self) -> str:
return repr(self.value)


@dataclass(frozen=True)
class JobDescriptionInternal:
materialized: bool = False
being_dropped: bool = False
logs_removed: bool = False


@dataclass(frozen=True)
class JobDescription:
id: str
Expand All @@ -220,9 +227,7 @@ class JobDescription:
preset_name: Optional[str] = None
preemptible_node: bool = False
privileged: bool = False
materialized: bool = False
being_dropped: bool = False
logs_removed: bool = False
_internal: JobDescriptionInternal = JobDescriptionInternal()


@dataclass(frozen=True)
Expand Down Expand Up @@ -407,9 +412,9 @@ async def list(
reverse: bool = False,
limit: Optional[int] = None,
cluster_name: Optional[str] = None,
materialized: Optional[bool] = None,
being_dropped: Optional[bool] = False,
logs_removed: Optional[bool] = False,
_materialized: Optional[bool] = None,
_being_dropped: Optional[bool] = False,
_logs_removed: Optional[bool] = False,
) -> AsyncIterator[JobDescription]:
url = self._config.api_url / "jobs"
headers = {"Accept": "application/x-ndjson"}
Expand Down Expand Up @@ -438,12 +443,12 @@ async def list(
params.add("reverse", "1")
if limit is not None:
params.add("limit", str(limit))
if materialized is not None:
params.add("materialized", str(materialized))
if being_dropped is not None:
params.add("being_dropped", str(being_dropped))
if logs_removed is not None:
params.add("logs_removed", str(logs_removed))
if _materialized is not None:
params.add("materialized", str(_materialized))
if _being_dropped is not None:
params.add("being_dropped", str(_being_dropped))
if _logs_removed is not None:
params.add("logs_removed", str(_logs_removed))
auth = await self._config._api_auth()
async with self._core.request(
"GET", url, headers=headers, params=params, auth=auth
Expand Down Expand Up @@ -1017,9 +1022,11 @@ def _job_description_from_api(res: Dict[str, Any], parse: Parser) -> JobDescript
life_span=life_span,
schedule_timeout=res.get("schedule_timeout", None),
preset_name=res.get("preset_name"),
materialized=res.get("materialized", False),
being_dropped=res.get("being_dropped", False),
logs_removed=res.get("logs_removed", False),
_internal=JobDescriptionInternal(
materialized=res.get("materialized", False),
being_dropped=res.get("being_dropped", False),
logs_removed=res.get("logs_removed", False),
),
)


Expand Down
4 changes: 2 additions & 2 deletions neuro-sdk/tests/test_jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -579,8 +579,8 @@ async def handler(request: web.Request) -> web.Response:
ret = await client.jobs.status("job-id")

assert ret == _job_description_from_api(JSON, client.parse)
assert ret.being_dropped
assert ret.logs_removed
assert ret._internal.being_dropped
assert ret._internal.logs_removed


async def test_status_with_http(
Expand Down

0 comments on commit 90904cc

Please sign in to comment.