Reputation: 1
I’m working on a Cube.js project where I need to configure pre-aggregations to refresh at regular intervals, specifically every 12 hours or at a specific time like 4:00 AM UTC. I’ve set up a cube to optimize query performance using pre-aggregations, but I'm unsure how to configure the refresh schedule to achieve this behavior.
When testing the last refresh using Postman, for example, checking every 5 minutes, Cube.js doesn’t seem to respect the scheduled refresh time, even though I’ve set it for every 5 minutes. The refresh happens inconsistently.
Here’s an example of my Orders cube where I want to apply these configurations:
cube('Orders', {
sql: `SELECT id, user_id, total_price, added_at FROM public.orders`,
preAggregations: {
OrdersSummary: {
dimensions: [Orders.id, Orders.userId, Orders.totalPrice],
refreshKey: {
every: '12 hour'
}
},
OrdersDetails: {
dimensions: [Orders.id, Orders.userId, Orders.addedAt],
refreshKey: {
every: '12 hour'
}
}
},
dimensions: {
id: {
sql: `id`,
type: `number`,
primaryKey: true
},
userId: {
sql: `user_id`,
type: `number`
},
totalPrice: {
sql: `total_price`,
type: `number`
},
addedAt: {
sql: `added_at`,
type: `time`
}
}
});
Upvotes: 0
Views: 199
Reputation: 1
Have you tried it with cron? Like this:
refresh_key: {
every: "0 13 * * *",
timezone: "Europe/Amsterdam",
}
This refreshes the preaggregation everyday at 13.00h Amsterdam time.
This you can use to run at 01.00 and 13.00
0 1,13 * * *
https://cube.dev/docs/reference/data-model/cube#refresh_key
Upvotes: 0