1
Fork 0
mirror of https://github.com/RYGhub/royalnet.git synced 2024-11-27 13:34:28 +00:00

Webserver stuff is complete!

This commit is contained in:
Steffo 2019-11-05 15:16:29 +01:00
parent 884b44302d
commit c2d9f747fa
3 changed files with 26 additions and 1 deletions

View file

@ -156,9 +156,17 @@ def run(telegram: typing.Optional[bool],
webserver_process: typing.Optional[multiprocessing.Process] = None
if interfaces["webserver"]:
# Common tables are always included
constellation_tables = set(r.packs.common.available_tables)
# Find the required tables
for star in [*enabled_page_stars, *enabled_exception_stars]:
constellation_tables = constellation_tables.union(star.tables)
# Create the Constellation
constellation = r.web.Constellation(page_stars=enabled_page_stars,
exc_stars=enabled_exception_stars,
secrets_name=secrets_name)
secrets_name=secrets_name,
database_uri=database,
tables=constellation_tables)
webserver_process = multiprocessing.Process(name="Constellation Webserver",
target=constellation.run_blocking,
args=(verbose,),

View file

@ -14,6 +14,8 @@ log = logging.getLogger(__name__)
class Constellation:
def __init__(self,
secrets_name: str,
database_uri: str,
tables: set,
page_stars: typing.List[typing.Type[PageStar]] = None,
exc_stars: typing.List[typing.Type[ExceptionStar]] = None,
*,
@ -29,6 +31,9 @@ class Constellation:
log.info("Creating starlette app...")
self.starlette = Starlette(debug=debug)
log.info(f"Creating alchemy with tables: {' '.join([table.__name__ for table in tables])}")
self.alchemy: royalnet.database.Alchemy = royalnet.database.Alchemy(database_uri=database_uri, tables=tables)
log.info("Registering page_stars...")
for SelectedPageStar in page_stars:
try:

View file

@ -14,6 +14,18 @@ class Star:
async def page(self, request: Request, **kwargs) -> Response:
raise NotImplementedError()
@property
def alchemy(self):
return self.constellation.alchemy
@property
def Session(self):
return self.constellation.alchemy.Session
@property
def session_acm(self):
return self.constellation.alchemy.session_acm
class PageStar(Star):
path: str = NotImplemented