22from sqlalchemy .orm import sessionmaker , scoped_session
33
44from hydrus .app_factory import app_factory
5- from hydrus .socketio_factory import create_socket
65from hydrus .utils import (set_session , set_doc , set_hydrus_server_url ,
76 set_token , set_api_name , set_authentication ,
87 set_page_size , set_pagination )
1110from hydrus .data .db_models import Base
1211from hydrus .data .user import add_user
1312from hydrus .data .exceptions import UserExists
14- from hydrus .data .stale_records_cleanup import remove_stale_modification_records
1513from gevent .pywsgi import WSGIServer
1614from hydra_openapi_parser .openapi_parser import parse
1715from hydrus .samples .hydra_doc_sample import doc as api_document
2927 help = "The API name." , type = str )
3028@click .option ("--auth/--no-auth" , default = True ,
3129 help = "Set authentication to True or False." )
32- @click .option ("--dburl" , default = "sqlite:///database.db " ,
30+ @click .option ("--dburl" , default = "sqlite:///:memory: " ,
3331 help = "Set database url" , type = str )
3432@click .option ("--hydradoc" , "-d" , default = None ,
3533 help = "Location to HydraDocumentation (JSON-LD) of server." ,
4442 help = "Toggle token based user authentication." )
4543@click .option ("--serverurl" , default = "http://localhost" ,
4644 help = "Set server url" , type = str )
47- @click .option ("--stale_records_removal_interval" , default = 900 ,
48- help = "Interval period between removal of stale modification records." ,
49- type = int )
5045@click .argument ("serve" , required = True )
5146def startserver (adduser : Tuple , api : str , auth : bool , dburl : str , pagination : bool ,
5247 hydradoc : str , port : int , pagesize : int , serverurl : str , token : bool ,
53- stale_records_removal_interval : int , serve : None ) -> None :
48+ serve : None ) -> None :
5449 """
5550 Python Hydrus CLI
5651
@@ -87,8 +82,8 @@ def startserver(adduser: Tuple, api: str, auth: bool, dburl: str, pagination: bo
8782
8883 click .echo ("Setting up the database" )
8984 # Create a connection to the database you want to use
90- engine = create_engine (DB_URL , connect_args = { 'check_same_thread' : False } )
91- Base . metadata . drop_all ( engine )
85+ engine = create_engine (DB_URL )
86+
9287 click .echo ("Creating models" )
9388 # Add the required Models to the database
9489 Base .metadata .create_all (engine )
@@ -164,8 +159,6 @@ def startserver(adduser: Tuple, api: str, auth: bool, dburl: str, pagination: bo
164159 # Create a Hydrus app with the API name you want, default will be "api"
165160 app = app_factory (API_NAME )
166161 # Set the name of the API
167- # Create a socket for the app
168- socketio = create_socket (app , session )
169162 click .echo ("Starting the application" )
170163 with set_authentication (app , auth ):
171164 # Use authentication for all requests
@@ -181,17 +174,17 @@ def startserver(adduser: Tuple, api: str, auth: bool, dburl: str, pagination: bo
181174 with set_pagination (app , pagination ):
182175 # Set page size of a collection view
183176 with set_page_size (app , pagesize ):
184- # Run a thread to remove stale modification records at some
185- # interval of time.
186- remove_stale_modification_records (
187- session , stale_records_removal_interval )
188177 # Start the hydrus app
189- socketio . run ( app , port = port )
178+ http_server = WSGIServer (( '' , port ), app )
190179 click .echo ("Server running at:" )
191180 click .echo (
192181 "{}{}" .format (
193182 HYDRUS_SERVER_URL ,
194183 API_NAME ))
184+ try :
185+ http_server .serve_forever ()
186+ except KeyboardInterrupt :
187+ pass
195188
196189
197190if __name__ == "__main__" :
0 commit comments