Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Caching example using aiocache #140

Merged
merged 10 commits into from
Nov 6, 2016
Merged

Conversation

argaen
Copy link
Contributor

@argaen argaen commented Nov 5, 2016

Example of caching using aiocache. #136

@seemethere
Copy link
Member

I don't know why this change would make a test fail. Can you pull and merge the latest changes in master and see if that fixes this?

I'd like to merge but I want to see a fast forward attempted and the PR retested before I do that.

@seemethere
Copy link
Member

@argaen the error should be fixed now, it's safe to remerge.

@argaen
Copy link
Contributor Author

argaen commented Nov 5, 2016

I merged right now you should be okay to merge right?

@seemethere seemethere merged commit ce8742c into sanic-org:master Nov 6, 2016
@argaen argaen deleted the caching_example branch November 6, 2016 15:37
Sharpek added a commit to Sharpek/sanic that referenced this pull request Jan 9, 2017
* Fix comments over-indentation

* Keep-alive requests stay open if communicating

* time.time faster than loop.time?

* Fix flake8

* Update README.md

via flake8

* Fix upload without content-type

* Add aiofiles to requirements.txt

* Fix value error for query string test

* Caching example using aiocache (sanic-org#140)

* Keep-alive requests stay open if communicating

* time.time faster than loop.time?

* Fix flake8

* Add aiofiles to requirements.txt

* Caching example using aiocache

* Caching example using aiocache

* Added aiocache to requirements

* fix(blueprints): @Middleware IndexError (sanic-org#139)

* fix(request.py): problem in case of request without content-type header (sanic-org#142)

* fix(request.py): exception if access request.form on GET request

* fix(request): just make a unification (parsed_form and parsed_files) + RFC fixes

parsed_form and parsed_files must be a RequestParameters type in all cases!

* fix(request): parse_multipart_form should return RequestParameters

I have this code:

```
form = FileForm(request.files)
```

and it raise error because the `request.files` is `dict` but `RequestParameters` is expected =/

* docs(request): return value docstring

* Add the client address to the request header

* fix whitespace

* pass flake8 tests

* Update variable name

Give `ra` a more explicit name

* Add Gitter badge

* aiohttp is slightly faster actually

Disabling access log increases RPS a lot

* Caching example (sanic-org#150)

* Caching example using aiocache

* Caching example using aiocache

* Added aiocache to requirements

* Fixed example with newest aiocache

* Example for using error_handler

* improved default handling

* Fix the flake8 error caused by new flake8 version

* provide default app name

* update readme example to use default

* fix the way using logging.exception

* Update headers to use CIMultiDict instead of dict

* Added shared request data

* Fix flake8

* Fixed new test error with aiohttp

* Updated test terminology

* Fixing import of CIMultiDict

* Fixed Exception error log on line 157 of server.py

* Adding a new line

* class based views implementation for sanic

* update readme

* pep8 fixes

* Convert server lambda to partial

Partials are faster then lambdas for repeated calls.

* Convert connections dict to set

Connections don't need to be a dict since the value is never used

* Use explicit import for httptools

Explicit importing the parser and the exception to save a name lookup.

* Change Request timeout process

This add a request timeout exception.
It cancels task, when request is timeout.

* Use write_response

* Change sleep time

* Add status code

* changes in doc

* rename&remove redundant code

* Use default error process

* before process

* fix for cookie header capitalization bug

* refactoring cookies

* improving comments and examples

* fix typo

* fixing line length

* Increment version to 0.1.8

* test for http2 lowercase header cookies

* Change Payload Too Large process

When Payload Too Large occurs, it uses error handler.

* Fix test_request_timeout.py

This increases sleep time, Because sometimes timeout error does not occur.

* return 400 on invalid json post data

* Find URL encoded filenames on the fs by decoding them first

* add sanic aiopg example with raw sql

* improvements for aiopg example

* pep8&improvements

* aiopg with sqlalchemy example

* url params docs typo fix

add missing '>' in url params docs example

* added a comment on why to decode the file_path

* add jinja example

* remove trailing space

* Fix PEP8 in Hello World example

* Fix leftover blank line

flake8 build failed here: https://travis-ci.org/channelcat/sanic/builds/183991976

* Fix quotes in sample code for consistency

* Change HttpParserError process

* Customizable protocol

* Create documentation for testing server endpoints.

Currently the sanic.utils functionality is undocumented. This provides
information on the interface as well as a complete example of testing
a server endpoint.

* Fixed import error

* Improvement

improvement: support fo binary data as a input. This do that the response process has more performance because not encoding needed.

* Apply response Middleware always

Response middleware are useful to apply some post-process information, just before send to the user. For example: Add some HTTP headers (security headers, for example), remove "Server" banner (for security reasons) or cookie management. 

The change is very very simple: although an "request" middleware has produced any response, we'll even apply the response middlewares.

* Explain how to chain two (or more) middlewares 

A funny and useful examples about how to chain middlewares.

* Fix some verbage

* allow overriding logging.basicConfig

* Refactor arguments of serve function

* Make golang performance test return JSON instead of string

* Refactor arguments of run function

* Update response.py

Type check by isinstance

* Adds python36 to tox.ini and .travis.yml

* Raise error if response is malformed. Issue sanic-org#115

* Rework conditionals to not be inline

* Remove trailing whitespace

* Rewrite static files tests

Relates to PR sanic-org#188

Changes include:
- Rewriting to work with pytest fixtures and an actual static directory
- Addition of a test that covers file paths that must be
  unquoted as a uri

* Use a try/except, it's a bit faster

Also reorder some imports and add some comments

* Add test for PR: sanic-org#215

* Increment version to 0.1.9

* convert header values to strings

* type -> isinstance

* header format function

* use try/except

* Change travis job to use tox

* Update to make flake8 actually work

* Allow Sanic-inherited application

* Added token property to request object.

* Added test for new token property on request object.

* Add test and example for custom protocol

* Improve examples/custom_protocol.py

* stop multiple worker server without sleep loop; issue sanic-org#73

* Handle hooks parameters in more debuggable way

1. not list() -> callable()
The args of hooking parameters of Sanic have to be callables.
For wrong parameters, errors will be generated from:
```
    listeners += args
```

By checking just list type, the raised error will be associated
with `[args]` instead of `args`, which is not given by users.
With this patch, the raised error will be associated with `args`.
Then users can notice their argument was neither callable nor list
in the easier way.

2. Function -> Functions in document
Regarding the parameter as a list is harmless to the user code.
But unawareness of its type can be list can limit the potent of
the user code.

* Add document for custom protocol

* Fix format in custom_protocol.md

* Improve custom_protocol.md

* fix misprints&renaming

* created methods to remove a route from api/router

* Include more explicit loop for headers conversion

Also merges master changes into this PR for this branch

* Add more verbose error handling

* Adds logging to error messages in debug mode as pointed out in PR sanic-org#249,
while also improving the debug message.

* Make exception tests test unhandled exceptions

* Adds tests for unhandled exceptions
* Adds tests for unhandled exceptions in exception handlers
* Rewrites tests to utilize pytest fixtures (No need to create the app
on import)

* Prevent flooding of meaningless traceback in `sanic_endpoint_test`

When Sanic has an exception in a request middleware, it fails to
save request object in `results`. In `sanic_endpoint_test`, because
it always requires `results` to have both `request` and `response` objects,
it prints traceback like attached example. It is not a user code and
it doesn't give any information to users, it is better to suppress
to print this kind of error.

To fix it, this patch insert collect hook as first request middleware
to guarantee to successfully run it always.

```
app = <sanic.sanic.Sanic object at 0x1102b5358>, method = 'get', uri = '/ping/', gather_request = True, loop = None
debug = True, request_args = (), request_kwargs = {}
_collect_request = <function sanic_endpoint_test.<locals>._collect_request at 0x11286c158>
_collect_response = <function sanic_endpoint_test.<locals>._collect_response at 0x11286c378>

    def sanic_endpoint_test(app, method='get', uri='/', gather_request=True,
                            loop=None, debug=False, *request_args,
                            **request_kwargs):
        results = []
        exceptions = []

        if gather_request:
            @app.middleware
            def _collect_request(request):
                results.append(request)

        async def _collect_response(sanic, loop):
            try:
                response = await local_request(method, uri, *request_args,
                                               **request_kwargs)
                results.append(response)
            except Exception as e:
                exceptions.append(e)
            app.stop()

        app.run(host=HOST, debug=debug, port=42101,
                after_start=_collect_response, loop=loop)

        if exceptions:
            raise ValueError("Exception during request: {}".format(exceptions))

        if gather_request:
            try:
>               request, response = results
E               ValueError: not enough values to unpack (expected 2, got 1)

../sanic/sanic/utils.py:46: ValueError
```

* Update .gitignore

* .python-version is generated by `pyenv local` command
* .eggs/ directory contains *.egg files

* Cache request.json even when it's null or empty

In case of request body is set to `{}`, `[]` or `null`, even it's
already processed, parsed_json won't be used due to its boolean
evaluation.

* Correct sanic.router.Router documentation

* Use constant PORT rather than literal in test code (sanic-org#266)

* add configurable backlog sanic-org#263

* Add tests for server start/stop event functions

* Fix this to actually reflect current behavior

* add example for asyncpg

* modify config to varbles

* Update sanic_asyncpg_example.py

Remove unused library

* move backlog to run()

* Change Ellipsis to None for consistency

* added as_view

* add docstrings&updated docs

* tests&small update

* removed debug from test

* fix multiple worker problem

* this branch is broken

* fix stop event

* skip multiprocessing tests

* Change the skips to actual pytest skips

By using the builtin pytest skips we can identify that the tests are still there but are being currently skipped.

Will update later to remove the skips once we figure out why they freeze with pytest (I experienced this same issue with multiprocessing when testing start/stop events).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants