Skip to content

Commit

Permalink
Limit workflow timeout to a range of 1 to 300 seconds
Browse files Browse the repository at this point in the history
Signed-off-by: Junwei Dai <[email protected]>
  • Loading branch information
Junwei Dai committed Jan 13, 2025
1 parent 76d244e commit 38466d4
Showing 1 changed file with 3 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.opensearch.flowframework.transport.GetWorkflowStateAction;
import org.opensearch.flowframework.transport.GetWorkflowStateRequest;
import org.opensearch.flowframework.transport.WorkflowResponse;
import org.opensearch.search.aggregations.metrics.Min;
import org.opensearch.threadpool.Scheduler;
import org.opensearch.threadpool.ThreadPool;

Expand All @@ -32,7 +33,7 @@ public class WorkflowTimeoutUtility {

private static final Logger logger = LogManager.getLogger(WorkflowTimeoutUtility.class);
private static final TimeValue MAX_TIMEOUT_MILLIS = TimeValue.timeValueSeconds(300);

private static final TimeValue MIN_TIMEOUT_MILLIS = TimeValue.timeValueSeconds(1);
/**
* Schedules a timeout task for a workflow execution.
*
Expand All @@ -53,6 +54,7 @@ public static ActionListener<WorkflowResponse> scheduleTimeoutHandler(
AtomicBoolean isResponseSent
) {
long adjustedTimeout = Math.min(timeout, MAX_TIMEOUT_MILLIS.millis());
adjustedTimeout = Math.max(adjustedTimeout, MIN_TIMEOUT_MILLIS.millis());
Scheduler.ScheduledCancellable scheduledCancellable = threadPool.schedule(
new WorkflowTimeoutListener(client, workflowId, listener, isResponseSent),
TimeValue.timeValueMillis(adjustedTimeout),
Expand Down

0 comments on commit 38466d4

Please sign in to comment.