用于阻塞直到服务监听的cli实用程序

urlwait的Python项目详细描述


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

我需要一种方法来阻止我的应用程序从启动到数据库服务运行 接受连接。这在使用docker和docker compose时尤其是一个问题。 可以将此实用程序作为run-dev.shrun-tests.sh脚本的一部分运行,它将 阻塞15秒(可配置),直到它可以连接到指定的主机名和端口 在您的连接URL中(默认情况下从数据库URL环境变量收集)。

安装

$ pip install urlwait

用法

$ 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

该模块也可用于您的python代码:

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

如果您没有服务url,但有主机和端口,则可以使用 wait_for_service(host, port, timeout)函数。

更改日志

  • 0.4-2017-03-02-如果协议为sqlite,则始终返回true

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java静态键入和编写一个简单的矩阵库   java如何最小化层次结构的代码量   这是在Google云数据存储中使用Java按键查询的正确方法吗?   java Android php+mysql+json执行异步任务时出错   java Hadoop Hbase访问被拒绝异常   java如何在json中指定特定的对象路径   JavaSpringJPA/Hibernate在使用@modify和@Query进行特殊更新之前调用完整更新   java多个错误通知   java插入Linkedlist和Node   java将图像放在webview中并调整其宽度   Java没有真实属性的缺点是什么?   java“isGooglePlayServicesAvailable”(此)已被弃用   java托管HIPPO CMS   安卓 Java。网URI构造函数不是编码字符(&C)   java如何用hibernate映射Deque?   java传递枚举类型作为参数   java自由堆大小在Maven中不会增加   java如何使用hashmap和arraylist的循环逻辑?   java如何使用JDBC复制MySql数据库