@@ -41,22 +41,57 @@ export default class ConfigurationRequestor {
41
41
createdAt : configResponse . createdAt ,
42
42
} ) ;
43
43
44
- // TODO: different polling intervals for bandit parameters
45
- const banditResponse = await this . httpClient . getBanditParameters ( ) ;
46
- if ( banditResponse ?. bandits ) {
47
- if ( ! this . banditModelConfigurationStore ) {
48
- throw new Error ( 'Bandit parameters fetched but no bandit configuration store provided' ) ;
49
- }
44
+ if ( this . requiresBanditModelConfigurationStoreUpdate ( configResponse . banditReferences ) ) {
45
+ const banditResponse = await this . httpClient . getBanditParameters ( ) ;
46
+ if ( banditResponse ?. bandits ) {
47
+ if ( ! this . banditModelConfigurationStore ) {
48
+ throw new Error ( 'Bandit parameters fetched but no bandit configuration store provided' ) ;
49
+ }
50
50
51
- await this . hydrateConfigurationStore ( this . banditModelConfigurationStore , {
52
- entries : banditResponse . bandits ,
53
- environment : configResponse . environment ,
54
- createdAt : configResponse . createdAt ,
55
- } ) ;
51
+ await this . hydrateConfigurationStore ( this . banditModelConfigurationStore , {
52
+ entries : banditResponse . bandits ,
53
+ environment : configResponse . environment ,
54
+ createdAt : configResponse . createdAt ,
55
+ } ) ;
56
+ }
56
57
}
57
58
}
58
59
}
59
60
61
+ private getLoadedBanditModelVersions (
62
+ banditModelConfigurationStore : IConfigurationStore < BanditParameters > | null ,
63
+ ) {
64
+ if ( banditModelConfigurationStore === null ) {
65
+ return [ ] ;
66
+ }
67
+ return Object . values ( banditModelConfigurationStore . entries ( ) ) . map (
68
+ ( banditParam : BanditParameters ) => banditParam . modelVersion ,
69
+ ) ;
70
+ }
71
+
72
+ private requiresBanditModelConfigurationStoreUpdate (
73
+ banditReferences : Record < string , BanditReference > ,
74
+ ) : boolean {
75
+ if ( ! this . banditModelConfigurationStore ) {
76
+ throw new Error ( 'Bandit parameters fetched but no bandit configuration store provided' ) ;
77
+ }
78
+ const referencedModelVersions = Object . values ( banditReferences ) . map (
79
+ ( banditReference : BanditReference ) => banditReference . modelVersion
80
+ ) ;
81
+
82
+ const banditModelVersionsInStore = this . getLoadedBanditModelVersions (
83
+ this . banditModelConfigurationStore ,
84
+ ) ;
85
+
86
+ referencedModelVersions . forEach ( ( modelVersion ) => {
87
+ if ( ! banditModelVersionsInStore . includes ( modelVersion ) ) {
88
+ return false ;
89
+ }
90
+ } ) ;
91
+
92
+ return true ;
93
+ }
94
+
60
95
private async hydrateConfigurationStore < T extends Entry > (
61
96
configurationStore : IConfigurationStore < T > | null ,
62
97
response : {
0 commit comments