-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.py
49 lines (36 loc) · 1.39 KB
/
server.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import time, sys, cherrypy, os
from paste.translogger import TransLogger
from app import create_app
from pyspark import SparkContext, SparkConf
from pyspark.sql import SQLContext
def init_spark_context():
# load spark context
# conf = SparkConf().setAppName("movie_recommendation-server")
conf = SparkConf().setAppName("sentiment-analyser-server")
# IMPORTANT: pass additional Python modules to each worker
# sc = SparkContext(conf=conf, pyFiles=['engine.py', 'app.py'])
sc = SparkContext(conf=conf, pyFiles=['analyser.py', 'app.py'])
sql_context = SQLContext(sc)
return sc, sql_context
def run_server(app):
# Enable WSGI access logging via Paste
app_logged = TransLogger(app)
# Mount the WSGI callable object (app) on the root directory
cherrypy.tree.graft(app_logged, '/')
# Set the configuration of the web server
cherrypy.config.update({
'engine.autoreload.on': True,
'log.screen': True,
'server.socket_port': 5432,
'server.socket_host': '0.0.0.0'
})
# Start the CherryPy WSGI web server
cherrypy.engine.start()
cherrypy.engine.block()
if __name__ == "__main__":
# Init spark context and load libraries
sc, sqlContext = init_spark_context()
dataset_path = os.path.join('datasets', 'ml-latest')
app = create_app(sc, sqlContext, dataset_path)
# start web server
run_server(app)