Skip to content

Commit 9ef0afc

Browse files
feat: update OpenFeature Provider with initialize and shutdown methods
1 parent 90de072 commit 9ef0afc

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

devcycle_python_sdk/open_feature_provider/provider.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import logging
2+
import time
23

34
from typing import Any, Optional, Union, List
45

@@ -9,7 +10,7 @@
910
from openfeature.provider.metadata import Metadata
1011
from openfeature.evaluation_context import EvaluationContext
1112
from openfeature.flag_evaluation import FlagResolutionDetails, Reason
12-
from openfeature.exception import ErrorCode, InvalidContextError, TypeMismatchError
13+
from openfeature.exception import ErrorCode, InvalidContextError, TypeMismatchError, GeneralError
1314
from openfeature.hook import Hook
1415

1516
logger = logging.getLogger(__name__)
@@ -26,11 +27,27 @@ def __init__(self, devcycle_client: AbstractDevCycleClient):
2627
self.client = devcycle_client
2728
self.meta_data = Metadata(name=f"DevCycle {self.client.get_sdk_platform()}")
2829

30+
def initialize(self, evaluation_context: EvaluationContext) -> None:
31+
timeout = 2
32+
start_time = time.time()
33+
34+
# Wait for the client to be initialized or timeout
35+
while not self.client.is_initialized():
36+
if time.time() - start_time > timeout:
37+
raise GeneralError(f"DevCycleProvider initialization timed out after {timeout} seconds")
38+
time.sleep(0.1) # Sleep briefly to avoid busy waiting
39+
40+
if self.client.is_initialized():
41+
logger.debug("DevCycleProvider initialized successfully")
42+
43+
def shutdown(self) -> None:
44+
self.client.close()
45+
2946
def get_metadata(self) -> Metadata:
3047
return self.meta_data
3148

3249
def get_provider_hooks(self) -> List[Hook]:
33-
return []
50+
return []
3451

3552
def _resolve(
3653
self,

0 commit comments

Comments
 (0)