comparison env/lib/python3.7/site-packages/planemo/galaxy/serve.py @ 5:9b1c78e6ba9c draft default tip

"planemo upload commit 6c0a8142489327ece472c84e558c47da711a9142"
author shellac
date Mon, 01 Jun 2020 08:59:25 -0400
parents 79f47841a781
children
comparison
equal deleted inserted replaced
4:79f47841a781 5:9b1c78e6ba9c
1 """Abstractions for serving out development Galaxy servers."""
2 from __future__ import print_function
3
4 import contextlib
5 import os
6 import time
7
8 from planemo import (
9 io,
10 network_util
11 )
12 from .config import galaxy_config
13 from .ephemeris_sleep import sleep
14 from .run import (
15 run_galaxy_command,
16 )
17
18
19 def serve(ctx, runnables=[], **kwds):
20 """Serve a Galaxy instance with artifacts defined by paths."""
21 try:
22 return _serve(ctx, runnables, **kwds)
23 except Exception as e:
24 ctx.vlog("Problem serving Galaxy", exception=e)
25 raise
26
27
28 def _serve(ctx, runnables, **kwds):
29 engine = kwds.get("engine", "galaxy")
30 if engine == "docker_galaxy":
31 kwds["dockerize"] = True
32
33 daemon = kwds.get("daemon", False)
34 if daemon:
35 kwds["no_cleanup"] = True
36
37 port = kwds.get("port", None)
38 if port is None:
39 port = network_util.get_free_port()
40 kwds["port"] = port
41
42 with galaxy_config(ctx, runnables, **kwds) as config:
43 cmd = config.startup_command(ctx, **kwds)
44 action = "Starting Galaxy"
45 exit_code = run_galaxy_command(
46 ctx,
47 cmd,
48 config.env,
49 action,
50 )
51 if exit_code:
52 message = "Problem running Galaxy command [%s]." % config.log_contents
53 io.warn(message)
54 raise Exception(message)
55 host = kwds.get("host", "127.0.0.1")
56
57 timeout = 500
58 galaxy_url = "http://%s:%s" % (host, port)
59 galaxy_alive = sleep(galaxy_url, verbose=ctx.verbose, timeout=timeout)
60 if not galaxy_alive:
61 raise Exception("Attempted to serve Galaxy at %s, but it failed to start in %d seconds." % (galaxy_url, timeout))
62 config.install_workflows()
63 if kwds.get("pid_file"):
64 real_pid_file = config.pid_file
65 if os.path.exists(config.pid_file):
66 os.symlink(real_pid_file, kwds["pid_file"])
67 else:
68 io.warn("Can't find Galaxy pid file [%s] to link" % real_pid_file)
69 return config
70
71
72 @contextlib.contextmanager
73 def shed_serve(ctx, install_args_list, **kwds):
74 """Serve a daemon instance of Galaxy with specified repositories installed."""
75 with serve_daemon(ctx, **kwds) as config:
76 install_deps = not kwds.get("skip_dependencies", False)
77 io.info("Installing repositories - this may take some time...")
78 for install_args in install_args_list:
79 install_args["install_tool_dependencies"] = install_deps
80 install_args["install_repository_dependencies"] = True
81 install_args["new_tool_panel_section_label"] = "Shed Installs"
82 config.install_repo(
83 **install_args
84 )
85 config.wait_for_all_installed()
86 yield config
87
88
89 @contextlib.contextmanager
90 def serve_daemon(ctx, runnables=[], **kwds):
91 """Serve a daemonized Galaxy instance with artifacts defined by paths."""
92 config = None
93 try:
94 kwds["daemon"] = True
95 config = serve(ctx, runnables, **kwds)
96 yield config
97 finally:
98 if config:
99 if ctx.verbose:
100 print("Galaxy Log:")
101 print(config.log_contents)
102 config.kill()
103 if not kwds.get("no_cleanup", False):
104 config.cleanup()
105
106
107 def sleep_for_serve():
108 # This is bad, do something better...
109 time.sleep(1000000)
110
111
112 __all__ = (
113 "serve",
114 "serve_daemon",
115 "shed_serve",
116 )