Skip to content

Commit

Permalink
Added asynchronicity to the backend and boilerplate services
Browse files Browse the repository at this point in the history
  • Loading branch information
sellnat77 committed Nov 20, 2019
1 parent 27d71c1 commit b813bb9
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 10 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,5 @@ package-lock.json
config.js
.env
settings.cfg

__pycache__/
20 changes: 19 additions & 1 deletion server/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,24 @@
aiofiles==0.4.0
certifi==2019.9.11
chardet==3.0.4
Click==7.0
Flask==1.1.1
h11==0.8.1
h2==3.1.1
hpack==3.0.0
httpcore==0.3.0
httptools==0.0.13
hyperframe==5.2.0
idna==2.8
itsdangerous==1.1.0
Jinja2==2.10.3
MarkupSafe==1.1.1
multidict==4.5.2
requests==2.22.0
requests-async==0.5.0
rfc3986==1.3.2
sanic==19.9.0
ujson==1.35
urllib3==1.25.7
uvloop==0.14.0
websockets==8.1
Werkzeug==0.16.0
34 changes: 26 additions & 8 deletions server/src/app.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,36 @@
import os
import json
from flask import Flask
from sanic import Sanic
from sanic.response import json
from services.time_to_close import time_to_close
from services.frequency import frequency

app = Flask(__name__)
app = Sanic(__name__)
app.config.from_pyfile(os.path.join(os.getcwd(),'settings.cfg'))

@app.route('/')
def index():
return 'You hit the index'
async def index(request):
return json('You hit the index')

@app.route('/timetoclose')
async def timetoclose(request):
ttc_worker = time_to_close()
# Insert time to close calculation here
return_data = ttc_worker.hello_world()

return json(return_data)

@app.route('/requestfrequency')
async def requestfrequency(request):
freq_worker = frequency()
# Insert frequency calculation here
return_data = freq_worker.hello_world()

return json(return_data)

@app.route('/sample-data')
def sample_route():
async def sample_route(request):
sample_dataset = {'cool_key':['value1', 'value2'], app.config['REDACTED']:app.config['REDACTED']}
return json.dumps(sample_dataset, indent=4)
return json(sample_dataset)

if __name__ == '__main__':
app.run()
app.run(host=app.config['HOST'], port=app.config['PORT'], debug=app.config['DEBUG'])
Empty file added server/src/services/__init__.py
Empty file.
6 changes: 6 additions & 0 deletions server/src/services/frequency.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class frequency(object):
def __init__(self):
pass

def hello_world(self):
return {'response':'hello from frequency service'}
6 changes: 6 additions & 0 deletions server/src/services/time_to_close.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class time_to_close(object):
def __init__(self):
pass

def hello_world(self):
return {'response':'hello from time to close service'}
5 changes: 4 additions & 1 deletion server/src/settings.example.cfg
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
REDACTED=REDACTED
DEBUG=True
HOST="0.0.0.0"
PORT="5000"
REDACTED = "REDACTED"

0 comments on commit b813bb9

Please sign in to comment.