Skip to content

Commit 5f040e1

Browse files
committed
Support synchronous refresh in the testing refresh-reporting endpoint
When wait=true is provided, run ReportingAPI::RefreshJob inline and respond with 200, so test callers can block until the materialised view is refreshed instead of polling. Default async behaviour is preserved.
1 parent 11952f1 commit 5f040e1

2 files changed

Lines changed: 16 additions & 2 deletions

File tree

app/controllers/api/testing/reporting_refresh_controller.rb

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@
22

33
class API::Testing::ReportingRefreshController < API::Testing::BaseController
44
def create
5-
ReportingAPI::RefreshJob.perform_later
6-
render status: :accepted
5+
if params[:wait].present?
6+
ReportingAPI::RefreshJob.perform_now
7+
render status: :ok
8+
else
9+
ReportingAPI::RefreshJob.perform_later
10+
render status: :accepted
11+
end
712
end
813
end

spec/controllers/api/testing/reporting_refresh_controller_spec.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,14 @@
77
get :create
88
expect(response).to have_http_status(:accepted)
99
end
10+
11+
context "when wait=true" do
12+
it "runs the refresh synchronously and responds with ok status" do
13+
expect(ReportingAPI::RefreshJob).to receive(:perform_now)
14+
expect(ReportingAPI::RefreshJob).not_to receive(:perform_later)
15+
get :create, params: { wait: "true" }
16+
expect(response).to have_http_status(:ok)
17+
end
18+
end
1019
end
1120
end

0 commit comments

Comments
 (0)