Skip to content

Commit

Permalink
Use GET /_tasks/<task_id> instead of direct access to system index
Browse files Browse the repository at this point in the history
Signed-off-by: Craig Perkins <[email protected]>
  • Loading branch information
cwperks committed Nov 1, 2024
1 parent 14fafe6 commit 6e21e8d
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 27 deletions.
8 changes: 4 additions & 4 deletions public/JobHandler/callbacks/force_merge.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ export const callbackForForceMerge: CallbackType = async (job: ForceMergeJobMeta
const tasksResult = await commonService.apiCaller<ForceMergeTaskResult>({
endpoint: "transport.request",
data: {
path: `/.tasks/_doc/${extras.taskId}`,
path: `/_tasks/${extras.taskId}`,
method: "GET",
},
});
if (tasksResult.ok) {
const { _source, found } = tasksResult.response;
const { completed, error } = (_source || {}) as ForceMergeTaskResult["_source"];
if (completed && found) {
const _source = tasksResult.response;
const { completed, error } = (_source || {}) as ForceMergeTaskResult;
if (completed) {
if (extras.toastId) {
core.notifications.toasts.remove(extras.toastId);
}
Expand Down
6 changes: 3 additions & 3 deletions public/JobHandler/callbacks/open.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ export const callbackForOpen: CallbackType = async (job: OpenJobMetaData, { core
const tasksResult = await commonService.apiCaller<OpenTaskResult>({
endpoint: "transport.request",
data: {
path: `/.tasks/_doc/${extras.taskId}`,
path: `/_tasks/${extras.taskId}`,
method: "GET",
},
});
if (tasksResult.ok) {
const { _source } = tasksResult.response;
const { completed, error } = (_source || {}) as OpenTaskResult["_source"];
const _source = tasksResult.response;
const { completed, error } = (_source || {}) as OpenTaskResult;
if (completed) {
const { acknowledged, shards_acknowledged } = _source.response || {};
if (acknowledged && shards_acknowledged) {
Expand Down
8 changes: 4 additions & 4 deletions public/JobHandler/callbacks/reindex.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ export const callbackForReindex: CallbackType = async (job: ReindexJobMetaData,
const tasksResult = await commonService.apiCaller<TaskResult>({
endpoint: "transport.request",
data: {
path: `/.tasks/_doc/${extras.taskId}`,
path: `/_tasks/${extras.taskId}`,
method: "GET",
},
});
if (tasksResult.ok) {
const { _source, found } = tasksResult.response;
const { completed, response, error } = (_source || {}) as ReindexTaskResult["_source"];
const _source = tasksResult.response;
const { completed, response, error } = (_source || {}) as ReindexTaskResult;
const { failures, canceled } = response || {};
if (completed && found) {
if (completed) {
if (extras.toastId) {
core.notifications.toasts.remove(extras.toastId);
}
Expand Down
8 changes: 4 additions & 4 deletions public/JobHandler/callbacks/shrink.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ export const callbackForShrink: CallbackType = async (job: RecoveryJobMetaData,
const tasksResult = await commonService.apiCaller<TaskResult>({
endpoint: "transport.request",
data: {
path: `/.tasks/_doc/${extras.taskId}`,
path: `/_tasks/${extras.taskId}`,
method: "GET",
},
});

if (tasksResult.ok) {
const { _source, found } = tasksResult.response;
const { completed, error } = (_source || {}) as TaskResult["_source"];
if (completed && found) {
const _source = tasksResult.response;
const { completed, error } = (_source || {}) as TaskResult;
if (completed) {
if (extras.toastId) {
core.notifications.toasts.remove(extras.toastId);
}
Expand Down
8 changes: 4 additions & 4 deletions public/JobHandler/callbacks/split.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ export const callbackForSplit: CallbackType = async (job: RecoveryJobMetaData, {
const tasksResult = await commonService.apiCaller<TaskResult>({
endpoint: "transport.request",
data: {
path: `/.tasks/_doc/${extras.taskId}`,
path: `/_tasks/${extras.taskId}`,
method: "GET",
},
});
if (tasksResult.ok) {
const { _source, found } = tasksResult.response;
const { completed, error } = (_source || {}) as TaskResult["_source"];
if (completed && found) {
const _source = tasksResult.response;
const { completed, error } = (_source || {}) as TaskResult;
if (completed) {
if (extras.toastId) {
core.notifications.toasts.remove(extras.toastId);
}
Expand Down
13 changes: 5 additions & 8 deletions public/JobHandler/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,11 @@ export type CallbackType = (
) => Promise<boolean>;

export type TaskResult<T = {}> = {
found: boolean;
_source: {
completed: boolean;
response: T;
error?: {
type: string;
reason: string;
};
completed: boolean;
response: T;
error?: {
type: string;
reason: string;
};
};

Expand Down

0 comments on commit 6e21e8d

Please sign in to comment.