Skip to content

Commit a14b1bb

Browse files
committed
add scheduledRefreshTimeZones func support to python
cover with tests
1 parent 9685e3a commit a14b1bb

File tree

4 files changed

+64
-2
lines changed

4 files changed

+64
-2
lines changed

packages/cubejs-backend-native/js/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,8 @@ export interface PyConfiguration {
354354
checkAuth?: (req: unknown, authorization: string) => Promise<{ 'security_context'?: unknown }>
355355
queryRewrite?: (query: unknown, ctx: unknown) => Promise<unknown>
356356
contextToApiScopes?: () => Promise<string[]>
357+
scheduledRefreshContexts?: () => Promise<string[]>
358+
scheduledRefreshTimeZones?: () => Promise<string[]>
357359
contextToRoles?: (ctx: unknown) => Promise<string[]>
358360
}
359361

packages/cubejs-backend-native/python/cube/src/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class Configuration:
4444
allow_js_duplicate_props_in_schema: bool
4545
jwt: Dict
4646
scheduled_refresh_timer: Any
47-
scheduled_refresh_timezones: list[str]
47+
scheduled_refresh_timezones: Union[Callable[[RequestContext], list[str]], list[str]]
4848
scheduled_refresh_concurrency: int
4949
scheduled_refresh_batch_size: int
5050
compiler_cache_size: int
@@ -93,7 +93,6 @@ def __init__(self):
9393
self.process_subscriptions_interval = None
9494
self.jwt = None
9595
self.scheduled_refresh_timer = None
96-
self.scheduled_refresh_timezones = None
9796
self.scheduled_refresh_concurrency = None
9897
self.scheduled_refresh_batch_size = None
9998
self.compiler_cache_size = None
@@ -118,6 +117,7 @@ def __init__(self):
118117
self.query_rewrite = None
119118
self.extend_context = None
120119
self.scheduled_refresh_contexts = None
120+
self.scheduled_refresh_timezones = None
121121
self.context_to_api_scopes = None
122122
self.repository_factory = None
123123
self.schema_version = None

packages/cubejs-backend-native/test/config.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,34 @@ async def context_to_api_scopes():
3333
return ["meta", "data", "jobs"]
3434

3535

36+
@config
37+
async def scheduled_refresh_time_zones(ctx):
38+
print("[python] scheduled_refresh_time_zones ctx=", ctx)
39+
return ["Europe/Kyiv", "Antarctica/Troll", "Australia/Sydney"]
40+
41+
42+
@config
43+
async def scheduled_refresh_contexts(ctx):
44+
print("[python] scheduled_refresh_contexts ctx=", ctx)
45+
return [
46+
{
47+
"securityContext": {
48+
"appid": 'test1', "u": { "prop1": "value1" }
49+
}
50+
},
51+
{
52+
"securityContext": {
53+
"appid": 'test2', "u": { "prop1": "value2" }
54+
}
55+
},
56+
{
57+
"securityContext": {
58+
"appid": 'test3', "u": { "prop1": "value3" }
59+
}
60+
},
61+
]
62+
63+
3664
@config
3765
def schema_version(ctx):
3866
print("[python] schema_version", ctx)

packages/cubejs-backend-native/test/python.test.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,38 @@ suite('Python Config', () => {
8383
expect(await config.contextToApiScopes()).toEqual(['meta', 'data', 'jobs']);
8484
});
8585

86+
test('scheduled_refresh_time_zones', async () => {
87+
if (!config.scheduledRefreshTimeZones) {
88+
throw new Error('scheduledRefreshTimeZones was not defined in config.py');
89+
}
90+
91+
expect(await config.scheduledRefreshTimeZones()).toEqual(['Europe/Kyiv', 'Antarctica/Troll', 'Australia/Sydney']);
92+
});
93+
94+
test('scheduled_refresh_contexts', async () => {
95+
if (!config.scheduledRefreshContexts) {
96+
throw new Error('scheduledRefreshContexts was not defined in config.py');
97+
}
98+
99+
expect(await config.scheduledRefreshContexts()).toEqual([
100+
{
101+
securityContext: {
102+
appid: 'test1', u: { prop1: 'value1' }
103+
}
104+
},
105+
{
106+
securityContext: {
107+
appid: 'test2', u: { prop1: 'value2' }
108+
}
109+
},
110+
{
111+
securityContext: {
112+
appid: 'test3', u: { prop1: 'value3' }
113+
}
114+
},
115+
]);
116+
});
117+
86118
test('repository factory', async () => {
87119
if (!config.repositoryFactory) {
88120
throw new Error('repositoryFactory was not defined in config.py');

0 commit comments

Comments
 (0)