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/servicekeyworker/servicekeyworker.py

30 lines
970 B
Python
Raw Normal View History

import logging
from datetime import datetime, timedelta
from app import app, instance_keys
from workers.servicekeyworker.models_pre_oci import pre_oci_model as model
from workers.worker import Worker
logger = logging.getLogger(__name__)
2017-07-12 13:37:51 +00:00
class ServiceKeyWorker(Worker):
def __init__(self):
super(ServiceKeyWorker, self).__init__()
self.add_operation(self._refresh_service_key,
2017-07-12 13:37:51 +00:00
app.config.get('INSTANCE_SERVICE_KEY_REFRESH', 60) * 60)
def _refresh_service_key(self):
"""
Refreshes the instance's active service key so it doesn't get garbage collected.
"""
expiration = timedelta(minutes=instance_keys.service_key_expiration)
logger.debug('Starting refresh of automatic service keys')
model.set_key_expiration(instance_keys.local_key_id, datetime.utcnow() + expiration)
logger.debug('Finished refresh of automatic service keys')
2017-07-12 13:37:51 +00:00
if __name__ == "__main__":
worker = ServiceKeyWorker()
worker.start()