1515class BigSegmentStoreStatusProviderImpl (BigSegmentStoreStatusProvider ):
1616 """
1717 Default implementation of the BigSegmentStoreStatusProvider interface.
18-
18+
1919 The real implementation of getting the status is in BigSegmentStoreManager - we pass in a lambda that
2020 allows us to get the current status from that class. So this class provides a facade for that, and
2121 also adds the listener mechanism.
2222 """
23+
2324 def __init__ (self , status_getter : Callable [[], BigSegmentStoreStatus ]):
2425 self .__status_getter = status_getter
2526 self .__status_listeners = Listeners ()
2627 self .__last_status = None # type: Optional[BigSegmentStoreStatus]
27-
28+
2829 @property
2930 def status (self ) -> BigSegmentStoreStatus :
3031 return self .__status_getter ()
@@ -43,15 +44,17 @@ def _update_status(self, new_status: BigSegmentStoreStatus):
4344 self .__last_status = new_status
4445 self .__status_listeners .notify (new_status )
4546
47+
4648class BigSegmentStoreManager :
4749 # use EMPTY_MEMBERSHIP as a singleton whenever a membership query returns None; it's safe to reuse it
4850 # because we will never modify the membership properties after they're queried
4951 EMPTY_MEMBERSHIP = {} # type: dict
50-
52+
5153 """
5254 Internal component that decorates the Big Segment store with caching behavior, and also polls the
5355 store to track its status.
5456 """
57+
5558 def __init__ (self , config : BigSegmentsConfig ):
5659 self .__store = config .store
5760
@@ -61,8 +64,8 @@ def __init__(self, config: BigSegmentsConfig):
6164 self .__poll_task = None # type: Optional[RepeatingTask]
6265
6366 if self .__store :
64- self .__cache = ExpiringDict (max_len = config .context_cache_size , max_age_seconds = config .context_cache_time )
65- self .__poll_task = RepeatingTask (config .status_poll_interval , 0 , self .poll_store_and_update_status )
67+ self .__cache = ExpiringDict (max_len = config .context_cache_size , max_age_seconds = config .context_cache_time )
68+ self .__poll_task = RepeatingTask ("ldclient.bigsegment.status-poll" , config .status_poll_interval , 0 , self .poll_store_and_update_status )
6669 self .__poll_task .start ()
6770
6871 def stop (self ):
@@ -74,7 +77,7 @@ def stop(self):
7477 @property
7578 def status_provider (self ) -> BigSegmentStoreStatusProvider :
7679 return self .__status_provider
77-
80+
7881 def get_user_membership (self , user_key : str ) -> Tuple [Optional [dict ], str ]:
7982 if not self .__store :
8083 return (None , BigSegmentsStatus .NOT_CONFIGURED )
@@ -101,7 +104,7 @@ def get_status(self) -> BigSegmentStoreStatus:
101104 return status if status else self .poll_store_and_update_status ()
102105
103106 def poll_store_and_update_status (self ) -> BigSegmentStoreStatus :
104- new_status = BigSegmentStoreStatus (False , False ) # default to "unavailable" if we don't get a new status below
107+ new_status = BigSegmentStoreStatus (False , False ) # default to "unavailable" if we don't get a new status below
105108 if self .__store :
106109 try :
107110 metadata = self .__store .get_metadata ()
@@ -115,5 +118,6 @@ def poll_store_and_update_status(self) -> BigSegmentStoreStatus:
115118 def is_stale (self , timestamp ) -> bool :
116119 return (timestamp is None ) or ((int (time .time () * 1000 ) - timestamp ) >= self .__stale_after_millis )
117120
121+
118122def _hash_for_user_key (user_key : str ) -> str :
119123 return base64 .b64encode (sha256 (user_key .encode ('utf-8' )).digest ()).decode ('utf-8' )
0 commit comments