service key worker to refresh automatic keys

This commit is contained in:
Evan Cordell 2016-04-29 10:51:22 -05:00 committed by Jimmy Zelinskie
parent 2242c6773d
commit a6f6a114c2
6 changed files with 82 additions and 18 deletions

View file

@ -0,0 +1,28 @@
import logging
from datetime import timedelta
from app import app
from data.model.service_keys import refresh_automatic_service_keys
from workers.worker import Worker
logger = logging.getLogger(__name__)
class ServiceKeyWorker(Worker):
def __init__(self):
super(ServiceKeyWorker, self).__init__()
self.add_operation(self._refresh_service_keys,
app.config.get('QUAY_SERVICE_KEY_REFRESH', 60)*60)
def _refresh_service_keys(self):
""" Refreshes active service keys so they don't get garbage collected. """
minutes_until_expiration = app.config.get('QUAY_SERVICE_KEY_EXPIRATION', 120)
expiration = timedelta(minutes=minutes_until_expiration)
logger.debug('Starting refresh of automatic service keys')
refresh_automatic_service_keys(expiration)
logger.debug('Finished refresh of automatic service keys')
if __name__ == "__main__":
worker = ServiceKeyWorker()
worker.start()