-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
catch RequestLimitExceeded exceptions and do several retries with sle… #12
base: master
Are you sure you want to change the base?
Changes from 1 commit
404bbb6
5e8d3d3
518f782
bdb76cb
f1504d8
12d74d5
5388741
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,10 +12,14 @@ | |
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
import logging | ||
import time | ||
|
||
from boto.exception import NoAuthHandlerFound | ||
from exceptions import * | ||
|
||
import boto | ||
from boto import ec2 | ||
|
||
|
||
from backup_monkey.exceptions import BackupMonkeyException | ||
|
||
__all__ = ('BackupMonkey', 'Logging') | ||
|
@@ -115,7 +119,22 @@ def snapshot_volumes(self): | |
description_parts.append(volume.attach_data.device) | ||
description = ' '.join(description_parts) | ||
log.info('Creating snapshot of %s: %s', volume.id, description) | ||
volume.create_snapshot(description) | ||
for attempt in range(5): | ||
try: | ||
volume.create_snapshot(description) | ||
except boto.exception.EC2ResponseError, e: | ||
log.error("Encountered Error %s on volume %s", e.error_code, volume.id) | ||
break | ||
except boto.exception.BotoServerError, e: | ||
log.error("Encountered Error %s on volume %s, waiting %d seconds then retrying", e.error_code, volume.id, attempt) | ||
time.sleep(attempt) | ||
break | ||
else: | ||
break | ||
else: | ||
log.error("Encountered Error %s on volume %s, %d retries failed, continuing", e.error_code, volume.id, attempt) | ||
continue | ||
|
||
return True | ||
|
||
|
||
|
@@ -147,7 +166,22 @@ def remove_old_snapshots(self): | |
for i in range(self._snapshots_per_volume, num_snapshots): | ||
snapshot = most_recent_snapshots[i] | ||
log.info(' Deleting %s: %s', snapshot.id, snapshot.description) | ||
snapshot.delete() | ||
for attempt in range(5): | ||
try: | ||
snapshot.delete() | ||
except boto.exception.EC2ResponseError, e: | ||
log.error("Encountered Error %s on volume %s", e.error_code, volume.id) | ||
break | ||
except boto.exception.BotoServerError, e: | ||
log.error("Encountered Error %s on volume %s, waiting %d seconds then retrying", e.error_code, volume.id, attempt) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here is snapshot related, snapshot id in log should be better. |
||
time.sleep(attempt) | ||
break | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. After sleep, it should not break but continue. |
||
else: | ||
break | ||
else: | ||
log.error("Encountered Error %s on volume %s, %d retries failed, continuing", e.error_code, volume.id, attempt) | ||
continue | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No need to put continue here. |
||
|
||
return True | ||
|
||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
most of code and logic for snapshot and volume are same, I use a func wrapper to do it.