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

update redis config

parent 01958442
import redis
import toml
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"))
class DFS:
def __init__(self, location="naoc"):
if location not in CONFIG.keys():
print("Available DFS locations: ", list(CONFIG.keys()))
raise ValueError(f"Unknown dfs location: {location}")
self.location = location
self.config = CONFIG[location]
print("Setting DFS config:")
for k, v in self.config["dfs"].items():
if k not in os.environ.keys():
def __init__(self, location=None):
# try each location
print("Test all locations:")
status_list = []
for loc in CONFIG.keys():
# print("Setting DFS config:")
for k, v in CONFIG[loc]["dfs"].items():
os.environ.setdefault(k, str(v))
print(f" - Set {k}: {v}")
else:
print(f" - {k}: {os.environ[k]}")
# print("Setting redis config:")
redis = Redis(location=loc)
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):
......
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