Merge pull request #3239 from kleesc/IPResolver-fix

UpdateIPRange thread start on the 1st call to _get_location_function
This commit is contained in:
Kenny Lee Sin Cheong 2018-09-05 13:45:50 -04:00 committed by GitHub
commit 56809ef125
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -84,8 +84,6 @@ class IPResolver(IPResolverInterface):
self.app = app self.app = app
self.geoip_db = geoip2.database.Reader('util/ipresolver/GeoLite2-Country.mmdb') self.geoip_db = geoip2.database.Reader('util/ipresolver/GeoLite2-Country.mmdb')
self._worker = _UpdateIPRange(_UPDATE_INTERVAL) self._worker = _UpdateIPRange(_UPDATE_INTERVAL)
if not app.config.get('TESTING', False):
self._worker.start()
@ttl_cache(maxsize=100, ttl=600) @ttl_cache(maxsize=100, ttl=600)
def is_ip_possible_threat(self, ip_address): def is_ip_possible_threat(self, ip_address):
@ -131,6 +129,8 @@ class IPResolver(IPResolverInterface):
return location_function(ip_address) return location_function(ip_address)
def _get_location_function(self): def _get_location_function(self):
if not self.app.config.get('TESTING', False) and not self._worker.is_alive():
self._worker.start()
try: try:
cache = CACHE cache = CACHE
sync_token = cache.get('sync_token', None) sync_token = cache.get('sync_token', None)