datasette-scale-to-zero


Namedatasette-scale-to-zero JSON
Version 0.3.1 PyPI version JSON
download
home_pagehttps://github.com/simonw/datasette-scale-to-zero
SummaryQuit Datasette if it has not received traffic for a specified time period
upload_time2024-02-29 21:25:07
maintainer
docs_urlNone
authorSimon Willison
requires_python>=3.8
licenseApache License, Version 2.0
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # datasette-scale-to-zero

[![PyPI](https://img.shields.io/pypi/v/datasette-scale-to-zero.svg)](https://pypi.org/project/datasette-scale-to-zero/)
[![Changelog](https://img.shields.io/github/v/release/simonw/datasette-scale-to-zero?include_prereleases&label=changelog)](https://github.com/simonw/datasette-scale-to-zero/releases)
[![Tests](https://github.com/simonw/datasette-scale-to-zero/workflows/Test/badge.svg)](https://github.com/simonw/datasette-scale-to-zero/actions?query=workflow%3ATest)
[![License](https://img.shields.io/badge/license-Apache%202.0-blue.svg)](https://github.com/simonw/datasette-scale-to-zero/blob/main/LICENSE)

Quit Datasette if it has not received traffic for a specified time period

Some hosting providers such as [Fly](https://fly.io/) offer a scale to zero mechanism, where servers can shut down and will be automatically started when new traffic arrives.

This plugin can be used to configure Datasette to quit X minutes (or seconds, or hours) after the last request it received. It can also cause the Datasette server to exit after a configured maximum time whether or not it is receiving traffic.

## Installation

Install this plugin in the same environment as Datasette.

    datasette install datasette-scale-to-zero

## Configuration

This plugin will only take effect if it has been configured.

Add the following to your ``metadata.json`` or ``metadata.yml`` configuration file:

```json
{
    "plugins": {
        "datasette-scale-to-zero": {
            "duration": "10m"
        }
    }
}
```
This will cause Datasette to quit if it has not received any HTTP traffic for 10 minutes.

You can set this value using a suffix of `m` for minutes, `h` for hours or `s` for seconds.

To cause Datasette to exit if the server has been running for longer than a specific time, use `"max_age"`:

```json
{
    "plugins": {
        "datasette-scale-to-zero": {
            "max_age": "10h"
        }
    }
}
```
This example will exit the Datasette server if it has been running for more than ten hours.

You can use `"duration"` and `"max_age"` together in the same configuration file:

```json
{
    "plugins": {
        "datasette-scale-to-zero": {
            "max_age": "10h",
            "duration": "5m"
        }
    }
}
```
This example will quit if no traffic has been received in five minutes, or if the server has been running for ten hours.

## Configuring a shutdown HTTP message

You can also configure the plugin to send an HTTP request somewhere right before it quits, using the `"shutdown_url"` option:

```json
{
    "plugins": {
        "datasette-scale-to-zero": {
            "duration": "10m",
            "shutdown_url": "https://example.com/shutdown"
        }
    }
}
```
You can add additional headers to the GET request - for example to send Authorization headers - using `"shutdown_headers"`:

```json
{
    "plugins": {
        "datasette-scale-to-zero": {
            "duration": "10m",
            "shutdown_url": "https://example.com/shutdown",
            "shutdown_headers": {
                "Authorization": "Bearer secret"
            }
        }
    }
}
```
Use `"shutdown_method"` to set a different HTTP method, e.g. for `POST`. You can also set `shutdown_body` to specify the body that should be sent with the request:

```json
{
    "plugins": {
        "datasette-scale-to-zero": {
            "duration": "10m",
            "shutdown_url": "https://example.com/shutdown",
            "shutdown_method": "POST",
            "shutdown_headers": {
                "Authorization": "Bearer secret",
                "Content-Type": "application/json"
            },
            "shutdown_body": "{\"message\": \"shutting down\"}"
        }
    }
}
```

## Development

To set up this plugin locally, first checkout the code. Then create a new virtual environment:

    cd datasette-scale-to-zero
    python3 -m venv venv
    source venv/bin/activate

Now install the dependencies and test dependencies:

    pip install -e '.[test]'

To run the tests:

    pytest

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/simonw/datasette-scale-to-zero",
    "name": "datasette-scale-to-zero",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": "",
    "keywords": "",
    "author": "Simon Willison",
    "author_email": "",
    "download_url": "https://files.pythonhosted.org/packages/e0/c4/ab251b2fb273855c485ac845d413054b8bf6ca9a69fc29a10b4a71c4c7af/datasette-scale-to-zero-0.3.1.tar.gz",
    "platform": null,
    "description": "# datasette-scale-to-zero\n\n[![PyPI](https://img.shields.io/pypi/v/datasette-scale-to-zero.svg)](https://pypi.org/project/datasette-scale-to-zero/)\n[![Changelog](https://img.shields.io/github/v/release/simonw/datasette-scale-to-zero?include_prereleases&label=changelog)](https://github.com/simonw/datasette-scale-to-zero/releases)\n[![Tests](https://github.com/simonw/datasette-scale-to-zero/workflows/Test/badge.svg)](https://github.com/simonw/datasette-scale-to-zero/actions?query=workflow%3ATest)\n[![License](https://img.shields.io/badge/license-Apache%202.0-blue.svg)](https://github.com/simonw/datasette-scale-to-zero/blob/main/LICENSE)\n\nQuit Datasette if it has not received traffic for a specified time period\n\nSome hosting providers such as [Fly](https://fly.io/) offer a scale to zero mechanism, where servers can shut down and will be automatically started when new traffic arrives.\n\nThis plugin can be used to configure Datasette to quit X minutes (or seconds, or hours) after the last request it received. It can also cause the Datasette server to exit after a configured maximum time whether or not it is receiving traffic.\n\n## Installation\n\nInstall this plugin in the same environment as Datasette.\n\n    datasette install datasette-scale-to-zero\n\n## Configuration\n\nThis plugin will only take effect if it has been configured.\n\nAdd the following to your ``metadata.json`` or ``metadata.yml`` configuration file:\n\n```json\n{\n    \"plugins\": {\n        \"datasette-scale-to-zero\": {\n            \"duration\": \"10m\"\n        }\n    }\n}\n```\nThis will cause Datasette to quit if it has not received any HTTP traffic for 10 minutes.\n\nYou can set this value using a suffix of `m` for minutes, `h` for hours or `s` for seconds.\n\nTo cause Datasette to exit if the server has been running for longer than a specific time, use `\"max_age\"`:\n\n```json\n{\n    \"plugins\": {\n        \"datasette-scale-to-zero\": {\n            \"max_age\": \"10h\"\n        }\n    }\n}\n```\nThis example will exit the Datasette server if it has been running for more than ten hours.\n\nYou can use `\"duration\"` and `\"max_age\"` together in the same configuration file:\n\n```json\n{\n    \"plugins\": {\n        \"datasette-scale-to-zero\": {\n            \"max_age\": \"10h\",\n            \"duration\": \"5m\"\n        }\n    }\n}\n```\nThis example will quit if no traffic has been received in five minutes, or if the server has been running for ten hours.\n\n## Configuring a shutdown HTTP message\n\nYou can also configure the plugin to send an HTTP request somewhere right before it quits, using the `\"shutdown_url\"` option:\n\n```json\n{\n    \"plugins\": {\n        \"datasette-scale-to-zero\": {\n            \"duration\": \"10m\",\n            \"shutdown_url\": \"https://example.com/shutdown\"\n        }\n    }\n}\n```\nYou can add additional headers to the GET request - for example to send Authorization headers - using `\"shutdown_headers\"`:\n\n```json\n{\n    \"plugins\": {\n        \"datasette-scale-to-zero\": {\n            \"duration\": \"10m\",\n            \"shutdown_url\": \"https://example.com/shutdown\",\n            \"shutdown_headers\": {\n                \"Authorization\": \"Bearer secret\"\n            }\n        }\n    }\n}\n```\nUse `\"shutdown_method\"` to set a different HTTP method, e.g. for `POST`. You can also set `shutdown_body` to specify the body that should be sent with the request:\n\n```json\n{\n    \"plugins\": {\n        \"datasette-scale-to-zero\": {\n            \"duration\": \"10m\",\n            \"shutdown_url\": \"https://example.com/shutdown\",\n            \"shutdown_method\": \"POST\",\n            \"shutdown_headers\": {\n                \"Authorization\": \"Bearer secret\",\n                \"Content-Type\": \"application/json\"\n            },\n            \"shutdown_body\": \"{\\\"message\\\": \\\"shutting down\\\"}\"\n        }\n    }\n}\n```\n\n## Development\n\nTo set up this plugin locally, first checkout the code. Then create a new virtual environment:\n\n    cd datasette-scale-to-zero\n    python3 -m venv venv\n    source venv/bin/activate\n\nNow install the dependencies and test dependencies:\n\n    pip install -e '.[test]'\n\nTo run the tests:\n\n    pytest\n",
    "bugtrack_url": null,
    "license": "Apache License, Version 2.0",
    "summary": "Quit Datasette if it has not received traffic for a specified time period",
    "version": "0.3.1",
    "project_urls": {
        "CI": "https://github.com/simonw/datasette-scale-to-zero/actions",
        "Changelog": "https://github.com/simonw/datasette-scale-to-zero/releases",
        "Homepage": "https://github.com/simonw/datasette-scale-to-zero",
        "Issues": "https://github.com/simonw/datasette-scale-to-zero/issues"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "30beed2f7be90b9105b6c42830bbabddd6eae769f1018223b35fc30f2b131cd6",
                "md5": "b1080d701a1c302fd79c3f37a96f3ce0",
                "sha256": "6e8039639c79259695ce669599ad78a478217ee580f132ae110d1ff414774e7a"
            },
            "downloads": -1,
            "filename": "datasette_scale_to_zero-0.3.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "b1080d701a1c302fd79c3f37a96f3ce0",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 9036,
            "upload_time": "2024-02-29T21:25:05",
            "upload_time_iso_8601": "2024-02-29T21:25:05.860264Z",
            "url": "https://files.pythonhosted.org/packages/30/be/ed2f7be90b9105b6c42830bbabddd6eae769f1018223b35fc30f2b131cd6/datasette_scale_to_zero-0.3.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "e0c4ab251b2fb273855c485ac845d413054b8bf6ca9a69fc29a10b4a71c4c7af",
                "md5": "b35ad3cfb99b5c1f7154af54100ee5e7",
                "sha256": "00142ee91b1c44a1cb905e9fecfd9fc4b29a4fe5bc20a946f291140d4d513563"
            },
            "downloads": -1,
            "filename": "datasette-scale-to-zero-0.3.1.tar.gz",
            "has_sig": false,
            "md5_digest": "b35ad3cfb99b5c1f7154af54100ee5e7",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 9732,
            "upload_time": "2024-02-29T21:25:07",
            "upload_time_iso_8601": "2024-02-29T21:25:07.263473Z",
            "url": "https://files.pythonhosted.org/packages/e0/c4/ab251b2fb273855c485ac845d413054b8bf6ca9a69fc29a10b4a71c4c7af/datasette-scale-to-zero-0.3.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-02-29 21:25:07",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "simonw",
    "github_project": "datasette-scale-to-zero",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "datasette-scale-to-zero"
}
        
Elapsed time: 0.21488s