diff options
author | Milo Casagrande <milo.casagrande@linaro.org> | 2014-05-09 16:18:32 +0200 |
---|---|---|
committer | Milo Casagrande <milo.casagrande@linaro.org> | 2014-05-09 16:19:03 +0200 |
commit | 5845b7dd0a70ab628967618e4ce3a141987668d5 (patch) | |
tree | 90013a43381470ea2d2113e10106c8ef3303dfd4 | |
parent | 1c711c4b99a91a9b0b39697ba2cee04b189dfb29 (diff) |
Implement POST method for boot handler.
* Add URL for boot handler.
-rw-r--r-- | app/handlers/__init__.py | 1 | ||||
-rw-r--r-- | app/handlers/boot.py | 21 | ||||
-rw-r--r-- | app/taskqueue/tasks.py | 19 | ||||
-rw-r--r-- | app/urls.py | 5 |
4 files changed, 42 insertions, 4 deletions
diff --git a/app/handlers/__init__.py b/app/handlers/__init__.py index 6c05ae3..5ff5b3c 100644 --- a/app/handlers/__init__.py +++ b/app/handlers/__init__.py @@ -13,6 +13,7 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. +from boot import * from defconf import * from job import * from subscription import * diff --git a/app/handlers/boot.py b/app/handlers/boot.py index fc16b46..ed8b2b7 100644 --- a/app/handlers/boot.py +++ b/app/handlers/boot.py @@ -17,6 +17,27 @@ from handlers.base import BaseHandler +from models.boot import BOOT_COLLECTION +from taskqueue.tasks import import_boot + class BootHandler(BaseHandler): """Handle the /boot URLs.""" + + def __init__(self, application, request, **kwargs): + super(BootHandler, self).__init__(application, request, **kwargs) + + @property + def collection(self): + return self.db[BOOT_COLLECTION] + + def _valid_keys(self, method): + valid_keys = { + 'POST': ['job', 'kernel'], + } + + return valid_keys.get(method, None) + + def _post(self, json_obj): + import_boot.apply_async([json_obj]) + self._create_valid_response(200) diff --git a/app/taskqueue/tasks.py b/app/taskqueue/tasks.py index 50807e6..3f50122 100644 --- a/app/taskqueue/tasks.py +++ b/app/taskqueue/tasks.py @@ -16,8 +16,9 @@ """Tasks that should be run via Celery.""" from taskqueue.celery import app +from utils.bootimport import import_and_save_boot +from utils.docimport import import_and_save_job from utils.subscription import send -from utils.docimport import import_and_save @app.task(name='send-emails') @@ -38,6 +39,18 @@ def import_job(json_obj): This is used to provide a Celery-task access to the import function. :param json_obj: The JSON object with the values necessary to import the - job. + job. """ - return import_and_save(json_obj) + return import_and_save_job(json_obj) + + +@app.task(name='import-boot') +def import_boot(json_obj): + """Just a wrapper around the real boot import function. + + This is used to provide a Celery-task access to the import function. + + :param json_obj: The JSON object with the values necessary to import the + boot report. + """ + import_and_save_boot(json_obj) diff --git a/app/urls.py b/app/urls.py index 67e872b..90cec3e 100644 --- a/app/urls.py +++ b/app/urls.py @@ -18,9 +18,10 @@ from tornado.web import url from handlers import ( + BootHandler, DefConfHandler, JobHandler, - SubscriptionHandler + SubscriptionHandler, ) _JOB_URL = url(r'/api/job(?P<sl>/)?(?P<id>.*)', JobHandler, name='job') @@ -32,8 +33,10 @@ _SUBSCRIPTION_URL = url( SubscriptionHandler, name='subscription', ) +_BOOT_URL = url(r'/api/boot(?P<sl>/)?(?P<id>.*)', BootHandler, name='boot') APP_URLS = [ + _BOOT_URL, _DEFCONF_URL, _JOB_URL, _SUBSCRIPTION_URL, |