From 062c1bce84958484bc17f369e777e1f03fc7e536 Mon Sep 17 00:00:00 2001 From: Simon Ebner Date: Tue, 16 Mar 2021 16:59:06 +0100 Subject: [PATCH] add update of channel cache --- bufferutils.py | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/bufferutils.py b/bufferutils.py index 90f519c..86044e7 100644 --- a/bufferutils.py +++ b/bufferutils.py @@ -144,13 +144,23 @@ def upload_sources_and_policies(sources, policies): upload_files = [("files", ("all.sources", StringIO(json.dumps(sources)))), ("files", ("all.policies", StringIO(json.dumps(policies))))] + logging.info(f"Upload {len(sources['sources'])} sources and {len(policies['policies'])} policies") test_response = requests.post(upload_url, files=upload_files) if test_response.ok: logging.info("Upload completed successfully!") # print(test_response.text) else: - logging.error("Something went wrong!") + logging.error(f"Upload failed!\n{test_response.text}") + + +def update_channel_cache(): + # Update channel cache of data-api + response = requests.post("https://data-api.psi.ch/sf/channels/config", json={"reload": "true"}) + if response.ok: + logging.info("Channel cache updated successfully!") + else: + logging.error(f"Updating channel cache failed!\n{response.text}") def main(): @@ -198,10 +208,10 @@ def main(): # Just to make sure that the additional labels entry does not break the backend - remove it # sources = remove_labels(sources) - logging.info(f"Upload {len(sources['sources'])} sources and {len(policies['policies'])} policies") upload_sources_and_policies(sources, policies) - # TODO Update channels chache + # Update channels chache + update_channel_cache() # # RESTART @@ -222,14 +232,12 @@ def main(): sources_new = remove_labeled_source(sources_new, label) # Stopping the removed source(s) - logging.info(f"Upload {len(sources_new['sources'])} sources and {len(policies['policies'])} policies") upload_sources_and_policies(sources_new, policies) # Starting the source(s) again - logging.info(f"Upload {len(sources['sources'])} sources and {len(policies['policies'])} policies") upload_sources_and_policies(sources, policies) - # TODO Update channels chache + # There is no need to update the channel chache as nothing really changed else: logging.warning("Not yet implemented") parser_restart.print_usage()