Skip to content

Commit

Permalink
Interface backend service no longer resets settings on startup.
Browse files Browse the repository at this point in the history
Closes #23
  • Loading branch information
DoctressWasTaken committed Feb 19, 2022
1 parent dbf64e1 commit 21d3a7e
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion drakebane/backend/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ def __init__(self):
self.settings = json.loads(settings.read())
with open("settings.json", "w+") as settings:
json.dump(self.settings, settings, indent=2, sort_keys=True)
asyncio.run(self.update_settings())
if asyncio.run(self.get_settings()):
asyncio.run(self.update_settings())
self.app = web.Application()
cors = aiohttp_cors.setup(
self.app,
Expand Down Expand Up @@ -55,5 +56,20 @@ async def update_settings(self):
else:
await con.set("service_%s" % key, "false")

async def get_settings(self):
"""Pull settings from redis if the exist."""
con = await aioredis.from_url(
"redis://redis:6379", encoding="utf-8", decode_responses=True
)
if not await con.exists("settings_set"):
return 1
self.settings["regions"] = json.loads(con.get("regions"))
self.settings["apiKey"] = con.get("apiKey")
for key in self.settings["services"]:
if await con.get("service_%s" % key) == "true":
self.settings["services"][key] = True
else:
self.settings["services"][key] = False

def run(self):
web.run_app(self.app, port=8302)

0 comments on commit 21d3a7e

Please sign in to comment.