diff env/lib/python3.7/site-packages/ephemeris/sleep.py @ 5:9b1c78e6ba9c draft default tip

"planemo upload commit 6c0a8142489327ece472c84e558c47da711a9142"
author shellac
date Mon, 01 Jun 2020 08:59:25 -0400
parents 79f47841a781
children
line wrap: on
line diff
--- a/env/lib/python3.7/site-packages/ephemeris/sleep.py	Thu May 14 16:47:39 2020 -0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,80 +0,0 @@
-#!/usr/bin/env python
-'''Utility to do a blocking sleep until a Galaxy instance is responsive.
-This is useful in docker images, in RUN steps, where one needs to wait
-for a currently starting Galaxy to be alive, before API requests can be
-made successfully.
-
-The script functions by making repeated requests to
-``http(s)://fqdn/api/version``, an API which requires no authentication
-to access.'''
-
-import sys
-import time
-from argparse import ArgumentParser
-
-import requests
-from galaxy.util import unicodify
-
-from .common_parser import get_common_args
-
-
-def _parser():
-    '''Constructs the parser object'''
-    parent = get_common_args(login_required=False)
-    parser = ArgumentParser(parents=[parent], usage="usage: %(prog)s <options>",
-                            description="Script to sleep and wait for Galaxy to be alive.")
-    parser.add_argument("--timeout",
-                        default=0, type=int,
-                        help="Galaxy startup timeout in seconds. The default value of 0 waits forever")
-    return parser
-
-
-def _parse_cli_options():
-    """
-    Parse command line options, returning `parse_args` from `ArgumentParser`.
-    """
-    parser = _parser()
-    return parser.parse_args()
-
-
-def galaxy_wait(galaxy_url, timeout=600, verbose=False):
-    count = 0
-    while True:
-        try:
-            result = requests.get(galaxy_url + '/api/version')
-            try:
-                result = result.json()
-                if verbose:
-                    sys.stdout.write("Galaxy Version: %s\n" % result['version_major'])
-                break
-            except ValueError:
-                if verbose:
-                    sys.stdout.write("[%02d] No valid json returned... %s\n" % (count, result.__str__()))
-                    sys.stdout.flush()
-        except requests.exceptions.ConnectionError as e:
-            if verbose:
-                sys.stdout.write("[%02d] Galaxy not up yet... %s\n" % (count, unicodify(e)[0:100]))
-                sys.stdout.flush()
-        count += 1
-
-        # If we cannot talk to galaxy and are over the timeout
-        if timeout != 0 and count > timeout:
-            sys.stderr.write("Failed to contact Galaxy\n")
-            sys.exit(1)
-
-        time.sleep(1)
-
-
-def main():
-    """
-    Main function
-    """
-    options = _parse_cli_options()
-
-    galaxy_wait(options.galaxy, options.timeout, options.verbose)
-
-    sys.exit(0)
-
-
-if __name__ == "__main__":
-    main()