import logging import time from app import app from util.ipresolver import update_resolver_datafiles from workers.worker import Worker logger = logging.getLogger(__name__) class IPResolverUpdateWorker(Worker): def __init__(self): super(IPResolverUpdateWorker, self).__init__() # Update now. try: self._update_resolver_datafiles() except: logger.exception('Initial update of range data files failed') self.add_operation(self._update_resolver_datafiles, app.config.get('IP_RESOLVER_DATAFILE_REFRESH', 60 * 60 * 2) * 60) def _update_resolver_datafiles(self): logger.debug('Starting refresh of IP resolver data files') update_resolver_datafiles() logger.debug('Finished refresh of IP resolver data files') if __name__ == "__main__": # Only enable if CloudFronted storage is used. requires_resolution = False for storage_type, _ in app.config.get('DISTRIBUTED_STORAGE_CONFIG', {}).values(): if storage_type == 'CloudFrontedS3Storage': requires_resolution = True break if not requires_resolution: logger.debug('Cloud fronted storage not used; skipping') while True: time.sleep(10000) worker = IPResolverUpdateWorker() worker.start()