Job class
- class almapiwrapper.config.Job(job_id: str, zone: str, env: Literal['P', 'S'] = 'P', job_type: Literal['M', 'S', 'O'] = 'M')
Bases:
RecordRepresents an Alma job and provides access to its execution instances.
This class allows you to: - list job execution instances, - retrieve detailed information about a specific instance, - monitor the execution state of an instance.
- Parameters:
job_id (str) – Alma job identifier.
zone (str) – Job zone (e.g.
NZ).env (str) – Entity environment:
'P'for production,'S'for sandbox.job_type (str) – Job type:
'M'for manual,'S'for scheduled.
- Variables:
job_id – Job identifier.
zone – Job zone.
env – Environment (
'P'or'S').job_type – Job type (
'M'or'S').instance_id – Current instance identifier.
area – API area is
'Conf'.format – API response format (default:
'xml').
Example
Example showing how to query a job and monitor an execution instance:
from almapiwrapper.config import Job from almapiwrapper.configlog import config_log # Initialize logging config_log() # Create the job job = Job(job_id="135", zone="NZ") # Retrieve all job instances instances = job.get_instances() print(instances) # Retrieve detailed information for a specific instance instance_id = "55493478870005501" instance = job.get_instance_info(instance_id) print(instance) # Access counters returned by the job counters = instance.content["counter"] print(counters) # Check execution state of the instance state = job.check_instance_state(instance_id) print(state)
- static api_call(method: Literal['get', 'put', 'post', 'delete'], *args, **kwargs) Response | None
Static method to handle http errors. Quit the program after 3 failed tries
- Parameters:
method – ‘get’, ‘put’, ‘post’ or ‘delete’ according to the api method call
- static build_headers(data_format: Literal['json', 'xml'], zone: str, area: str, rights: Literal['R', 'RW'] = 'RW', env: Literal['P', 'S'] | None = 'P') Dict
Build the headers for the API calls.
- Parameters:
data_format – “json” or “xml”
zone – optional, if indicated allow to make the query in an other IZ
area – area of the record, bibs, users for example
rights – “R” for read only or “RW” for write and read rights
env – environment of the api call: ‘P’ for production, ‘S’ for sandbox
- Returns:
dict with the headers
- check_instance_state(instance_id: str | None = None) Dict | None
Check the state of the provided instance id or of instance started with
almapiwrapper.config.Job.run()- Parameters:
instance_id – optional parameter indicating the instance to check. If not provided it will use the instance id of a job started
Note
If the record encountered an error, this method will be skipped.
- property data: Dict | Element | DataFrame | None
Property that get xml data with API call. If not available, make an api call
- Returns:
xml data, dictionary or pandas dataframe
- get_instance_info(instance_id: str | None = None) 'JsonData' | None
Get information about a specif job instance
- Parameters:
instance_id – optional parameter indicating the instance to check. If not provided it will use the instance id of a job started
- Returns:
almapiwrapper.record.JsonDatawith the details of a job instance return None in case of error
Note
If the record encountered an error, this method will be skipped.
- get_instances(self) 'JsonData' | None
Get the list of the instances of a job in json format
- Returns:
almapiwrapper.record.JsonDatawith the list of job instances return None in case of error
Note
If the record encountered an error, this method will be skipped.
- static parse_data(data: JsonData | XmlData | Dict | str) JsonData | XmlData | None
Parse the data and return a parsed data object or None if an error occurs
- Parameters:
data – data to be parsed
- Returns:
parsed data object or None if an error occurs
- run(parameters: str | 'XmlData' | None = '<job/>') 'XmlData' | None
Run the job with the provided parameters
- Parameters:
parameters –
almapiwrapper.record.XmlDataor string with the parameters to use for the job. For some jobs no parameters are required.- Returns:
almapiwrapper.record.XmlDatawith the instance of the job or None in case of error.
Note
If the record encountered an error, this method will be skipped.