Skip to content

Commit

Permalink
put all redis calls of the fragment API in try-catch blocks (#94)
Browse files Browse the repository at this point in the history
* Put all redis calls in try-czatch blocks

* Log redis failures as warnings rather than errors since they are not fatal
  • Loading branch information
flekschas authored and pkerpedjiev committed Feb 12, 2019
1 parent 50e30f7 commit 5a189e2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
21 changes: 18 additions & 3 deletions fragments/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,12 @@ def get_fragments_by_loci(request):
mat_b64 = pybase64.b64encode(np_to_png(matrix)).decode('ascii')

if not no_cache:
rdb.set('im_b64_%s' % id, mat_b64, 60 * 30)
try:
rdb.set('im_b64_%s' % id, mat_b64, 60 * 30)
except Exception as ex:
# error caching a tile
# log the error and carry forward, this isn't critical
logger.warn(ex)

matrices[i] = mat_b64

Expand All @@ -550,7 +555,12 @@ def get_fragments_by_loci(request):
results['previews2d'] = previews_2d

# Cache results for 30 minutes
rdb.set('frag_by_loci_%s' % uuid, pickle.dumps(results), 60 * 30)
try:
rdb.set('frag_by_loci_%s' % uuid, pickle.dumps(results), 60 * 30)
except Exception as ex:
# error caching a tile
# log the error and carry forward, this isn't critical
logger.warn(ex)

if encoding == 'image':
if len(matrices) == 1:
Expand Down Expand Up @@ -761,7 +771,12 @@ def fragments_by_chr(request):
results['fragments'] = fragments_arr

# Cache results for 30 mins
rdb.set('frag_by_chrom_%s' % uuid, pickle.dumps(results), 60 * 30)
try:
rdb.set('frag_by_chrom_%s' % uuid, pickle.dumps(results), 60 * 30)
except Exception as ex:
# error caching a tile
# log the error and carry forward, this isn't critical
logger.warn(ex)

return JsonResponse(results)

Expand Down
4 changes: 2 additions & 2 deletions tilesets/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ def tiles(request):
# there was an error accessing the cache server
# log the error and carry forward fetching the tile
# from the original data
logger.error(ex)
logger.warn(ex)

#tile_value = None

Expand Down Expand Up @@ -479,7 +479,7 @@ def tiles(request):
except Exception as ex:
# error caching a tile
# log the error and carry forward, this isn't critical
logger.error(ex)
logger.warn(ex)

if tile_id in transform_id_to_original_id:
original_tile_id = transform_id_to_original_id[tile_id]
Expand Down

0 comments on commit 5a189e2

Please sign in to comment.