Move serverkeyworker into its own package
This commit is contained in:
parent
457f685952
commit
3b496e2759
4 changed files with 1 additions and 1 deletions
27
workers/servicekeyworker/servicekeyworker.py
Normal file
27
workers/servicekeyworker/servicekeyworker.py
Normal file
|
@ -0,0 +1,27 @@
|
|||
import logging
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
from app import app, instance_keys
|
||||
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.
|
||||
"""
|
||||
expiration = timedelta(minutes=instance_keys.service_key_expiration)
|
||||
logger.debug('Starting refresh of automatic service keys')
|
||||
set_key_expiration(instance_keys.local_key_id, datetime.now() + expiration)
|
||||
logger.debug('Finished refresh of automatic service keys')
|
||||
|
||||
if __name__ == "__main__":
|
||||
worker = ServiceKeyWorker()
|
||||
worker.start()
|
Reference in a new issue