This repository has been archived on 2020-03-24. You can view files and clone it, but cannot push or open issues or pull requests.
quay/workers/service_key_worker.py
2016-05-03 13:11:21 -04:00

32 lines
1,022 B
Python

import logging
from datetime import datetime, timedelta
from app import app
from data.model.service_keys import set_key_expiration
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('INSTANCE_SERVICE_KEY_REFRESH', 60)*60)
def _refresh_service_keys(self):
"""
Refreshes active service keys so they don't get garbage collected.
"""
with open("/conf/quay.kid") as f:
kid = f.read()
minutes_until_expiration = app.config.get('INSTANCE_SERVICE_KEY_EXPIRATION', 120)
expiration = timedelta(minutes=minutes_until_expiration)
logger.debug('Starting refresh of automatic service keys')
set_key_expiration(kid, datetime.now() + expiration)
logger.debug('Finished refresh of automatic service keys')
if __name__ == "__main__":
worker = ServiceKeyWorker()
worker.start()