Skip to content

Commit de2ae1e

Browse files
authored
Merge pull request #418 from HTTP-APIs/revert-417-develop
Revert "Develop (#417)"
2 parents 16a0df8 + b5b97e8 commit de2ae1e

16 files changed

Lines changed: 444 additions & 1131 deletions

cli.py

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
from sqlalchemy.orm import sessionmaker, scoped_session
33

44
from hydrus.app_factory import app_factory
5-
from hydrus.socketio_factory import create_socket
65
from 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)
@@ -11,7 +10,6 @@
1110
from hydrus.data.db_models import Base
1211
from hydrus.data.user import add_user
1312
from hydrus.data.exceptions import UserExists
14-
from hydrus.data.stale_records_cleanup import remove_stale_modification_records
1513
from gevent.pywsgi import WSGIServer
1614
from hydra_openapi_parser.openapi_parser import parse
1715
from hydrus.samples.hydra_doc_sample import doc as api_document
@@ -29,7 +27,7 @@
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.",
@@ -44,13 +42,10 @@
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)
5146
def 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

197190
if __name__ == "__main__":

0 commit comments

Comments
 (0)