-
Notifications
You must be signed in to change notification settings - Fork 2
/
gams2web.py
72 lines (45 loc) · 1.72 KB
/
gams2web.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
from gevent import monkey
monkey.patch_all()
from flask import Flask
from flask.ext.socketio import SocketIO
from core.api import rest_api
from core.signals import task_added, task_completed, worker_before_execution, worker_after_execution, task_deleted
from core.commands import command_manager
import settings
# Flask application
web = Flask(__name__, static_url_path='/assets')
web.config.from_object(settings)
# REST API
web.register_blueprint(rest_api, url_prefix='/api')
# WebSocket API
socket = SocketIO(web)
# Command
manager = command_manager(web, socket)
@web.route('/')
@web.route('/<path:path>')
def index(path=''):
# if path.startswith('api'): return abort(404)
return web.send_static_file('views/index.html')
@web.route('/favicon.ico')
def favicon():
return web.send_static_file('favicon-flat.ico')
@socket.on('connect', namespace='/t')
def on_connect():
socket.emit('message', 'WebSocket connected', namespace='/t')
@task_added.connect
def on_task_added(task):
socket.emit('task:new', task.to_primitive(role='DTO'), namespace='/t')
@worker_before_execution.connect
def on_task_started(worker, task):
socket.emit('task:status', dict(task_id=task.id, status=task.status, worker_id=worker.id), namespace='/t')
@worker_after_execution.connect
def on_task_finished(worker, task):
socket.emit('task:status', dict(task_id=task.id, status=task.status, worker_id=worker.id), namespace='/t')
@task_completed.connect
def on_task_completed(task):
socket.emit('task:status', dict(task_id=task.id, status=task.status), namespace='/t')
@task_deleted.connect
def on_task_deleted(task):
socket.emit('task:delete', dict(task_id=task.id), namespace='/t')
if __name__ == "__main__":
manager.run()