Add app to server Mayan EDMS using tornado.
This commit is contained in:
3
mayan/apps/server/__init__.py
Normal file
3
mayan/apps/server/__init__.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
default_app_config = 'server.apps.ServerApp'
|
||||
13
mayan/apps/server/apps.py
Normal file
13
mayan/apps/server/apps.py
Normal 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()
|
||||
0
mayan/apps/server/management/__init__.py
Normal file
0
mayan/apps/server/management/__init__.py
Normal file
0
mayan/apps/server/management/commands/__init__.py
Normal file
0
mayan/apps/server/management/commands/__init__.py
Normal file
68
mayan/apps/server/management/commands/serve.py
Executable file
68
mayan/apps/server/management/commands/serve.py
Executable 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()
|
||||
@@ -75,6 +75,7 @@ INSTALLED_APPS = (
|
||||
'mimetype',
|
||||
'navigation',
|
||||
'permissions',
|
||||
'server',
|
||||
'smart_settings',
|
||||
'user_management',
|
||||
# Mayan EDMS
|
||||
|
||||
Reference in New Issue
Block a user