Skip to content
This repository was archived by the owner on Sep 12, 2018. It is now read-only.

Commit a95c000

Browse files
committed
try..except around redis_conn uses
1 parent 0eda142 commit a95c000

File tree

3 files changed

+28
-8
lines changed

3 files changed

+28
-8
lines changed

docker_registry/images.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -289,8 +289,7 @@ def put_image_checksum(image_id):
289289
# Checksum is ok, we remove the marker
290290
store.remove(mark_path)
291291
# We trigger a task on the diff worker if it's running
292-
if cache.redis_conn:
293-
layers.diff_queue.push(image_id)
292+
layers.enqueue_diff(image_id)
294293
return toolkit.response()
295294

296295

docker_registry/lib/layers.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# -*- coding: utf-8 -*-
22

3+
import logging
34
import tarfile
45
import tempfile
56

@@ -28,10 +29,21 @@
2829
tarfile.GNUTYPE_SPARSE: 'S',
2930
}
3031

32+
logger = logging.getLogger(__name__)
33+
3134
# queue for requesting diff calculations from workers
3235
diff_queue = rqueue.CappedCollection(cache.redis_conn, "diff-worker", 1024)
3336

3437

38+
39+
def enqueue_diff(image_id):
40+
try:
41+
if cache.redis_conn:
42+
layers.diff_queue.push(image_id)
43+
except cache.redis.exceptions.ConnectionError:
44+
logger.warning('Diff queue: Redis connection error')
45+
46+
3547
def generate_ancestry(image_id, parent_id=None):
3648
if not parent_id:
3749
store.put_content(store.image_ancestry_path(image_id),

docker_registry/lib/mirroring.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,14 @@ def wrapper(namespace, repository, *args, **kwargs):
105105
# client GETs a single tag
106106
tag_path = store.tag_path(namespace, repository, kwargs['tag'])
107107

108-
data = cache.redis_conn.get('{0}:{1}'.format(
109-
cache.cache_prefix, tag_path
110-
))
108+
try:
109+
data = cache.redis_conn.get('{0}:{1}'.format(
110+
cache.cache_prefix, tag_path
111+
))
112+
except cache.redis.exceptions.ConnectionError:
113+
data = None
114+
logger.warning('Tags cache: Redis connection error')
115+
111116
if data is not None:
112117
return toolkit.response(data=data, raw=True)
113118
source_resp = lookup_source(
@@ -117,9 +122,13 @@ def wrapper(namespace, repository, *args, **kwargs):
117122
return resp
118123
data = source_resp.content
119124
headers = _response_headers(source_resp.headers)
120-
cache.redis_conn.setex('{0}:{1}'.format(
121-
cache.cache_prefix, tag_path
122-
), tags_cache_ttl, data)
125+
try:
126+
cache.redis_conn.setex('{0}:{1}'.format(
127+
cache.cache_prefix, tag_path
128+
), tags_cache_ttl, data)
129+
except cache.redis.exceptions.ConnectionError:
130+
logger.warning('Tags cache: Redis connection error')
131+
123132
return toolkit.response(data=data, headers=headers,
124133
raw=True)
125134
return wrapper

0 commit comments

Comments
 (0)