jenkins-bot has submitted this change and it was merged. Change subject: Endpoint to handle multiple thumbnail requests at once ......................................................................
Endpoint to handle multiple thumbnail requests at once This will allow us to do pre rendering very efficiently, with MediaWiki being able to quickly request thumbor to thumbnail several sizes in one thread, without having to wait for the work to be done. Bug: T122570 Change-Id: I27c1efe9c51a4fc6b2b1a08c44cbcbd3c19a2828 --- A LICENSE A Makefile A requirements.txt A setup.py A tox.ini A wikimedia_thumbor_multi_handler/__init__.py A wikimedia_thumbor_multi_handler/handlers/__init__.py A wikimedia_thumbor_multi_handler/handlers/multi.py 8 files changed, 184 insertions(+), 0 deletions(-) Approvals: Ori.livneh: Looks good to me, approved Filippo Giunchedi: Looks good to me, but someone else must approve jenkins-bot: Verified diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..04dc90e --- /dev/null +++ b/LICENSE @@ -0,0 +1,22 @@ +The MIT License (MIT) + +Copyright (c) 2016 Gilles Dubuc, Wikimedia Foundation + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..02fd9fe --- /dev/null +++ b/Makefile @@ -0,0 +1,23 @@ +.PHONY: setup_docs build_docs docs + +install: + pip install . + +reinstall: + pip uninstall wikimedia_thumbor_multi_handler -y + pip install . + +setup: + @pip install -e .[tests] + +setup_docs: + pip install -r docs/requirements.txt + +build_docs: + cd docs && make html + +docs: setup_docs build_docs + python -mwebbrowser file:///`pwd`/docs/_build/html/index.html + +pyvows_run: + @pyvows -vvv --profile --cover --cover-package=wikimedia_thumbor_multi_handler vows/ diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..ce1d4f8 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +tc_core +thumbor diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..dd049c7 --- /dev/null +++ b/setup.py @@ -0,0 +1,35 @@ +# -*- coding: utf-8 -*- + +from setuptools import setup, find_packages + + +setup( + name='wikimedia_thumbor_multi_handler', + version='0.1.1', + url='https://github.com/wikimedia/thumbor-multi-handler', + license='MIT', + author='Gilles Dubuc, Wikimedia Foundation', + description='Multi request handler', + packages=find_packages(), + include_package_data=True, + zip_safe=False, + platforms='any', + install_requires=[ + 'thumbor', + 'tc_core', + ], + extras_require={ + 'tests': [ + 'pyvows', + 'coverage', + ], + }, + classifiers=[ + 'Development Status :: 4 - Beta', + 'Intended Audience :: Developers', + 'License :: OSI Approved :: MIT License', + 'Operating System :: OS Independent', + 'Programming Language :: Python', + 'Topic :: Software Development :: Libraries :: Python Modules' + ] +) diff --git a/tox.ini b/tox.ini new file mode 100644 index 0000000..157253d --- /dev/null +++ b/tox.ini @@ -0,0 +1,12 @@ +[tox] +minversion = 1.6 +skipsdist = True +envlist = flake8, py27 + +[testenv] +setenv = VIRTUAL_ENV={envdir} +deps = -r{toxinidir}/requirements.txt + +[testenv:flake8] +commands = flake8 {posargs} +deps = flake8 diff --git a/wikimedia_thumbor_multi_handler/__init__.py b/wikimedia_thumbor_multi_handler/__init__.py new file mode 100644 index 0000000..ef97a05 --- /dev/null +++ b/wikimedia_thumbor_multi_handler/__init__.py @@ -0,0 +1,14 @@ +# -*- coding: utf-8 -*- + +# Copyright (c) 2016, thumbor-community, Wikimedia Foundation +# Use of this source code is governed by the MIT license that can be +# found in the LICENSE file. + +from tc_core import Extension, Extensions +from wikimedia_thumbor_multi_handler.handlers.multi import MultiHandler + + +extension = Extension('wikimedia_thumbor_multi_handler') +extension.add_handler(MultiHandler.regex(), MultiHandler) + +Extensions.register(extension) diff --git a/wikimedia_thumbor_multi_handler/handlers/__init__.py b/wikimedia_thumbor_multi_handler/handlers/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/wikimedia_thumbor_multi_handler/handlers/__init__.py diff --git a/wikimedia_thumbor_multi_handler/handlers/multi.py b/wikimedia_thumbor_multi_handler/handlers/multi.py new file mode 100644 index 0000000..dc5e9f2 --- /dev/null +++ b/wikimedia_thumbor_multi_handler/handlers/multi.py @@ -0,0 +1,76 @@ +# -*- coding: utf-8 -*- + +# Copyright (c) 2016, thumbor-community, Wikimedia Foundation +# Use of this source code is governed by the MIT license that can be +# found in the LICENSE file. +# +# This handler lets one warm up caches by generating a list of requested +# thumbnails asynchronously. + +import re + +import tornado.web +from tornado import gen +from tornado.httputil import HTTPServerRequest + +from thumbor.handlers.imaging import ImagingHandler +from thumbor.url import Url + + +class MultiHandler(ImagingHandler): + paths_limit = 128 + + @classmethod + def regex(cls): + return r'/multi' + + @tornado.web.asynchronous + @gen.coroutine + def post(self, **kw): + paths = self.get_arguments('paths[]') + + if len(paths) > MultiHandler.paths_limit: + self.set_status(400) + super(MultiHandler, self).write( + 'Too many paths: %d max' % MultiHandler.paths_limit + ) + super(MultiHandler, self).finish() + return + + for path in paths: + request = HTTPServerRequest( + method='GET', + uri=path, + host=self.request.host, + connection=self.request.connection + ) + + handler = MultiHandler( + self.application, + request, + context=self.context + ) + + # Copy over the storage as-is, which allows those requests to + # share storage if needed (useful for request-storage) + handler.context.modules.storage = self.context.modules.storage + + m = re.match(Url.regex(), path) + yield handler.check_image(m.groupdict()) + + # Close the request ASAP, the work is to be done async + self.set_status(200) + super(MultiHandler, self).finish() + + # We don't want /multi to serve any of the requested content + def write(self, chunk): + pass + + def finish(self, chunk=None): + pass + + def add_header(self, name, value): + pass + + def set_header(self, name, value): + pass -- To view, visit https://gerrit.wikimedia.org/r/261337 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I27c1efe9c51a4fc6b2b1a08c44cbcbd3c19a2828 Gerrit-PatchSet: 3 Gerrit-Project: thumbor/multi-handler Gerrit-Branch: master Gerrit-Owner: Gilles <gdu...@wikimedia.org> Gerrit-Reviewer: Filippo Giunchedi <fgiunch...@wikimedia.org> Gerrit-Reviewer: Gilles <gdu...@wikimedia.org> Gerrit-Reviewer: Giuseppe Lavagetto <glavage...@wikimedia.org> Gerrit-Reviewer: Ori.livneh <o...@wikimedia.org> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits