Job Types¶
JobTypes(perfdb)
¶
Class used for handling job types. Can be accessed via perfdb.jobs.types.
Parameters:
Source code in echo_postgres/perfdb_root.py
def __init__(self, perfdb: e_pg.PerfDB) -> None:
"""Base class that all subclasses should inherit from.
Parameters
----------
perfdb : PerfDB
Top level object carrying all functionality and the connection handler.
"""
self._perfdb: e_pg.PerfDB = perfdb
get(output_type='dict')
¶
Gets all job types definitions with detailed information.
The most useful keys/columns returned are:
- id
- description
- parameters_schema
Parameters:
-
(output_type¶Literal['dict', 'DataFrame'], default:'dict') –Output type of the data. Can be one of ["dict", "DataFrame"] By default "dict"
Returns:
-
dict[str, dict[str, Any]]–In case output_type is "dict", returns a dictionary in the format {name: {attribute: value, ...}, ...}
-
DataFrame–In case output_type is "DataFrame", returns a DataFrame with the following format: index = name, columns = [attribute, ...]
Source code in echo_postgres/job_types.py
@validate_call
def get(self, output_type: Literal["dict", "DataFrame"] = "dict") -> dict[str, dict[str, Any]] | DataFrame:
"""Gets all job types definitions with detailed information.
The most useful keys/columns returned are:
- id
- description
- parameters_schema
Parameters
----------
output_type : Literal["dict", "DataFrame"], optional
Output type of the data. Can be one of ["dict", "DataFrame"]
By default "dict"
Returns
-------
dict[str, dict[str, Any]]
In case output_type is "dict", returns a dictionary in the format {name: {attribute: value, ...}, ...}
DataFrame
In case output_type is "DataFrame", returns a DataFrame with the following format: index = name, columns = [attribute, ...]
"""
query = sql.SQL("SELECT * FROM performance.job_types ORDER BY name")
with self._perfdb.conn.reconnect() as conn:
df = conn.read_to_pandas(query, post_convert="pyarrow")
df = df.set_index("name")
return df.to_dict(orient="index") if output_type == "dict" else df
get_ids()
¶
Gets all job types and their respective ids.
Returns:
-
dict[str, int]–Dictionary with all job types and their respective ids in the format {name: id, ...}.
Source code in echo_postgres/job_types.py
def get_ids(self) -> dict[str, int]:
"""Gets all job types and their respective ids.
Returns
-------
dict[str, int]
Dictionary with all job types and their respective ids in the format {name: id, ...}.
"""
query = sql.SQL("SELECT name, id FROM performance.job_types ORDER BY name")
with self._perfdb.conn.reconnect() as conn:
df = conn.read_to_pandas(query)
return df.set_index("name").to_dict()["id"]