]>
Commit | Line | Data |
---|---|---|
9137135a MT |
1 | #!/usr/bin/python |
2 | ||
3 | import logging | |
4 | import os.path | |
5 | import tornado.httpserver | |
6 | import tornado.locale | |
7 | import tornado.options | |
8 | import tornado.web | |
9 | ||
57859ebc | 10 | from .. import Backend |
9f2cdc47 | 11 | from ..decorators import * |
2c909128 MT |
12 | |
13 | from . import handlers | |
9137135a | 14 | |
c2902b29 MT |
15 | # Read command line |
16 | tornado.options.define("debug", default=False, help="Run in debug mode", type=bool) | |
9137135a MT |
17 | tornado.options.parse_command_line() |
18 | ||
f6e6ff79 | 19 | class Application(tornado.web.Application): |
9137135a MT |
20 | def __init__(self): |
21 | settings = dict( | |
c2902b29 | 22 | debug = tornado.options.options.debug, |
f6e6ff79 | 23 | gzip = True, |
9137135a MT |
24 | ) |
25 | ||
9f2cdc47 | 26 | tornado.web.Application.__init__(self, [ |
f6e6ff79 | 27 | # Redirect strayed users. |
c2902b29 | 28 | #(r"/", handlers.RedirectHandler), |
f6e6ff79 | 29 | |
c2902b29 MT |
30 | # Test handlers |
31 | (r"/noop", handlers.NoopHandler), | |
32 | (r"/error/test", handlers.ErrorTestHandler), | |
33 | (r"/error/test/(\d+)", handlers.ErrorTestHandler), | |
34 | ||
c2902b29 MT |
35 | # Builds |
36 | (r"/builds/create", handlers.BuildsCreateHandler), | |
37 | (r"/builds/(.*)", handlers.BuildsGetHandler), | |
38 | ||
39 | # Builders | |
40 | (r"/builders/info", handlers.BuildersInfoHandler), | |
41 | (r"/builders/jobs/queue", handlers.BuildersJobsQueueHandler), | |
42 | (r"/builders/jobs/(.*)/addfile/(.*)", handlers.BuildersJobsAddFileHandler), | |
43 | (r"/builders/jobs/(.*)/buildroot", handlers.BuildersJobsBuildrootHandler), | |
44 | (r"/builders/jobs/(.*)/state/(.*)", handlers.BuildersJobsStateHandler), | |
45 | (r"/builders/keepalive", handlers.BuildersKeepaliveHandler), | |
46 | ||
47 | # Jobs | |
ba9f9092 MT |
48 | (r"/jobs/active", handlers.JobsGetActiveHandler), |
49 | (r"/jobs/latest", handlers.JobsGetLatestHandler), | |
50 | (r"/jobs/queue", handlers.JobsGetQueueHandler), | |
c2902b29 MT |
51 | (r"/jobs/(.*)", handlers.JobsGetHandler), |
52 | ||
53 | # Packages | |
54 | (r"/packages/(.*)", handlers.PackagesGetHandler), | |
55 | ||
56 | # Uploads | |
57 | (r"/uploads/create", handlers.UploadsCreateHandler), | |
58 | (r"/uploads/(.*)/sendchunk", handlers.UploadsSendChunkHandler), | |
59 | (r"/uploads/(.*)/finished", handlers.UploadsFinishedHandler), | |
60 | (r"/uploads/(.*)/destroy", handlers.UploadsDestroyHandler), | |
9f2cdc47 | 61 | ], **settings) |
9137135a MT |
62 | |
63 | logging.info("Successfully initialied application") | |
64 | ||
9f2cdc47 MT |
65 | @lazy_property |
66 | def backend(self): | |
67 | return Backend() | |
f6e6ff79 | 68 | |
9137135a MT |
69 | def __del__(self): |
70 | logging.info("Shutting down application") | |
71 | ||
72 | @property | |
73 | def ioloop(self): | |
74 | return tornado.ioloop.IOLoop.instance() | |
75 | ||
76 | def shutdown(self, *args): | |
77 | logging.debug("Caught shutdown signal") | |
78 | self.ioloop.stop() | |
79 | ||
80 | def run(self, port=81): | |
81 | logging.debug("Going to background") | |
82 | ||
9137135a MT |
83 | http_server = tornado.httpserver.HTTPServer(self, xheaders=True) |
84 | ||
85 | # If we are not running in debug mode, we can actually run multiple | |
86 | # frontends to get best performance out of our service. | |
87 | if not self.settings["debug"]: | |
88 | http_server.bind(port) | |
89 | http_server.start(num_processes=4) | |
90 | else: | |
91 | http_server.listen(port) | |
92 | ||
f6e6ff79 MT |
93 | # All requests should be done after 30 seconds or they will be killed. |
94 | self.ioloop.set_blocking_log_threshold(30) | |
95 | ||
9137135a MT |
96 | self.ioloop.start() |
97 | ||
98 | def reload(self): | |
99 | logging.debug("Caught reload signal") |