forked from archiver_config/sf_databuffer
add update of channel cache
This commit is contained in:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user