Skip to content

Commit

Permalink
refactor(client): move function "retry" from Job to SquashAndMergeJob
Browse files Browse the repository at this point in the history
PR Closed: #1247
  • Loading branch information
graczhual committed Apr 11, 2022
1 parent 526a7e9 commit 9f0242f
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 20 deletions.
3 changes: 1 addition & 2 deletions docs/code/basic_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,8 @@
job.update(until_complete=True)
""""""

"""Abort and Retry Job"""
"""Abort Job"""
job.abort()
job.retry()
""""""

"""Create Dataset"""
Expand Down
8 changes: 4 additions & 4 deletions docs/source/features/search/basic_search.rst
Original file line number Diff line number Diff line change
Expand Up @@ -117,14 +117,14 @@ set to ``True``, the BasicSearchJob will be blocked until it is completed.
:start-after: """Update Job"""
:end-before: """"""

Abort or Retry
==============
Abort
=====

BasicSearchJob also supports :func:`~tensorbay.client.job.Job.abort` and :func:`~tensorbay.client.job.Job.retry`:
BasicSearchJob also supports :func:`~tensorbay.client.job.Job.abort`:

.. literalinclude:: ../../../../docs/code/basic_search.py
:language: python
:start-after: """Abort and Retry Job"""
:start-after: """Abort Job"""
:end-before: """"""

Create Dataset
Expand Down
2 changes: 1 addition & 1 deletion docs/source/features/version_control/squash_and_merge.rst
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ set to ``True``, the SquashAndMergeJob will be blocked until it is completed.
Abort or retry
==============

SquashAndMergeJob also supports :func:`~tensorbay.client.job.Job.abort` and :func:`~tensorbay.client.job.Job.retry`:
SquashAndMergeJob also supports :func:`~tensorbay.client.job.Job.abort` and :func:`~tensorbay.client.job.SquashAndMergeJob.retry`:

.. literalinclude:: ../../../../docs/code/squash_and_merge.py
:language: python
Expand Down
12 changes: 6 additions & 6 deletions tensorbay/client/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,12 +169,6 @@ def abort(self) -> None:
"POST", f"jobs/{self.job_id}/abort?jobType={self._job_type}", self._dataset_id
)

def retry(self) -> None:
"""Retry a :class:`Job`."""
self._client.open_api_do(
"POST", f"jobs/{self.job_id}/retry?jobType={self._job_type}", self._dataset_id
)


class SquashAndMergeJob(Job):
"""This class defines :class:`SquashAndMergeJob`.
Expand Down Expand Up @@ -296,6 +290,12 @@ def from_response_body( # type: ignore[override] # pylint: disable=arguments-d

return job

def retry(self) -> None:
"""Retry a :class:`SquashAndMergeJob`."""
self._client.open_api_do(
"POST", f"jobs/{self.job_id}/retry?jobType={self._job_type}", self._dataset_id
)


class BasicSearchJob(Job):
"""This class defines :class:`BasicSearchJob`."""
Expand Down
18 changes: 11 additions & 7 deletions tests/test_basic_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,16 @@ def init_dataset_client(accesskey, url, tmp_path_factory):

@pytest.fixture(scope="class", name="job")
def init_job(dataset_client):
job = dataset_client.basic_search.create_job(
title="basic search job example",
conjunction="AND",
unit="FILE",
filters=[("withLabel", "=", True)],
)
job.abort()
job.update()
assert job.status == "ABORTED"

job = dataset_client.basic_search.create_job(
title="basic search job example",
description="search description",
Expand All @@ -120,12 +130,6 @@ def init_job(dataset_client):
("sensor", "in", ["CAM_BACK_RIGHT"]),
],
)
job.abort()
job.update()
assert job.status == "ABORTED"
job.retry()
job.update()
assert job.status == "PROCESSING"

yield job

Expand Down Expand Up @@ -197,7 +201,7 @@ def test_job_result(self, dataset_client, job):
@pytest.mark.xfail(reason="there are still some bugs in creating and aborting job")
def test_list_jobs(self, dataset_client):
jobs = dataset_client.basic_search.list_jobs()
assert len(jobs) == 1
assert len(jobs) == 2
for job in jobs:
dataset_client.basic_search.delete_job(job.job_id)
jobs = dataset_client.basic_search.list_jobs()
Expand Down

0 comments on commit 9f0242f

Please sign in to comment.