Skip to content

BatchJob

Batch job.

Source code in hume/_batch/batch_job.py
class BatchJob:
    """Batch job."""

    def __init__(self, client: "HumeBatchClient", job_id: str):
        """Construct a BatchJob.

        Args:
            client (HumeBatchClient): HumeBatchClient instance.
            job_id (str): Job ID.
        """
        self._client = client
        self.id = job_id

    def get_status(self) -> BatchJobStatus:
        """Get the status of the job.

        Returns:
            BatchJobStatus: The status of the `BatchJob`.
        """
        return self.get_result().status

    def get_result(self) -> BatchJobResult:
        """Get the result of the BatchJob.

        Note that the result of a job may be fetched before the job has completed.
        You may want to use `job.await_complete()` which will wait for the job to
        reach a terminal state before returning the result.

        Returns:
            BatchJobResult: The result of the `BatchJob`.
        """
        return self._client.get_job_result(self.id)

    def await_complete(self, timeout: int = 300) -> BatchJobResult:
        """Block until the job has reached a terminal status.

        Args:
            timeout (int): Maximum time in seconds to await. If the timeout is reached
                before the job reaches a terminal state the job will continue to be processed,
                but a `HumeClientException` will be raised to the caller of `await_complete`.

        Raises:
            ValueError: If the timeout is not valid.

        Returns:
            BatchJobResult: The result of the `BatchJob`.
        """
        if timeout < 1:
            raise ValueError("timeout must be at least 1 second")

        return self._await_complete(timeout=timeout)

    # pylint: disable=unused-argument
    @retry()
    def _await_complete(self, timeout: int = 300) -> BatchJobResult:
        result = self._client.get_job_result(self.id)
        if not BatchJobStatus.is_terminal(result.status):
            raise RetryIterError
        return result

    def __repr__(self) -> str:
        """Get the string representation of the `BatchJob`.

        Returns:
            The the string representation of the `BatchJob`.
        """
        return f'Job(id="{self.id}")'

__init__(client, job_id)

Construct a BatchJob.

Parameters:

Name Type Description Default
client HumeBatchClient

HumeBatchClient instance.

required
job_id str

Job ID.

required
Source code in hume/_batch/batch_job.py
def __init__(self, client: "HumeBatchClient", job_id: str):
    """Construct a BatchJob.

    Args:
        client (HumeBatchClient): HumeBatchClient instance.
        job_id (str): Job ID.
    """
    self._client = client
    self.id = job_id

__repr__()

Get the string representation of the BatchJob.

Returns:

Type Description
str

The the string representation of the BatchJob.

Source code in hume/_batch/batch_job.py
def __repr__(self) -> str:
    """Get the string representation of the `BatchJob`.

    Returns:
        The the string representation of the `BatchJob`.
    """
    return f'Job(id="{self.id}")'

await_complete(timeout=300)

Block until the job has reached a terminal status.

Parameters:

Name Type Description Default
timeout int

Maximum time in seconds to await. If the timeout is reached before the job reaches a terminal state the job will continue to be processed, but a HumeClientException will be raised to the caller of await_complete.

300

Raises:

Type Description
ValueError

If the timeout is not valid.

Returns:

Name Type Description
BatchJobResult BatchJobResult

The result of the BatchJob.

Source code in hume/_batch/batch_job.py
def await_complete(self, timeout: int = 300) -> BatchJobResult:
    """Block until the job has reached a terminal status.

    Args:
        timeout (int): Maximum time in seconds to await. If the timeout is reached
            before the job reaches a terminal state the job will continue to be processed,
            but a `HumeClientException` will be raised to the caller of `await_complete`.

    Raises:
        ValueError: If the timeout is not valid.

    Returns:
        BatchJobResult: The result of the `BatchJob`.
    """
    if timeout < 1:
        raise ValueError("timeout must be at least 1 second")

    return self._await_complete(timeout=timeout)

get_result()

Get the result of the BatchJob.

Note that the result of a job may be fetched before the job has completed. You may want to use job.await_complete() which will wait for the job to reach a terminal state before returning the result.

Returns:

Name Type Description
BatchJobResult BatchJobResult

The result of the BatchJob.

Source code in hume/_batch/batch_job.py
def get_result(self) -> BatchJobResult:
    """Get the result of the BatchJob.

    Note that the result of a job may be fetched before the job has completed.
    You may want to use `job.await_complete()` which will wait for the job to
    reach a terminal state before returning the result.

    Returns:
        BatchJobResult: The result of the `BatchJob`.
    """
    return self._client.get_job_result(self.id)

get_status()

Get the status of the job.

Returns:

Name Type Description
BatchJobStatus BatchJobStatus

The status of the BatchJob.

Source code in hume/_batch/batch_job.py
def get_status(self) -> BatchJobStatus:
    """Get the status of the job.

    Returns:
        BatchJobStatus: The status of the `BatchJob`.
    """
    return self.get_result().status