refresh_links_for_backend: handling KeyboardInterrupt better

It now reports on the number of refreshed links before aborting.
This commit is contained in:
Sybren A. Stüvel 2016-07-27 11:58:39 +02:00
parent fbf7dd9596
commit 1312ededfb
2 changed files with 32 additions and 31 deletions

View File

@ -474,6 +474,7 @@ def refresh_links_for_backend(backend_name, chunk_size, expiry_seconds):
refreshed = 0 refreshed = 0
for file_doc in to_refresh: for file_doc in to_refresh:
try:
file_id = file_doc['_id'] file_id = file_doc['_id']
project_id = file_doc.get('project') project_id = file_doc.get('project')
if project_id is None: if project_id is None:
@ -501,8 +502,11 @@ def refresh_links_for_backend(backend_name, chunk_size, expiry_seconds):
log.warning('Skipping file %s, GCS forbids us access to project %s bucket.', log.warning('Skipping file %s, GCS forbids us access to project %s bucket.',
file_id, project_id) file_id, project_id)
continue continue
refreshed += 1 refreshed += 1
except KeyboardInterrupt:
log.warning('Aborting due to KeyboardInterrupt after refreshing %i links',
refreshed)
return
log.info('Refreshed %i links', refreshed) log.info('Refreshed %i links', refreshed)

View File

@ -593,10 +593,7 @@ def refresh_backend_links(backend_name, chunk_size=50, quiet=False, window=12):
chunk_size = int(chunk_size) # CLI parameters are passed as strings chunk_size = int(chunk_size) # CLI parameters are passed as strings
from application.modules import file_storage from application.modules import file_storage
try:
file_storage.refresh_links_for_backend(backend_name, chunk_size, window * 3600) file_storage.refresh_links_for_backend(backend_name, chunk_size, window * 3600)
except KeyboardInterrupt:
print('Aborted due to keyboard interrupt.')
@manager.command @manager.command