Add app to server Mayan EDMS using tornado.

This commit is contained in:
Roberto Rosario
2016-03-27 05:00:13 -04:00
parent ccd6e8c88c
commit 94c4df1f5e
6 changed files with 85 additions and 0 deletions

View File

@@ -0,0 +1,3 @@
from __future__ import unicode_literals
default_app_config = 'server.apps.ServerApp'

13
mayan/apps/server/apps.py Normal file
View File

@@ -0,0 +1,13 @@
from __future__ import absolute_import, unicode_literals
from django.utils.translation import ugettext_lazy as _
from common import MayanAppConfig
class ServerApp(MayanAppConfig):
name = 'server'
verbose_name = _('Server')
def ready(self):
super(ServerApp, self).ready()

View File

View File

@@ -0,0 +1,68 @@
from __future__ import unicode_literals
from django.core import management
from django.core.wsgi import get_wsgi_application
import tornado.httpserver
import tornado.ioloop
from tornado.process import Subprocess
import tornado.web
import tornado.wsgi
DEFAULT_PORT = 52723
class Command(management.BaseCommand):
help = 'Launches a local Tornado server.'
def add_arguments(self, parser):
parser.add_argument(
'--single-process',
action='store_true',
dest='single-process',
default=False,
help='Forces only one server process.'
)
parser.add_argument(
'--port',
action='store',
dest='port',
default=DEFAULT_PORT,
help='Port on which to bind the server.'
)
def handle(self, *args, **options):
wsgi_application = get_wsgi_application()
wsgi_container = tornado.wsgi.WSGIContainer(wsgi_application)
tornado_application = tornado.web.Application(
handlers=(
(
r'/static/(.*)', tornado.web.StaticFileHandler,
{'path': 'mayan/media/static'},
),
(
'.*', tornado.web.FallbackHandler,
dict(fallback=wsgi_container)
),
)
)
http_server = tornado.httpserver.HTTPServer(tornado_application)
try:
if options['single-process']:
http_server.listen(options['port'])
ioloop = tornado.ioloop.IOLoop.instance()
Subprocess(['./manage.py', 'celery', 'worker'])
ioloop.start()
else:
http_server.bind(options['port'])
http_server.start(0) # forks one process per cpu
ioloop = tornado.ioloop.IOLoop.current()
Subprocess(['./manage.py', 'celery', 'worker'])
ioloop.start()
except KeyboardInterrupt:
tornado.ioloop.IOLoop.instance().stop()

View File

@@ -75,6 +75,7 @@ INSTALLED_APPS = (
'mimetype',
'navigation',
'permissions',
'server',
'smart_settings',
'user_management',
# Mayan EDMS