dragonfly.implementations.postgres_interface module

Some template vars

Members: PostgreSQLInterface SQLSnapshot SQLTable exception_map Functions: Classes:

A service fo interfacing with the DAQ DB (the run table in particular)

Note: services using this module will require sqlalchemy (and assuming we’re still using postgresql, psycopg2 as the sqlalchemy backend)

Summary

class dragonfly.implementations.postgres_interface.PostgreSQLInterface(database_name, database_server, **kwargs)

Bases: dragonfly.implementations.postgres_interface.PostgreSQLInterface

A not-so-flexible provider for getting run_id values.

Keyword Arguments:
 
  • database_name (str) – name of the database to connect to
  • database_server (str) – network resolvable hostname of database server
  • name (str) – unique identifier across all dripline services (used to determine routing key)
  • calibration (str||dict) – string use to process raw get result (with .format(raw)) or a dict to use for the same purpose where raw must be a key
  • get_on_set (bool) – flag to toggle running ‘on_get’ after each ‘on_set’

database_name (str): name of the database to connect to database_server (str): network resolvable hostname of database server

add_endpoint(endpoint)
cmd(target, method_name, value=[], payload={}, lockout_key=False, timeout=None, ignore_retcode=False)
endpoint(endpoint)
endpoint_names
endpoints
get(target, timeout=None, ignore_retcode=False)
handle_request(channel, method, properties, request)
is_locked
list_endpoints()
lock(*args, **kwargs)
lockout_key
logging_status
on_cmd(*args, **kwargs)

WARNING! if you override this method, you must ensure you deal with lockout properly

on_config(attribute, value=None)

configure a property again

WARNING! if you override this method, you must ensure you deal with lockout properly

on_send(*commands)
on_set(*args, **kwargs)
ping(*args, **kwargs)

ignore all details and respond with an empty message

schedule_status
set(target, value, lockout_key=False, timeout=None, ignore_retcode=False)
set_condition(*args, **kwargs)

To actually do something inside a class, the set_condition should be implemented in the class itself.

take_snapshot(start_time, end_time, metadata_target, filename)
unlock(*args, **kwargs)
class dragonfly.implementations.postgres_interface.SQLSnapshot(target_items, payload_field='value_cal', *args, **kwargs)

Bases: dragonfly.implementations.postgres_interface.SQLSnapshot

Keyword Arguments:
 
  • target_items (list) – items (str) to take snapshot of
  • payload_field (str) – field to take from database instead of value_cal
  • table_name (str) – name of the table within the database
  • schema (str) – name of the schema where the table is located
  • required_insert_names (list) – list of names (str||dict) of the table columns which must be included on every requested insert (if dict: keys are ‘column’ and ‘payload_key’, if string it is assumed that both are that value)
  • return_col_names (list) – list of names (str) of columns whose values should be returned on completion of the insert
  • optional_insert_names (list) – list of names (str||dict) of columns which the user may specify on an insert request, but which may be omitted (if dict: keys are ‘column’ and ‘payload_key’, if string it is assumed that both are that value)
  • default_insert_values (dict) – dictionary of {column_names: values} to serve as defaults when inserting, any values provided explicitly on the insert request will override these values
  • name (str) – unique identifier across all dripline services (used to determine routing key)
  • calibration (str||dict) – string use to process raw get result (with .format(raw)) or a dict to use for the same purpose where raw must be a key
  • get_on_set (bool) – flag to toggle running ‘on_get’ after each ‘on_set’

target_items (list): items (str) to take snapshot of payload_field (str): field to take from database instead of value_cal

do_insert(*args, **kwargs)
do_select(return_cols=[], where_eq_dict={}, where_lt_dict={}, where_gt_dict={})

return_cols (list of str): string names of columns, internally converted to sql reference; if evaluates as false, all columns are returned where_eq_dict (dict): keys are column names (str), and values are tested with ‘==’ where_lt_dict (dict): keys are column names (str), and values are tested with ‘<’ where_gt_dict (dict): keys are column names (str), and values are tested with ‘>’

Other select “where” statements are not supported

Returns: a tuple, 1st element is list of column names, 2nd is a list of tuples of the rows that matched the select

get_latest(timestamp, endpoint_list)

Method to retrieve last database value for all endpoints in list. Used as part of standard DAQ operation timestamp (str): timestamp upper bound for selection. Format must follow constants.TIME_FORMAT, i.e. YYYY-MM-DDThh:mm:ssZ endpoint_list (list): list of endpoint names (str) of interest. Usage for dragonfly CLI e.g. endpoint_list=’[“endpoint_name1”,”endpoint_name_2”,…]’

get_logs(start_timestamp, end_timestamp)

Method to retrieve all database values for all endpoints between two timestamps. Used as part of standard DAQ operation Both input timestamps must be follow the format of constants.TIME_FORMAT, i.e. YYYY-MM-DDThh:mm:ssZ start_timestamp (str): oldest timestamp for query into database ending_timesamp (str): most recent timestamp for query into database

get_single_log(start_timestamp, end_timestamp, *args)

Method to retrieve all database values for subset of endpoints between two timestamps. Both input timestamps must be follow the format of constants.TIME_FORMAT, i.e. YYYY-MM-DDThh:mm:ssZ start_timestamp (str): oldest timestamp for query into database ending_timesamp (str): most recent timestamp for query into database *args: list of endpoints of interest

handle_request(channel, method, properties, request)
is_locked
lock(lockout_key=None, *args, **kwargs)
lockout_key
on_cmd(*args, **kwargs)

WARNING! if you override this method, you must ensure you deal with lockout properly

on_config(attribute, value=None)

configure a property again

WARNING! if you override this method, you must ensure you deal with lockout properly

ping(*args, **kwargs)

ignore all details and respond with an empty message

set_condition(*args, **kwargs)

To actually do something inside a class, the set_condition should be implemented in the class itself.

unlock(*args, **kwargs)
class dragonfly.implementations.postgres_interface.SQLTable(table_name, schema, required_insert_names=[], return_col_names=[], optional_insert_names=[], default_insert_values={}, *args, **kwargs)

Bases: dragonfly.implementations.postgres_interface.SQLTable

A class for making calls to _insert_with_return

Keyword Arguments:
 
  • table_name (str) – name of the table within the database
  • schema (str) – name of the schema where the table is located
  • required_insert_names (list) – list of names (str||dict) of the table columns which must be included on every requested insert (if dict: keys are ‘column’ and ‘payload_key’, if string it is assumed that both are that value)
  • return_col_names (list) – list of names (str) of columns whose values should be returned on completion of the insert
  • optional_insert_names (list) – list of names (str||dict) of columns which the user may specify on an insert request, but which may be omitted (if dict: keys are ‘column’ and ‘payload_key’, if string it is assumed that both are that value)
  • default_insert_values (dict) – dictionary of {column_names: values} to serve as defaults when inserting, any values provided explicitly on the insert request will override these values
  • name (str) – unique identifier across all dripline services (used to determine routing key)
  • calibration (str||dict) – string use to process raw get result (with .format(raw)) or a dict to use for the same purpose where raw must be a key
  • get_on_set (bool) – flag to toggle running ‘on_get’ after each ‘on_set’

table_name (str): name of the table within the database schema (str): name of the schema where the table is located required_insert_names (list): list of names (str||dict) of the table columns which must be included on every requested insert (if dict: keys are ‘column’ and ‘payload_key’, if string it is assumed that both are that value) return_col_names (list): list of names (str) of columns whose values should be returned on completion of the insert optional_insert_names (list): list of names (str||dict) of columns which the user may specify on an insert request, but which may be omitted (if dict: keys are ‘column’ and ‘payload_key’, if string it is assumed that both are that value) default_insert_values (dict): dictionary of {column_names: values} to serve as defaults when inserting, any values provided explicitly on the insert request will override these values

do_insert(*args, **kwargs)
do_select(return_cols=[], where_eq_dict={}, where_lt_dict={}, where_gt_dict={})

return_cols (list of str): string names of columns, internally converted to sql reference; if evaluates as false, all columns are returned where_eq_dict (dict): keys are column names (str), and values are tested with ‘==’ where_lt_dict (dict): keys are column names (str), and values are tested with ‘<’ where_gt_dict (dict): keys are column names (str), and values are tested with ‘>’

Other select “where” statements are not supported

Returns: a tuple, 1st element is list of column names, 2nd is a list of tuples of the rows that matched the select

handle_request(channel, method, properties, request)
is_locked
lock(lockout_key=None, *args, **kwargs)
lockout_key
on_cmd(*args, **kwargs)

WARNING! if you override this method, you must ensure you deal with lockout properly

on_config(attribute, value=None)

configure a property again

WARNING! if you override this method, you must ensure you deal with lockout properly

ping(*args, **kwargs)

ignore all details and respond with an empty message

set_condition(*args, **kwargs)

To actually do something inside a class, the set_condition should be implemented in the class itself.

unlock(*args, **kwargs)

End of modules condition

Data:

End of data condition