Skip to content

Commit 76b2db0

Browse files
author
Bogdan Tsechoev
committed
Merge branch 'refresh-on-demand' into 'dle-4-0'
feat: Refresh API method See merge request postgres-ai/database-lab!1019
2 parents 37ff43f + 483366a commit 76b2db0

File tree

3 files changed

+60
-0
lines changed

3 files changed

+60
-0
lines changed

engine/api/swagger-spec/dblab_openapi.yaml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,38 @@ paths:
224224
example:
225225
code: "UNAUTHORIZED"
226226
message: "Check your verification token."
227+
/full-refresh:
228+
post:
229+
tags:
230+
- Instance
231+
summary: Trigger full data refresh
232+
description: "Initiates a full data refresh."
233+
operationId: refresh
234+
parameters:
235+
- name: Verification-Token
236+
in: header
237+
required: true
238+
schema:
239+
type: string
240+
responses:
241+
200:
242+
description: Full refresh has been initiated
243+
content:
244+
application/json:
245+
schema:
246+
$ref: '#/components/schemas/FullRefresh'
247+
example:
248+
status: OK
249+
message: Full refresh started
250+
401:
251+
description: Unauthorized access
252+
content:
253+
application/json:
254+
schema:
255+
$ref: '#/components/schemas/Error'
256+
example:
257+
code: "UNAUTHORIZED"
258+
message: "Check your verification token."
227259
/snapshot:
228260
post:
229261
tags:
@@ -1876,3 +1908,12 @@ components:
18761908
format: date-time
18771909
message:
18781910
type: string
1911+
FullRefresh:
1912+
type: object
1913+
properties:
1914+
status:
1915+
type: string
1916+
example: OK
1917+
message:
1918+
type: string
1919+
example: Full refresh started

engine/internal/srv/routes.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -950,3 +950,19 @@ func (s *Server) healthCheck(w http.ResponseWriter, _ *http.Request) {
950950
return
951951
}
952952
}
953+
954+
func (s *Server) refresh(w http.ResponseWriter, r *http.Request) {
955+
go func() {
956+
if err := s.Retrieval.FullRefresh(context.Background()); err != nil {
957+
log.Err("failed to initiate full refresh", err)
958+
}
959+
}()
960+
961+
if err := api.WriteJSON(w, http.StatusOK, models.Response{
962+
Status: models.ResponseOK,
963+
Message: "Full refresh started",
964+
}); err != nil {
965+
api.SendError(w, r, err)
966+
return
967+
}
968+
}

engine/internal/srv/server.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,9 @@ func (s *Server) InitHandlers() {
236236
// Health check.
237237
r.HandleFunc("/healthz", s.healthCheck).Methods(http.MethodGet, http.MethodPost)
238238

239+
// Full refresh
240+
r.HandleFunc("/full-refresh", authMW.Authorized(s.refresh)).Methods(http.MethodPost)
241+
239242
// Show Swagger UI on index page.
240243
if err := attachAPI(r); err != nil {
241244
log.Err("Cannot load API description.")

0 commit comments

Comments
 (0)