Skip to main content

A CLI utility for blocking until a service is listening

Project description

https://img.shields.io/travis/pmclanahan/urlwait.svg https://img.shields.io/pypi/v/urlwait.svg

I needed a way to block my app from starting until the database service was running and accepting connections. This was particularly a problem when using Docker and docker-compose. You can run this utility as part of a run-dev.sh or run-tests.sh script and it will block for 15 seconds (configurable) until it can connect to the hostname and port as specified in your connection URL (gleaned from DATABASE_URL environment variable by default).

Installation

$ pip install urlwait

Usage

$ urlwait --help

Usage:

    $ urlwait [SERVICE URL] [TIMEOUT]

    SERVICE URL is a connection url, e.g. a typical value for $DATABASE_URL. TIMEOUT is
    a number of seconds to try to connect to the host and port specified in the SERVICE
    URL. These values may also be specified in environment variables, but command line
    args take precedence:

        URLWAIT_VARNAME: the env var name containing the URL to check. Default DATABASE_URL.
        URLWAIT_TIMEOUT: the number of seconds to wait. Default 15.

    Returns a 0 status if the connection completed successfully before the timeout, or 1 if not.
    It is designed for use with Docker or other dev or testing environments where the connected
    services and the app are started simultaneously, but one should wait for the other.

Examples:

    The following are equivalent:

    $ urlwait redis://localhost:6379/0 20
    $ urlwait $CACHE_URL 20
    $ URLWAIT_VARNAME=CACHE_URL URLWAIT_TIMEOUT=20 urlwait

The module is also usable in your python code:

import os

from urlwait import wait_for_url


if wait_for_url(os.getenv('REDIS_URL')):
    # do things with the service
else:
    # service likely did not start

If you don’t have the service URL but do have the host and port, you can use the wait_for_service(host, port, timeout) function instead.

Changelog

  • 0.4 - 2017-03-02 - Always return true if protocol is sqlite

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

urlwait-0.4.tar.gz (4.9 kB view details)

Uploaded Source

Built Distribution

urlwait-0.4-py2.py3-none-any.whl (6.3 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file urlwait-0.4.tar.gz.

File metadata

  • Download URL: urlwait-0.4.tar.gz
  • Upload date:
  • Size: 4.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for urlwait-0.4.tar.gz
Algorithm Hash digest
SHA256 395fc0c2a7f9736858a2c2f449aa20c6e9da1f86bfc2d1fda4f2f5b78a5c115a
MD5 416724cd7c96937b098c1cf127be3276
BLAKE2b-256 9acd74d33204d67170e113a5262b2615c549568b5fddbd3a37fba9d2156e6179

See more details on using hashes here.

File details

Details for the file urlwait-0.4-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for urlwait-0.4-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 fc39ff2c8abbcaad5043e1f79699dcb15a036cc4b0ff4d1aa825ea105d4889ff
MD5 d8248fcd916814836d91e24168bd659c
BLAKE2b-256 e641e5666e076e5a89b88f47d9c511fbe829b34150a607a185d974026f4ed4b1

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page