How to use the pgctl.functions.print_stderr function in pgctl

To help you get started, we’ve selected a few pgctl examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Yelp / pgctl / pgctl / poll_ready.py View on Github external
start = time.time()
    while True:  # heartbeat, continue to check if the service is up. if it becomes down, terminate it.
        elapsed = time.time() - start
        if is_service_down:
            print_stderr('pgctl-poll-ready: service is stopping -- quitting the poll')
            return
        elif check_ready() == 0:
            start = time.time()
            is_service_down = wait_for_down_signal(down_fifo, poll_down)
        elif elapsed < timeout:
            print_stderr('pgctl-poll-ready: failed (restarting in {:.2f} seconds)'.format(timeout - elapsed))
            is_service_down = wait_for_down_signal(down_fifo, poll_down)
        else:
            service = os.path.basename(os.getcwd())
            # TODO: Add support for directories
            print_stderr(
                'pgctl-poll-ready: failed for more than {:.2f} seconds -- we are restarting this service for you'.format(timeout)
            )
            exec_(('pgctl', 'restart', service))  # doesn't return
github Yelp / pgctl / pgctl / poll_ready.py View on Github external
def pgctl_poll_ready(down_fifo, notification_fd, timeout, poll_ready, poll_down, check_ready=check_ready):

    is_service_down = wait_for_down_signal(down_fifo, 0)
    while True:  # waiting for the service to come up.
        if is_service_down:
            print_stderr('pgctl-poll-ready: service is stopping -- quitting the poll')
            return
        elif check_ready() == 0:
            print_stderr('pgctl-poll-ready: service\'s ready check succeeded')
            os.write(notification_fd, b'ready\n')
            break
        else:
            is_service_down = wait_for_down_signal(down_fifo, poll_ready)

    is_service_down = wait_for_down_signal(down_fifo, 0)
    start = time.time()
    while True:  # heartbeat, continue to check if the service is up. if it becomes down, terminate it.
        elapsed = time.time() - start
        if is_service_down:
            print_stderr('pgctl-poll-ready: service is stopping -- quitting the poll')
            return
        elif check_ready() == 0:
            start = time.time()
            is_service_down = wait_for_down_signal(down_fifo, poll_down)
        elif elapsed < timeout:
github Yelp / pgctl / pgctl / poll_ready.py View on Github external
def main():
    if os.environ.get('PGCTL_DEBUG'):
        print_stderr('pgctl-poll-ready: disabled during debug -- quitting')
        exec_(argv[1:])  # never returns

    # TODO-TEST: fail if notification-fd doesn't exist
    # TODO-TEST: echo 4 > notification-fd
    notification_fd = int(floatfile('notification-fd'))

    # Create a FIFO to listen for the s6 down event
    #
    # Set up the FIFO in the parent before forking because the process we exec
    # might die immediately (and the child wouldn't receive the "down" event).
    #
    # The name of the FIFO created in S6's FIFO dir must comply with certain
    # naming conventions. See the link below for more information.
    # https://github.com/skarnet/s6/blob/v2.2.2.0/src/libs6/ftrigw_notifyb_nosig.c#L29,L30
    down_fifo_path = os.path.join(
        'event', 'ftrig1' + 'poll_ready_{}'.format(os.getpid()).ljust(43, '_'),
github Yelp / pgctl / pgctl / poll_ready.py View on Github external
def pgctl_poll_ready(down_fifo, notification_fd, timeout, poll_ready, poll_down, check_ready=check_ready):

    is_service_down = wait_for_down_signal(down_fifo, 0)
    while True:  # waiting for the service to come up.
        if is_service_down:
            print_stderr('pgctl-poll-ready: service is stopping -- quitting the poll')
            return
        elif check_ready() == 0:
            print_stderr('pgctl-poll-ready: service\'s ready check succeeded')
            os.write(notification_fd, b'ready\n')
            break
        else:
            is_service_down = wait_for_down_signal(down_fifo, poll_ready)

    is_service_down = wait_for_down_signal(down_fifo, 0)
    start = time.time()
    while True:  # heartbeat, continue to check if the service is up. if it becomes down, terminate it.
        elapsed = time.time() - start
        if is_service_down:
            print_stderr('pgctl-poll-ready: service is stopping -- quitting the poll')
            return
        elif check_ready() == 0:
github Yelp / pgctl / pgctl / poll_ready.py View on Github external
if is_service_down:
            print_stderr('pgctl-poll-ready: service is stopping -- quitting the poll')
            return
        elif check_ready() == 0:
            print_stderr('pgctl-poll-ready: service\'s ready check succeeded')
            os.write(notification_fd, b'ready\n')
            break
        else:
            is_service_down = wait_for_down_signal(down_fifo, poll_ready)

    is_service_down = wait_for_down_signal(down_fifo, 0)
    start = time.time()
    while True:  # heartbeat, continue to check if the service is up. if it becomes down, terminate it.
        elapsed = time.time() - start
        if is_service_down:
            print_stderr('pgctl-poll-ready: service is stopping -- quitting the poll')
            return
        elif check_ready() == 0:
            start = time.time()
            is_service_down = wait_for_down_signal(down_fifo, poll_down)
        elif elapsed < timeout:
            print_stderr('pgctl-poll-ready: failed (restarting in {:.2f} seconds)'.format(timeout - elapsed))
            is_service_down = wait_for_down_signal(down_fifo, poll_down)
        else:
            service = os.path.basename(os.getcwd())
            # TODO: Add support for directories
            print_stderr(
                'pgctl-poll-ready: failed for more than {:.2f} seconds -- we are restarting this service for you'.format(timeout)
            )
            exec_(('pgctl', 'restart', service))  # doesn't return
github Yelp / pgctl / pgctl / poll_ready.py View on Github external
break
        else:
            is_service_down = wait_for_down_signal(down_fifo, poll_ready)

    is_service_down = wait_for_down_signal(down_fifo, 0)
    start = time.time()
    while True:  # heartbeat, continue to check if the service is up. if it becomes down, terminate it.
        elapsed = time.time() - start
        if is_service_down:
            print_stderr('pgctl-poll-ready: service is stopping -- quitting the poll')
            return
        elif check_ready() == 0:
            start = time.time()
            is_service_down = wait_for_down_signal(down_fifo, poll_down)
        elif elapsed < timeout:
            print_stderr('pgctl-poll-ready: failed (restarting in {:.2f} seconds)'.format(timeout - elapsed))
            is_service_down = wait_for_down_signal(down_fifo, poll_down)
        else:
            service = os.path.basename(os.getcwd())
            # TODO: Add support for directories
            print_stderr(
                'pgctl-poll-ready: failed for more than {:.2f} seconds -- we are restarting this service for you'.format(timeout)
            )
            exec_(('pgctl', 'restart', service))  # doesn't return