Skip to content

Commit e061e67

Browse files
committed
[NEP-18090]: Adding en endpoint for warming up the dataset cache
Version upgrade Update changlog Validations for dashboard_id Added spec cases
1 parent 47037e1 commit e061e67

File tree

5 files changed

+50
-3
lines changed

5 files changed

+50
-3
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
## Change Log
22

3+
## 0.1.6 - 2024-07-10
4+
5+
* added a class **WarmUpCache** to hit the 'api/v1/dataset/warm_up_cache' endpoint to warm up the cache of all the datasets for a particular dashaboard being passed to the class - https://github.com/rdytech/superset-client/pull/28
6+
37
## 0.1.5 - 2024-05-10
48

59
* add multi config for multi env creds https://github.com/rdytech/superset-client/pull/22

Gemfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ GIT
1414
PATH
1515
remote: .
1616
specs:
17-
superset (0.1.5)
17+
superset (0.1.6)
1818
dotenv (~> 2.7)
1919
enumerate_it (~> 1.7.0)
2020
faraday (~> 1.0)

lib/superset/dataset/warm_up_cache.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,20 @@ def initialize(dashboard_id:)
99
end
1010

1111
def perform
12+
validate_dashboard_id
1213
dataset_details = fetch_dataset_details(dashboard_id)
1314
dataset_details.each do |dataset|
1415
begin
1516
client.put(route, params(dashboard_id, dataset["datasource_name"], dataset["name"]))
1617
rescue => e
1718
Rollbar.error(e.message)
1819
end
19-
end
20+
end
21+
return "Dashboard warmed up"
22+
end
23+
24+
def validate_dashboard_id
25+
raise InvalidParameterError, "dashboard_id must be present and must be an integer" unless dashboard_id.present? && dashboard_id.is_a?(Integer)
2026
end
2127

2228
def params(dashboard_id, dataset_name, db_name)

lib/superset/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# frozen_string_literal: true
22

33
module Superset
4-
VERSION = "0.1.5"
4+
VERSION = "0.1.6"
55
end
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
require 'spec_helper'
2+
3+
RSpec.describe Superset::Dataset::WarmUpCache do
4+
subject { described_class.new(dashboard_id: dashboard_id) }
5+
let(:dashboard_id) { 1 }
6+
let(:response) { nil }
7+
8+
before do
9+
allow(subject).to receive(:response).and_return(response)
10+
end
11+
12+
describe '.perform' do
13+
context 'when dashboard_id is not present' do
14+
let(:dashboard_id) { nil }
15+
16+
it 'raises an error' do
17+
expect { subject.perform }.to raise_error(Superset::Request::InvalidParameterError, "dashboard_id must be present and must be an integer")
18+
end
19+
end
20+
21+
context 'when dashboard_id is not an integer' do
22+
let(:dashboard_id) { 'string' }
23+
24+
it 'raises an error' do
25+
expect { subject.perform }.to raise_error(Superset::Request::InvalidParameterError, "dashboard_id must be present and must be an integer")
26+
end
27+
end
28+
29+
context 'when dashboard_id is an integer' do
30+
let(:response) { 'Dashboard warmed up' }
31+
32+
it 'warms up the dataset' do
33+
expect(subject.perform).to eq response
34+
end
35+
end
36+
end
37+
end

0 commit comments

Comments
 (0)