Commit 58b0d2f9 authored by BO ZHANG's avatar BO ZHANG 🏀
Browse files

update redis config

parent 01958442
import redis import redis
import toml import toml
import os import os
from csst_dfs_client import plan, level0
from astropy.table import Table
CONFIG = toml.load(os.path.join(os.path.dirname(__file__), "config", "config.toml")) CONFIG = toml.load(os.path.join(os.path.dirname(__file__), "config", "config.toml"))
class DFS: class DFS:
def __init__(self, location="naoc"): def __init__(self, location=None):
if location not in CONFIG.keys(): # try each location
print("Available DFS locations: ", list(CONFIG.keys())) print("Test all locations:")
raise ValueError(f"Unknown dfs location: {location}") status_list = []
self.location = location for loc in CONFIG.keys():
self.config = CONFIG[location] # print("Setting DFS config:")
print("Setting DFS config:") for k, v in CONFIG[loc]["dfs"].items():
for k, v in self.config["dfs"].items():
if k not in os.environ.keys():
os.environ.setdefault(k, str(v)) os.environ.setdefault(k, str(v))
print(f" - Set {k}: {v}") # print("Setting redis config:")
else: redis = Redis(location=loc)
print(f" - {k}: {os.environ[k]}") this_dfs_status = plan.find(instrument="").success
try:
this_redis_status = redis.ping()
except BaseException:
this_redis_status = False
this_status = dict(
location=loc,
status=this_dfs_status and this_redis_status,
dfs=this_dfs_status,
redis=this_redis_status,
)
status_list.append(this_status)
status_table = Table(status_list)
print(status_table)
self.redis = Redis(location) if status_table["status"].sum() == 0:
raise ValueError("No DFS location is available")
elif status_table["status"].sum() > 1:
print("Multiple DFS locations are available, please specify one")
raise ValueError("Multiple DFS locations are available")
else:
self.location = status_table["location"][status_table["status"]][0]
self.config = CONFIG[self.location]
print(f"Using DFS location: {location}")
for k, v in CONFIG[loc]["dfs"].items():
os.environ.setdefault(k, str(v))
# print("Setting redis config:")
self.redis = Redis(location=loc)
class Redis(redis.Redis): class Redis(redis.Redis):
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment