Metadata-Version: 2.4
Name: django-request-queue-timeout
Version: 1.0.4
Summary: Django middleware class to quickly dispatch any requests that wait too long in a queue before being processed
License: MIT License
        
        Copyright (c) 2020 Evan Grim
        
        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.
Keywords: django,queue,timeout
Description-Content-Type: text/markdown
License-File: LICENSE.txt
Requires-Dist: django<6,>=4.2
Provides-Extra: dev
Requires-Dist: bandit>=1.7.4; extra == "dev"
Requires-Dist: coverage[toml]==6.3.2; extra == "dev"
Requires-Dist: freezegun~=0.3.15; extra == "dev"
Requires-Dist: ipython~=7.15.0; extra == "dev"
Requires-Dist: ruff~=0.1.2; extra == "dev"
Dynamic: license-file

# Django-Request-Queue-Timeout

This package provides a Django middleware class to quickly dispatch any requests that wait too long in a queue before being processed.

This is useful in environments like Heroku, where traffic spikes can result in requests remaining in the queue well beyond the [30 second limit](https://devcenter.heroku.com/articles/http-routing#timeouts) the Heroku router enforces before giving up on the request.  With this middleware in place, applications recover much more quickly by not wasting time processing requests for which clients have already received a server error response. 

## Requirements

Recent versions of Python and Django.  See `pyproject.toml` for exact versions.

## Installation

Install from git

```sh
pip install git+<git address>#egg=django-request-queue-timeout
```
    
Install from [PyPI](https://pypi.org/project/django-request-queue-timeout/)

```sh
pip install django-request-queue-timeout
```

Add to `MIDDLEWARE` list in settings file as the first item:

```python
MIDDLEWARE = (
    'rqto.middleware.RequestQueueTimeoutMiddleware'
    ...
)
```

## Configuration

When installed, the middleware checks each incoming request for a [`X-REQUEST-START` header](https://devcenter.heroku.com/articles/http-routing#heroku-headers) value indicating when the request started (in milliseconds since the unix epoch).  If the request has queued too long before being processed a `503 Service Unavailable` response is generated.

The timeout is 30 seconds by default, but can be configured to a different value by providing a Django setting:

```python
REQUEST_QUEUE_TIMEOUT_IN_SECONDS = 60  # configure a 60 second request queue timeout
```

## See Also
- [Request Timeout | Heroku Dev Center](https://devcenter.heroku.com/articles/request-timeout)
