API reference¶
JobManager¶
-
class
kubernetes_job.
JobManager
(k8s_client: kubernetes.client.api_client.ApiClient, k8s_job_spec: [<class 'dict'>, <class 'str'>], namespace: str = 'default')[source]¶ Kubernetes JobManager
- Parameters
k8s_client – Kubernetes OpenAPI client
k8s_job_spec – dict or path to YAML file containing the spec for the job worker
namespace – Kubernetes k8s_namespace (default: ‘default’)
-
clean_jobs
(field_selector=None, label_selector=None)[source]¶ Clean up completed jobs
- Parameters
field_selector – A selector to restrict the list of returned objects by their fields. Defaults to everything.
label_selector – A selector to restrict the list of returned objects by their labels. Defaults to everything.
-
create_job
(func, *func_args, **func_kwargs) → kubernetes.client.models.v1_job.V1Job[source]¶ Create a job
- Parameters
func – Function pointer
func_args – Args to submit to the function
func_kwargs – Kwargs to submit to the function
- Returns
V1Job
-
delete_job
(job: [<class 'str'>, <class 'kubernetes.client.models.v1_job.V1Job'>], grace_period_seconds: int = 0, propagation_policy: str = 'Background') → kubernetes.client.models.v1_status.V1Status[source]¶ Delete a Job
- Parameters
job – Name or V1Job instance
grace_period_seconds – (default: 0)
propagation_policy – (default: ‘Background’)
- Returns
V1Status
-
static
execute_job
(job_func_def: Optional[str] = None)[source]¶ Execute the JobFuncDef specified in the func_spec
- Parameters
job_func_def – Serialized job definition
- Returns
Job function return value (if any)
-
list_jobs
(field_selector=None, label_selector=None) → Iterator[kubernetes.client.models.v1_job.V1Job][source]¶ List job objects
- Parameters
field_selector – A selector to restrict the list of returned objects by their fields. Defaults to everything.
label_selector – A selector to restrict the list of returned objects by their labels. Defaults to everything.
- Returns
Iterator of V1Job
Helpers¶
-
kubernetes_job.
job_name
(job: [<class 'str'>, <class 'kubernetes.client.models.v1_job.V1Job'>]) → str[source]¶ Return the name of a job
-
kubernetes_job.
job_status
(job: kubernetes.client.models.v1_job.V1Job) → str[source]¶ Return SUCCEEDED, FAILED, ACTIVE, or PENDING, depending on the status of the job
-
kubernetes_job.
is_completed
(job: kubernetes.client.models.v1_job.V1Job)[source]¶ Return True if the job has completed (either failed or succeeded)
-
kubernetes_job.
is_succeeded
(job: kubernetes.client.models.v1_job.V1Job)[source]¶ Return True if the job has succeeded
-
kubernetes_job.
is_failed
(job: kubernetes.client.models.v1_job.V1Job)[source]¶ Return True if the job is failed
-
kubernetes_job.
is_active
(job: kubernetes.client.models.v1_job.V1Job)[source]¶ Return True if the job is active (running)
-
kubernetes_job.
current_job
=kubernetes_job.job_func_def.JobFuncDef¶ Current JobFuncDef when executing a Kubernetes-job (as runner), otherwise None.
job_func_def¶
job_func_def contains helper classes for the serialization and execution of the function call.
-
class
kubernetes_job.job_func_def.
JobFuncDef
(func, args=None, kwargs=None, meta: Optional[kubernetes_job.job_func_def.JobMeta] = None)[source]¶ Helper class to hold the job function definition
- Parameters
func – Pointer to the job function
args – Args for the job function
kwargs – Kwargs for the job function
meta – Metadata for the job
-
args
= None¶ Args for the job function
-
func
= None¶ Pointer to the job function
-
kwargs
= None¶ Kwargs for the job function
-
static
load
(s: str) → kubernetes_job.job_func_def.JobFuncDef[source]¶ Load the job function definition from a base64 string
-
meta
: kubernetes_job.job_func_def.JobMeta = None¶ Metadata for the job
-
class
kubernetes_job.job_func_def.
JobMeta
[source]¶ Helper class to hold job meta information
-
dt_scheduled
: <module ‘datetime’ from ‘/home/docs/.pyenv/versions/3.7.9/lib/python3.7/datetime.py’> = datetime.datetime(1, 1, 1, 0, 0)¶ Job scheduled datetime
-
host
: str = '[HOST]'¶ Host responsible for spawning the job
-
name
: str = '[JOB-NAME]'¶ Unique job name
-