summaryrefslogtreecommitdiff
path: root/docs/gl_objects/builds.py
diff options
context:
space:
mode:
authorGauvain Pocentek <gauvain@pocentek.net>2016-07-17 14:09:39 +0200
committerGauvain Pocentek <gauvain@pocentek.net>2016-07-17 14:09:39 +0200
commit94aea524a23ac428259bae327a1fccdd2f5b841d (patch)
treef8c3c8a90f4baf8ef271f6df3572de7991bbe22c /docs/gl_objects/builds.py
parent8e6a9442324926ed1dec0a8bfaf77792e4bdb10f (diff)
downloadgitlab-94aea524a23ac428259bae327a1fccdd2f5b841d.tar.gz
Allow to stream the downloads when appropriate
Some API calls will download possibly large data, resulting in a high memory usage and out-of-memory errors. For these API calls use the requests streaming capabilities and download chunked data. The caller is responsible of providing a callable to actually store the data. The default callable just prints the data on stdout.
Diffstat (limited to 'docs/gl_objects/builds.py')
-rw-r--r--docs/gl_objects/builds.py13
1 files changed, 13 insertions, 0 deletions
diff --git a/docs/gl_objects/builds.py b/docs/gl_objects/builds.py
index 4b663c6..c535cb2 100644
--- a/docs/gl_objects/builds.py
+++ b/docs/gl_objects/builds.py
@@ -77,6 +77,19 @@ project.builds.get(build_id)
build.artifacts()
# end artifacts
+# stream artifacts
+class Foo(object):
+ def __init__(self):
+ self._fd = open('artifacts.zip', 'w')
+
+ def __call__(self, chunk):
+ self._fd.write(chunk)
+
+target = Foo()
+build.artifacts(streamed=True, streamed=True, action=target)
+del(target) # flushes data on disk
+# end stream artifacts
+
# keep artifacts
build.keep_artifacts()
# end keep artifacts