Back to Prefect

jobs

docs/integrations/prefect-kubernetes/api-ref/prefect_kubernetes-jobs.mdx

3.6.30.dev310.7 KB
Original Source

prefect_kubernetes.jobs

Module to define tasks for interacting with Kubernetes jobs.

Functions

create_namespaced_job <sup><a href="https://github.com/PrefectHQ/prefect/blob/main/src/integrations/prefect-kubernetes/prefect_kubernetes/jobs.py#L33" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>

python
create_namespaced_job(kubernetes_credentials: KubernetesCredentials, new_job: Union[V1Job, Dict[str, Any]], namespace: Optional[str] = 'default', **kube_kwargs: Dict[str, Any]) -> V1Job

Task for creating a namespaced Kubernetes job.

Args:

  • kubernetes_credentials: KubernetesCredentials block holding authentication needed to generate the required API client.
  • new_job: A Kubernetes V1Job specification.
  • namespace: The Kubernetes namespace to create this job in.
  • **kube_kwargs: Optional extra keyword arguments to pass to the Kubernetes API (e.g. {"pretty"\: "...", "dry_run"\: "..."}).

Returns:

  • A Kubernetes V1Job object.

delete_namespaced_job <sup><a href="https://github.com/PrefectHQ/prefect/blob/main/src/integrations/prefect-kubernetes/prefect_kubernetes/jobs.py#L77" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>

python
delete_namespaced_job(kubernetes_credentials: KubernetesCredentials, job_name: str, delete_options: Optional[V1DeleteOptions] = None, namespace: Optional[str] = 'default', **kube_kwargs: Dict[str, Any]) -> V1Status

Task for deleting a namespaced Kubernetes job.

Args:

  • kubernetes_credentials: KubernetesCredentials block holding authentication needed to generate the required API client.
  • job_name: The name of a job to delete.
  • delete_options: A Kubernetes V1DeleteOptions object.
  • namespace: The Kubernetes namespace to delete this job in.
  • **kube_kwargs: Optional extra keyword arguments to pass to the Kubernetes API (e.g. {"pretty"\: "...", "dry_run"\: "..."}).

Returns:

  • A Kubernetes V1Status object.

list_namespaced_job <sup><a href="https://github.com/PrefectHQ/prefect/blob/main/src/integrations/prefect-kubernetes/prefect_kubernetes/jobs.py#L127" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>

python
list_namespaced_job(kubernetes_credentials: KubernetesCredentials, namespace: Optional[str] = 'default', **kube_kwargs: Dict[str, Any]) -> V1JobList

Task for listing namespaced Kubernetes jobs.

Args:

  • kubernetes_credentials: KubernetesCredentials block holding authentication needed to generate the required API client.
  • namespace: The Kubernetes namespace to list jobs from.
  • **kube_kwargs: Optional extra keyword arguments to pass to the Kubernetes API (e.g. {"pretty"\: "...", "dry_run"\: "..."}).

Returns:

  • A Kubernetes V1JobList object.

patch_namespaced_job <sup><a href="https://github.com/PrefectHQ/prefect/blob/main/src/integrations/prefect-kubernetes/prefect_kubernetes/jobs.py#L167" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>

python
patch_namespaced_job(kubernetes_credentials: KubernetesCredentials, job_name: str, job_updates: V1Job, namespace: Optional[str] = 'default', **kube_kwargs: Dict[str, Any]) -> V1Job

Task for patching a namespaced Kubernetes job.

Args:

  • kubernetes_credentials: KubernetesCredentials block holding authentication needed to generate the required API client.
  • job_name: The name of a job to patch.
  • job_updates: A Kubernetes V1Job specification.
  • namespace: The Kubernetes namespace to patch this job in.
  • **kube_kwargs: Optional extra keyword arguments to pass to the Kubernetes API (e.g. {"pretty"\: "...", "dry_run"\: "..."}).

Raises:

  • ValueError: if job_name is None.

Returns:

  • A Kubernetes V1Job object.

read_namespaced_job <sup><a href="https://github.com/PrefectHQ/prefect/blob/main/src/integrations/prefect-kubernetes/prefect_kubernetes/jobs.py#L220" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>

python
read_namespaced_job(kubernetes_credentials: KubernetesCredentials, job_name: str, namespace: Optional[str] = 'default', **kube_kwargs: Dict[str, Any]) -> V1Job

Task for reading a namespaced Kubernetes job.

Args:

  • kubernetes_credentials: KubernetesCredentials block holding authentication needed to generate the required API client.
  • job_name: The name of a job to read.
  • namespace: The Kubernetes namespace to read this job in.
  • **kube_kwargs: Optional extra keyword arguments to pass to the Kubernetes API (e.g. {"pretty"\: "...", "dry_run"\: "..."}).

Raises:

  • ValueError: if job_name is None.

Returns:

  • A Kubernetes V1Job object.

replace_namespaced_job <sup><a href="https://github.com/PrefectHQ/prefect/blob/main/src/integrations/prefect-kubernetes/prefect_kubernetes/jobs.py#L266" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>

python
replace_namespaced_job(kubernetes_credentials: KubernetesCredentials, job_name: str, new_job: V1Job, namespace: Optional[str] = 'default', **kube_kwargs: Dict[str, Any]) -> V1Job

Task for replacing a namespaced Kubernetes job.

Args:

  • kubernetes_credentials: KubernetesCredentials block holding authentication needed to generate the required API client.
  • job_name: The name of a job to replace.
  • new_job: A Kubernetes V1Job specification.
  • namespace: The Kubernetes namespace to replace this job in.
  • **kube_kwargs: Optional extra keyword arguments to pass to the Kubernetes API (e.g. {"pretty"\: "...", "dry_run"\: "..."}).

Returns:

  • A Kubernetes V1Job object.

read_namespaced_job_status <sup><a href="https://github.com/PrefectHQ/prefect/blob/main/src/integrations/prefect-kubernetes/prefect_kubernetes/jobs.py#L313" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>

python
read_namespaced_job_status(kubernetes_credentials: KubernetesCredentials, job_name: str, namespace: Optional[str] = 'default', **kube_kwargs: Dict[str, Any]) -> V1Job

Task for fetching status of a namespaced Kubernetes job.

Args:

  • kubernetes_credentials: KubernetesCredentials block holding authentication needed to generate the required API client.
  • job_name: The name of a job to fetch status for.
  • namespace: The Kubernetes namespace to fetch status of job in.
  • **kube_kwargs: Optional extra keyword arguments to pass to the Kubernetes API (e.g. {"pretty"\: "...", "dry_run"\: "..."}).

Returns:

  • A Kubernetes V1JobStatus object.

Classes

KubernetesJobRun <sup><a href="https://github.com/PrefectHQ/prefect/blob/main/src/integrations/prefect-kubernetes/prefect_kubernetes/jobs.py#L355" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>

A container representing a run of a Kubernetes job.

Methods:

afetch_result <sup><a href="https://github.com/PrefectHQ/prefect/blob/main/src/integrations/prefect-kubernetes/prefect_kubernetes/jobs.py#L496" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>

python
afetch_result(self) -> Dict[str, Any]

Async implementation: fetch the results of the job.

Returns:

  • The logs from each of the pods in the job.

Raises:

  • ValueError: If this method is called when the job has a non-terminal state.

await_for_completion <sup><a href="https://github.com/PrefectHQ/prefect/blob/main/src/integrations/prefect-kubernetes/prefect_kubernetes/jobs.py#L392" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>

python
await_for_completion(self, print_func: Optional[Callable] = None)

Async implementation: waits for the job to complete.

If the job has delete_after_completion set to True, the job will be deleted if it is observed by this method to enter a completed state.

Raises:

  • RuntimeError: If the Kubernetes job fails.
  • KubernetesJobTimeoutError: If the Kubernetes job times out.

fetch_result <sup><a href="https://github.com/PrefectHQ/prefect/blob/main/src/integrations/prefect-kubernetes/prefect_kubernetes/jobs.py#L515" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>

python
fetch_result(self) -> Dict[str, Any]

Fetch the results of the job.

Returns:

  • The logs from each of the pods in the job.

Raises:

  • ValueError: If this method is called when the job has a non-terminal state.

v1_job_model <sup><a href="https://github.com/PrefectHQ/prefect/blob/main/src/integrations/prefect-kubernetes/prefect_kubernetes/jobs.py#L370" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>

python
v1_job_model(self) -> dict[str, Any]

wait_for_completion <sup><a href="https://github.com/PrefectHQ/prefect/blob/main/src/integrations/prefect-kubernetes/prefect_kubernetes/jobs.py#L481" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>

python
wait_for_completion(self, print_func: Optional[Callable] = None)

Waits for the job to complete.

If the job has delete_after_completion set to True, the job will be deleted if it is observed by this method to enter a completed state.

Raises:

  • RuntimeError: If the Kubernetes job fails.
  • KubernetesJobTimeoutError: If the Kubernetes job times out.

KubernetesJob <sup><a href="https://github.com/PrefectHQ/prefect/blob/main/src/integrations/prefect-kubernetes/prefect_kubernetes/jobs.py#L530" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>

A block representing a Kubernetes job configuration.

Methods:

atrigger <sup><a href="https://github.com/PrefectHQ/prefect/blob/main/src/integrations/prefect-kubernetes/prefect_kubernetes/jobs.py#L573" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>

python
atrigger(self)

Async implementation: create a Kubernetes job and return a KubernetesJobRun object.

from_yaml_file <sup><a href="https://github.com/PrefectHQ/prefect/blob/main/src/integrations/prefect-kubernetes/prefect_kubernetes/jobs.py#L592" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>

python
from_yaml_file(cls: Type[Self], manifest_path: Union[Path, str], **kwargs) -> Self

Create a KubernetesJob from a YAML file.

Args:

  • manifest_path: The YAML file to create the KubernetesJob from.

Returns:

  • A KubernetesJob object.

trigger <sup><a href="https://github.com/PrefectHQ/prefect/blob/main/src/integrations/prefect-kubernetes/prefect_kubernetes/jobs.py#L587" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>

python
trigger(self)

Create a Kubernetes job and return a KubernetesJobRun object.