-
-
Save streeter/70a3486823e458a806c4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
from sentry.utils.runner import configure | |
configure(config_path='sentry.conf.py') | |
from datetime import datetime, timedelta | |
from sentry.app import tsdb | |
def cleanup_connection(connection, epoch): | |
def delete(key): | |
print('>> Removing key {}'.format(key)) | |
connection.delete(key) | |
for key in connection.scan_iter('ts:*'): | |
bits = key.split(':', 4) | |
assert len(bits) == 4 | |
if int(bits[2]) < epoch: # 7 days | |
delete(key) | |
def cleanup(): | |
epoch = tsdb.normalize_to_rollup(datetime.utcnow() - timedelta(days=7), 3600) | |
print('Epoch set to {}'.format(epoch)) | |
for connection in tsdb.conn.hosts.itervalues(): | |
print('> Checking connection {}'.format(connection)) | |
cleanup_connection(connection, epoch) | |
if __name__ == '__main__': | |
cleanup() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment