Skip to content

Commit bc99bb1

Browse files
committed
docs: Multi-tenant scheduled_refresh_time_zones
1 parent 049ac33 commit bc99bb1

File tree

2 files changed

+46
-14
lines changed

2 files changed

+46
-14
lines changed

docs/pages/product/configuration/advanced/multitenancy.mdx

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,19 @@ Cube supports multitenancy out of the box, both on database and data model
99
levels. Multiple drivers are also supported, meaning that you can have one
1010
customer’s data in MongoDB and others in Postgres with one Cube instance.
1111

12-
There are 6 [configuration options][ref-config-opts] you can leverage to make
12+
There are several [configuration options][ref-config-opts] you can leverage for
1313
your multitenancy setup. You can use all of them or just a couple, depending on
1414
your specific case. The options are:
1515

16-
- `contextToAppId`
17-
- `contextToOrchestratorId`
18-
- `driverFactory`
19-
- `repositoryFactory`
20-
- `preAggregationsSchema`
21-
- `queryRewrite`
16+
- `context_to_app_id`
17+
- `schema_version`
18+
- `repository_factory`
19+
- `driver_factory`
20+
- `context_to_orchestrator_id`
21+
- `pre_aggregations_schema`
22+
- `query_rewrite`
23+
- `scheduled_refresh_contexts`
24+
- `scheduled_refresh_time_zones`
2225

2326
All of the above options are functions, which you provide to Cube in the
2427
[`cube.js` configuration file][ref-config]. The functions accept one argument -
@@ -360,12 +363,12 @@ module.exports = {
360363

361364
If you need scheduled refreshes for your pre-aggregations in a multi-tenant
362365
deployment, ensure you have configured
363-
[`scheduledRefreshContexts`][ref-config-refresh-ctx] correctly. You may also
364-
need to configure [`scheduledRefreshTimeZones`][ref-config-refresh-tz].
366+
[`scheduled_refresh_contexts`][ref-config-refresh-ctx] correctly. You may also
367+
need to configure [`scheduled_refresh_time_zones`][ref-config-refresh-tz].
365368

366369
<WarningBox>
367370

368-
Leaving [`scheduledRefreshContexts`][ref-config-refresh-ctx] unconfigured will
371+
Leaving [`scheduled_refresh_contexts`][ref-config-refresh-ctx] unconfigured will
369372
lead to issues where the security context will be `undefined`. This is because
370373
there is no way for Cube to know how to generate a context without the required
371374
input.

docs/pages/reference/configuration/config.mdx

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -654,32 +654,61 @@ You may also need to configure
654654
This option specifies a list of time zones that pre-aggregations will be built
655655
for. It has impact on [pre-aggregation matching][ref-matching-preaggs].
656656

657-
You can specify multiple timezones in the [TZ Database Name][link-wiki-tz]
658-
format, e.g., `America/Los_Angeles`:
657+
Either an array or function returning an array can be passed. Providing a function
658+
allows to set the time zones dynamically depending on the security context.
659+
660+
Time zones should be specified in the [TZ Database Name][link-wiki-tz] format,
661+
e.g., `America/Los_Angeles`.
659662

660663
<CodeTabs>
661664

662665
```python
663666
from cube import config
664667

668+
# An array of time zones
665669
config.scheduled_refresh_time_zones = [
666670
'America/Vancouver',
667671
'America/Toronto'
668672
]
673+
674+
# Alternatively, a function returning an array of time zones
675+
@config('scheduled_refresh_time_zones')
676+
def scheduled_refresh_time_zones(ctx: dict) -> list[str]:
677+
time_zones = {
678+
'tenant_1': ['America/New_York'],
679+
'tenant_2': ['America/Chicago'],
680+
'tenant_3': ['America/Los_Angeles']
681+
}
682+
default_time_zones = ['UTC']
683+
tenant_id = ctx['securityContext']['tenant_id']
684+
return time_zones.get(tenant_id, default_time_zones)
669685
```
670686

671687
```javascript
672688
module.exports = {
689+
// An array of time zones
673690
scheduledRefreshTimeZones: [
674691
'America/Vancouver',
675692
'America/Toronto'
676-
]
693+
],
694+
695+
// Alternatively, a function returning an array of time zones
696+
scheduledRefreshTimeZones: ({ securityContext }) => {
697+
let time_zones = {
698+
'tenant_1': ['America/New_York'],
699+
'tenant_2': ['America/Chicago'],
700+
'tenant_3': ['America/Los_Angeles']
701+
}
702+
let default_time_zones = ['UTC']
703+
let tenant_id = securityContext.tenant_id
704+
return time_zones[tenant_id] || default_time_zones
705+
}
677706
};
678707
```
679708

680709
</CodeTabs>
681710

682-
The default value is a list of a single time zone. `UTC`.
711+
The default value is a list of a single time zone: `UTC`.
683712

684713
This configuration option can also be set using the
685714
`CUBEJS_SCHEDULED_REFRESH_TIMEZONES` environment variable.

0 commit comments

Comments
 (0)