Skip to content

Commit

Permalink
api - implement breeders list endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
cherusk committed Nov 17, 2023
1 parent a01dcc6 commit 38c5838
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 29 deletions.
44 changes: 15 additions & 29 deletions api/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,38 +136,24 @@ def breeders_get(): # noqa: E501
Provides info on configured breeders # noqa: E501
"""
configured_breeders = dict()

api_response = None
## fetch breeder meta data list
db_config = META_DB_CONFIG.copy()
db_config.update(dict(dbname='meta_data'))
db_table_name = 'breeder_meta_data'

with client.ApiClient(configuration) as api_client:
api_instance = dag_run_api.DAGRunApi(api_client)
__query = meta_data.queries.fetch_breeders_list(table_name=db_table_name, breeder_name=breeder_name)
breeder_meta_data_list = archive.archive_db.execute(db_info=db_config, query=__query, with_result=True)

list_dag_runs_form = ListDagRunsForm(
#order_by="order_by_example",
page_offset=0,
page_limit=10000,
dag_ids=[
"linux_network_stack_breeder", # only one dag existing so far
],
#states=[
#],
execution_date_gte=dateutil_parser('1970-01-01T00:00:00.00Z'),
execution_date_lte=dateutil_parser('1970-01-01T00:00:00.00Z'),
start_date_gte=dateutil_parser('1970-01-01T00:00:00.00Z'),
start_date_lte=dateutil_parser('1970-01-01T00:00:00.00Z'),
end_date_gte=dateutil_parser('1970-01-01T00:00:00.00Z'),
end_date_lte=dateutil_parser('1970-01-01T00:00:00.00Z'),
) # ListDagRunsForm |

# example passing only required values which don't have defaults set
try:
# List DAG runs (batch)
api_response = api_instance.get_dag_runs_batch(list_dag_runs_form)
except client.ApiException as e:
pprint("Exception when calling DAGRunApi->get_dag_runs_batch: %s\n" % e)
raise e

return api_response.to_dict()
# preformat timestamp to be stringifyable
breeder_meta_data_list = [(breeder_row[0].isoformat(),breeder_row[1]) for breeder_row in breeder_meta_data_list]

logging.error(json.dumps(breeder_meta_data_list))

return Response(response=json.dumps(dict(breeders=configured_breeders)),
status=200,
mimetype='application/json')


def breeders_name_get(breeder_name): # noqa: E501
Expand Down
7 changes: 7 additions & 0 deletions api/meta_data_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,10 @@ def fetch_meta_data(table_name=None, breeder_name=None):
"""

return query

def fetch_breeders_list(table_name=None, breeder_name=None):
query = f"""
SELECT definition->>'name',creation_tsz, FROM {table_name};
"""

return query

0 comments on commit 38c5838

Please sign in to comment.