Skip to content

Commit

Permalink
make refresh code a daemon thread
Browse files Browse the repository at this point in the history
Signed-off-by: Stanley Opara <a-sopara@expediagroup.com>
  • Loading branch information
Stanley Opara committed Jun 5, 2024
1 parent c05b0db commit 2074959
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion sdk/python/feast/infra/registry/caching_registry.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import atexit
import logging
import threading
from abc import abstractmethod
Expand Down Expand Up @@ -33,7 +34,7 @@ def __init__(
)
self.allow_async_cache = allow_async_cache
if allow_async_cache:
threading.Timer(cache_ttl_seconds, self.refresh).start()
self._start_async_refresh(cache_ttl_seconds)

@abstractmethod
def _get_data_source(self, name: str, project: str) -> DataSource:
Expand Down Expand Up @@ -312,3 +313,12 @@ def _refresh_cached_registry_if_necessary(self):
if expired:
logger.info("Registry cache expired, so refreshing")
self.refresh()

def _start_async_refresh(self, cache_ttl_seconds):
self.registry_refresh_thread = threading.Timer(cache_ttl_seconds, self.refresh)
self.registry_refresh_thread.setDaemon(True)
self.registry_refresh_thread.start()
atexit.register(self._exit_handler)

def _exit_handler(self):
self.registry_refresh_thread.cancel()

0 comments on commit 2074959

Please sign in to comment.