mockslurm.process_db
Implements the access to a "slurm database", stored in a HDF5 file.
HDF5 files are locked during access, which provides a convenient method to not have several process modifying the same database easily
Functions:
| Name | Description |
|---|---|
append_job |
Append a job to the database |
clear_db |
Deletes the database file. |
find_db_file |
Return a path to the location of the mock database hdf5 file. |
get_db |
Get the Database as a dataset in the HDF5 file |
get_db_file_handle |
Open the database HDF5 file in append mode. |
get_filtered_DB_mask |
Get a mask selecting the DB rows where the field values are equal to |
open_file_retry_on_locked |
Open |
update_db_value |
Update the |
update_with_default_value |
Update |
append_job
Append a job to the database
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
db_file
|
File
|
Opened file handle to the database |
required |
Returns:
| Type | Description |
|---|---|
int
|
Index of the job that was appended |
Source code in src/mockslurm/process_db.py
clear_db
find_db_file
Return a path to the location of the mock database hdf5 file.
The database file location is searched among various locations typically available.
Returns:
| Type | Description |
|---|---|
Path
|
Path to the mock database hdf5 file. |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If a suitable location for the database file could not be found. |
Source code in src/mockslurm/process_db.py
get_db
Get the Database as a dataset in the HDF5 file
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
db_file
|
File
|
Opened database file handle |
required |
Returns:
| Type | Description |
|---|---|
Dataset
|
Dataset storing the database |
Source code in src/mockslurm/process_db.py
get_db_file_handle
Open the database HDF5 file in append mode.
On success, the returned h5py.File contains a dataset with the expected dtypes of the database.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
db_file
|
Path
|
Path to the database file to open |
required |
Returns:
| Type | Description |
|---|---|
File
|
File handle to the database |
Source code in src/mockslurm/process_db.py
get_filtered_DB_mask
Get a mask selecting the DB rows where the field values are equal to fields_values values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
db_file
|
File
|
Opened file handle to the database HDF5 file |
required |
fields_values
|
Dict[str, str | List[str]]
|
Map from fields to allowed fields values. Rows where the fields value is not equal to one of the field values are not selected. Key: field name, eg "NAME", "USER" values: field value, eg "Robert", ["Robert", "Roberta"] |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
Index mask array, True where the row's fields are equal to the |
Source code in src/mockslurm/process_db.py
open_file_retry_on_locked
Open file as an HDF5 file in mode.
Since the HDF5 files are locked when another process access them, this function tries to open the file a certain number of time.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file
|
Path
|
Path to the file to open |
required |
nb_retries
|
int
|
Number of times to try to open the file, by default 40 |
40
|
wait_s
|
float
|
Amount of time to wait between 2 attempts to open the file, in seconds, by default 0.1 |
0.01
|
Returns:
| Type | Description |
|---|---|
File
|
Open file handle to |
Source code in src/mockslurm/process_db.py
update_db_value
Update the value of key in the database, at index
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
db_file
|
File
|
Opened file handle to the database HDF5 file |
required |
index
|
int
|
Index of the row to update |
required |
key
|
str
|
Field to update |
required |
value
|
Any
|
New value for the field |
required |
Source code in src/mockslurm/process_db.py
update_with_default_value
Update db_dict missing fields with the default value in the database
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
db_dict
|
Dict
|
dict containing a database row data, possibly missing some columns to be filled with default values |
required |
Returns:
| Type | Description |
|---|---|
Dict
|
dict with all fields expected by the database present, with |