Skip to content

Commit 8ce19f9

Browse files
Update AbstractTaskCancellation.java
Signed-off-by: Kiran Prakash <[email protected]>
1 parent 8aeea17 commit 8ce19f9

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

server/src/main/java/org/opensearch/search/sandboxing/cancellation/AbstractTaskCancellation.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,10 @@ private List<TaskCancellation> getTaskCancellations(Sandbox sandbox, SandboxReso
100100
}
101101

102102
private long getReduceBy(Sandbox sandbox, SandboxResourceType resourceType) {
103+
Long usage = getUsage(sandbox, resourceType);
104+
if (usage == null) {
105+
return 0;
106+
}
103107
return getUsage(sandbox, resourceType) - sandbox.getResourceLimitFor(resourceType).getThresholdInLong();
104108
}
105109

@@ -112,8 +116,8 @@ private List<Task> getAllTasksInSandbox(String sandboxId) {
112116
}
113117

114118
private TaskCancellation createTaskCancellation(CancellableTask task) {
115-
// todo add reasons and callbacks
116-
return new TaskCancellation(task, List.of(), List.of(this::callbackOnCancel));
119+
// todo add correct reason and callbacks
120+
return new TaskCancellation(task, List.of(new TaskCancellation.Reason("limits exceeded", 5)), List.of(this::callbackOnCancel));
117121
}
118122

119123
private void callbackOnCancel() {

0 commit comments

Comments
 (0)